How to create a carousel in React using Ant Design

In web development, a carousel is a UI component that displays a series of content items in a rotating or sliding manner. Carousels are designed to maximize limited screen space, providing a visually appealing way to present featured products, image galleries, testimonials, and more.

When and why carousels are used

Here are some of the top reasons why developers may need to use carousels in the web applications:

  • Display featured products: Carousels are great for highlighting featured products. By rotating through a curated selection, businesses can capture users’ attention and entice them to explore further.

  • Showcase image galleries or portfolios: Carousels offer an elegant solution for photographers, designers, or anyone with a visual portfolio. They allow creators to seamlessly present a collection of images or projects, creating a visually cohesive and interactive experience for visitors.

  • Highlight testimonials or customer reviews: Carousels are valuable for showcasing customer testimonials or reviews. By cycling through positive feedback, businesses can build trust and credibility, providing social proof to potential customers.

Carousels in Ant Design

Ant Design, or antd, is a React UI library that offers a variety of UI components, making it an ideal choice for developers aiming to create polished and user-friendly interfaces. Here are some key advantages of using the Ant Design carousel:

  • Customization: Developers can easily tailor the appearance and behavior of the carousel to suit the application’s specific requirements and aesthetics. This includes adjusting autoplay settings, transition speeds, and more.

  • Responsive design: Ant Design’s Carousel is designed with responsiveness in mind. It adapts seamlessly to different screen sizes and resolutions, ensuring a consistent and user-friendly experience across devices, from desktops to mobile devices.

  • Accessibility features: The Carousel component is built with accessibility in mind, ensuring that users with disabilities can navigate and interact with the carousel seamlessly. This aligns with best practices for creating inclusive web applications.

Installation

To get started, we first need to install the Ant Design (antd) library in our React project. We can use either of the following installation commands:

npm install antd
// OR
yarn add antd
Installing the antd library

Example

Let's look at the carousel in action in the following code example:

Explanation

In the App.js file:

  • Line 2: We import the Carousel component from the antd library.

  • Line 7: We add the Carousel component to our React app.

  • Line 8: We enable the autoplay property so that the carousel slides automatically move to the next slide.

  • Line 9: We set the dotPosition property to “left.” This displays the slider dots on the left of the carousel slides. We can also set this to “right,” “top,” or “bottom.”

  • Line 10: We set the effect property to “scrollx.” This adds a scroll animation when the slides transition. We can also set it to “fade” to use the fade transition.

  • Lines 13–24: Each div represents a slide in the carousel. We have created three slides with basic text.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved