---
localeCode: en-US
order: 61
category: Show
title: Carousel
subTitle: Carousel
icon: doc-carousel
brief: Carousel is a media component that can display the effect of playing multiple pictures in turn in a visualization application.
---
## Demos
### How to import
```jsx import
import { Carousel } from '@douyinfe/semi-ui';
```
### Basic Carousel
Basic carousel
```jsx live=true dir="column"
import React from 'react';
import { Carousel, Typography, Space } from '@douyinfe/semi-ui';
() => {
const { Title, Paragraph } = Typography;
const style = {
width: '100%',
height: '400px',
};
const titleStyle = {
position: 'absolute',
top: '100px',
left: '100px',
color: '#1C1F23'
};
const colorStyle = {
color: '#1C1F23'
};
const renderLogo = () => {
return (
);
};
const imgList = [
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-1.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-2.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-3.png',
];
const textList = [
['Semi Design System Management', 'From Semi Design, To Any Design', 'Quickly define your design system and apply it to design drafts and code'],
['Semi Material', 'Customized components for business scenarios, support online preview and debugging', 'Content co-authored by Semi Design users'],
['Semi Template', 'Efficient Design2Code converts design into real code in seconds', 'One-click conversion of massive page template front-end code'],
];
return (
{
imgList.map((src, index) => {
return (
{renderLogo()}
{textList[index][0]}
{textList[index][1]}
{textList[index][2]}
);
})
}
);
};
```
### Theme Switch
Three themes are defined by default: `primary`、`light`、`dark`
```jsx live=true dir="column"
import React from 'react';
import { Carousel, RadioGroup, Radio, Space, Typography } from '@douyinfe/semi-ui';
() => {
const { Title, Paragraph } = Typography;
const [theme, setTheme] = useState('primary');
const style = {
width: '100%',
height: '400px',
};
const titleStyle = {
position: 'absolute',
top: '100px',
left: '100px'
};
const colorStyle = {
color: '#1C1F23'
};
const renderLogo = () => {
return (
);
};
const imgList = [
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-1.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-2.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-3.png',
];
const textList = [
['Semi Design System Management', 'From Semi Design, To Any Design', 'Quickly define your design system and apply it to design drafts and code'],
['Semi Material', 'Customized components for business scenarios, support online preview and debugging', 'Content co-authored by Semi Design users'],
['Semi Template', 'Efficient Design2Code converts design into real code in seconds', 'One-click conversion of massive page template front-end code'],
];
return (
{
imgList.map((src, index) => {
return (
{renderLogo()}
{textList[index][0]}
{textList[index][1]}
{textList[index][2]}
);
})
}
theme
setTheme(e.target.value)} value={theme} type="button">
primary
light
dark
);
};
```
### Indicators
Indicators can be adjusted for type, position, size
type: `dot`、`line`、`columnar`
position: `left`、`center`、`right`
size: `small`、`medium`
```jsx live=true dir="column"
import React from 'react';
import { Carousel, RadioGroup, Radio, Space, Typography } from '@douyinfe/semi-ui';
() => {
const { Title, Paragraph } = Typography;
const [size, setSize] = useState('small');
const [type, setType] = useState('dot');
const [position, setPosition] = useState('left');
const style = {
width: '100%',
height: '400px',
};
const titleStyle = {
position: 'absolute',
top: '100px',
left: '100px'
};
const colorStyle = {
color: '#1C1F23'
};
const renderLogo = () => {
return (
);
};
const imgList = [
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-1.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-2.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-3.png',
];
const textList = [
['Semi Design System Management', 'From Semi Design, To Any Design', 'Quickly define your design system and apply it to design drafts and code'],
['Semi Material', 'Customized components for business scenarios, support online preview and debugging', 'Content co-authored by Semi Design users'],
['Semi Template', 'Efficient Design2Code converts design into real code in seconds', 'One-click conversion of massive page template front-end code'],
];
return (
{
imgList.map((src, index) => {
return (
{renderLogo()}
{textList[index][0]}
{textList[index][1]}
{textList[index][2]}
);
})
}
type
setType(e.target.value)} value={type} type="button">
dot
line
columnar
position
setPosition(e.target.value)} value={position} type="button">
left
center
right
size
setSize(e.target.value)} value={size} type="button">
small
medium
);
};
```
### Arrows
Control whether the arrow is visible through the showArrow property
If the arrow is visible, use the arrowType property to control the timing of the arrow display
```jsx live=true dir="column"
import React from 'react';
import { Carousel, RadioGroup, Radio, Space, Typography } from '@douyinfe/semi-ui';
() => {
const { Title, Paragraph } = Typography;
const [arrowType, setArrowType] = useState('always');
const [show, setShow] = useState(true);
const style = {
width: '100%',
height: '400px',
};
const titleStyle = {
position: 'absolute',
top: '100px',
left: '100px'
};
const colorStyle = {
color: '#1C1F23'
};
const renderLogo = () => {
return (
);
};
const imgList = [
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-1.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-2.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-3.png',
];
const textList = [
['Semi Design System Management', 'From Semi Design, To Any Design', 'Quickly define your design system and apply it to design drafts and code'],
['Semi Material', 'Customized components for business scenarios, support online preview and debugging', 'Content co-authored by Semi Design users'],
['Semi Template', 'Efficient Design2Code converts design into real code in seconds', 'One-click conversion of massive page template front-end code'],
];
return (
{
imgList.map((src, index) => {
return (
{renderLogo()}
{textList[index][0]}
{textList[index][1]}
{textList[index][2]}
);
})
}
arrow
setShow(e.target.value)} value={show} type="button">
show
hide
show time
setArrowType(e.target.value)} value={arrowType} type="button">
always
hover
);
};
```
### Custom Arrow
Customize arrow styles and click events through the arrowProps property
```jsx live=true dir="column"
import React from 'react';
import { Carousel, Typography, Space } from '@douyinfe/semi-ui';
import { IconArrowLeft, IconArrowRight } from "@douyinfe/semi-icons";
class CarouselDemo extends React.Component {
constructor(props) {
super(props);
this.imgList = [
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-1.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-2.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-3.png',
];
this.textList = [
['Semi Design System Management', 'From Semi Design, To Any Design', 'Quickly define your design system and apply it to design drafts and code'],
['Semi Material', 'Customized components for business scenarios, support online preview and debugging', 'Content co-authored by Semi Design users'],
['Semi Template', 'Efficient Design2Code converts design into real code in seconds', 'One-click conversion of massive page template front-end code'],
];
this.arrowProps = {
leftArrow: { children: },
rightArrow: { children: },
};
};
renderLogo() {
return (
);
};
render() {
const style = {
width: '100%',
height: '400px',
};
const titleStyle = {
position: 'absolute',
top: '100px',
left: '100px'
};
const colorStyle = {
color: '#1C1F23'
};
return (
{
this.imgList.map((src, index) => {
return (
{this.renderLogo()}
{this.textList[index][0]}
{this.textList[index][1]}
{this.textList[index][2]}
);
})
}
);
}
}
```
### Play Parameters
Pass the parameter interval to autoPlay to control the time interval between two pictures, and pass hoverToPause to control whether to stop playing when the mouse is placed on the picture
```jsx live=true dir="column"
import React from 'react';
import { Carousel, Typography, Space } from '@douyinfe/semi-ui';
() => {
const { Title, Paragraph } = Typography;
const style = {
width: '100%',
height: '400px',
};
const titleStyle = {
position: 'absolute',
top: '100px',
left: '100px'
};
const colorStyle = {
color: '#1C1F23'
};
const renderLogo = () => {
return (
);
};
const imgList = [
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-1.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-2.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-3.png',
];
const textList = [
['Semi Design System Management', 'From Semi Design, To Any Design', 'Quickly define your design system and apply it to design drafts and code'],
['Semi Material', 'Customized components for business scenarios, support online preview and debugging', 'Content co-authored by Semi Design users'],
['Semi Template', 'Efficient Design2Code converts design into real code in seconds', 'One-click conversion of massive page template front-end code'],
];
return (
{
imgList.map((src, index) => {
return (
{renderLogo()}
{textList[index][0]}
{textList[index][1]}
{textList[index][2]}
);
})
}
);
};
```
### Animation and Speed
Control the animation by giving the animation property, optional values are `fade`, `slide`
Control the switching time between two pictures by giving the speed attribute, the unit is ms
```jsx live=true dir="column"
import React from 'react';
import { Carousel, Typography, Space } from '@douyinfe/semi-ui';
() => {
const { Title, Paragraph } = Typography;
const style = {
width: '100%',
height: '400px',
};
const titleStyle = {
position: 'absolute',
top: '100px',
left: '100px'
};
const colorStyle = {
color: '#1C1F23'
};
const renderLogo = () => {
return (
);
};
const imgList = [
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-1.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-2.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-3.png',
];
const textList = [
['Semi Design System Management', 'From Semi Design, To Any Design', 'Quickly define your design system and apply it to design drafts and code'],
['Semi Material', 'Customized components for business scenarios, support online preview and debugging', 'Content co-authored by Semi Design users'],
['Semi Template', 'Efficient Design2Code converts design into real code in seconds', 'One-click conversion of massive page template front-end code'],
];
return (
{
imgList.map((src, index) => {
return (
{renderLogo()}
{textList[index][0]}
{textList[index][1]}
{textList[index][2]}
);
})
}
);
};
```
### Controlled Carousel
```jsx live=true dir="column"
import React from 'react';
import { Carousel, Space, Typography } from '@douyinfe/semi-ui';
class CarouselDemo extends React.Component {
constructor(props) {
super(props);
this.imgList = [
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-1.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-2.png',
'https://lf3-static.bytednsdoc.com/obj/eden-cn/hjeh7pldnulm/SemiDocs/bg-3.png',
];
this.textList = [
['Semi Design System Management', 'From Semi Design, To Any Design', 'Quickly define your design system and apply it to design drafts and code'],
['Semi Material', 'Customized components for business scenarios, support online preview and debugging', 'Content co-authored by Semi Design users'],
['Semi Template', 'Efficient Design2Code converts design into real code in seconds', 'One-click conversion of massive page template front-end code'],
];
this.state = {
activeIndex: 0,
};
}
renderLogo() {
return (
);
};
onChange(activeIndex){
this.setState({ activeIndex });
}
render() {
const style = {
width: '100%',
height: '400px',
};
const titleStyle = {
position: 'absolute',
top: '100px',
left: '100px'
};
const colorStyle = {
color: '#1C1F23'
};
const { activeIndex } = this.state;
return (
{
this.imgList.map((src, index) => {
return (
{this.renderLogo()}
{this.textList[index][0]}
{this.textList[index][1]}
{this.textList[index][2]}
);
})
}
);
}
}
```
### API reference
**Carousel**
|PROPERTIES |INSTRUCTIONS |TYPE |DEFAULT |VERSION|
|------------------|-------------------------------------------------------------------------------------|------------------|--------|-------|
|activeIndex |Controlled property |number |- |2.10.0|
|animation |Animation, optional:`fade`, `slide` | "fade" \| "slide" |"slide"|2.10.0|
|arrowProps |Arrow parameters for custom arrow styles and click events | () => { leftArrow: ArrowButton, rightArrow:ArrowButton }|- |2.10.0|
|autoPlay |Whether to automatically display in a loop, or pass in { interval: Auto switch time interval(default: 2000), hoverToPause: Whether to pause automatic switching when the mouse is hovering(default: true) }|boolean | { interval?: number, hoverToPause?: boolean } |true |2.10.0|
|className |The className of Carousel container |string |- |2.10.0|
|defaultActiveIndex|The index displayed by default when initializing |number |0 |2.10.0|
|indicatorPosition |Indicator position, optional values are: `left`、`center`、`right` | "left" \| "center" \| "right"|"center"|2.10.0|
|indicatorSize |Indicator size, optional values are: `small`、`medium` | "small" \| "medium"|"small"|2.10.0|
|indicatorType |Indicator type, optional values are: `dot`、`line`、`columnar` | "dot" \| "line" \| "columnar"|"dot"|2.10.0|
|theme |Indicator and arrow theme, optional values are: `primary`、`light`、`dark` | "primary" \| "light" \| "dark" |"light"|2.10.0|
|onChange |Callback when image is switched | (index: number, preIndex: number) => void |- |2.10.0|
|arrowType |Arrow display timing, optional values are: `hover`、`always` | "hover" \| "always"|always |2.10.0|
|showArrow |Whether to show arrows |boolean |true |2.10.0|
|showIndicator |Whether to show the indicator |boolean |true |2.10.0|
|slideDirection |The direction of the slide when the animation effect is `slide`, optional: `left`、 `right` |"left" \| "right" |"left" |2.10.0|
|speed |Switching speed |number |300 |2.10.0|
|style |Carousel style |CSSProperties |- |2.10.0|
|trigger |When the indicator is triggered, the optional values are: `hover`、`click` | "hover" \| "click" |- |2.10.0|
**ArrowButton**
|PROPERTIES |INSTRUCTIONS |TYPE |DEFAULT|VERSION|
|------------------|---------------------------------------------------------------|------------------|------|------|
|props |Parameters on the arrow div, including style, onClick events, etc |DetailedHTMLProps, HTMLDivElement\> |- |2.10.0|
|children |Arrow custom icon |React.ReactNode |- |2.10.0|
## Methods
Some internal methods provided by Carousel can be accessed through ref:
| Method | Instructions | Version |
| ------------------ | ------------------------------- | ------- |
| play() | Play | 2.10.0 |
| stop() | Stop | 2.10.0 |
| goTo(targetIndex) | Go to target index | 2.10.0 |
| prev() | Go to previous index | 2.10.0 |
| next() | Go to next index | 2.10.0 |
## Design Tokens