DEV Community

javier
javier

Posted on

Creating A Carousel In React With Bootstrap

Creating a carousel in react might sound a bit intimidating; but with the right tools and background knowledge, it becomes much easier. First, we'll start by installing Bootstrap with npm.

npm install react-bootstrap bootstrap

After you have installed Bootstrap, you will need to import it into your JS.

import Carousel from 'react-bootstrap/Carousel';

Now let's get to the fun part. You'll want do use the following code to create your carousel:

 <Carousel>
  <div className='slide'><img src='https://cdn.mos.cms.futurecdn.net/MeU4HokrzUwhbd9PJBQCSV-1200-80.png'/></div>
  <div className='slide'><img src='https://fs-prod-cdn.nintendo-europe.com/media/images/10_share_images/games_15/nintendo_switch_download_software_1/2x1_NSwitchDS_Overwatch2WatchpointPack_image1600w.jpg'/></div>
  <div className='slide'><img src='https://i.ytimg.com/vi/wQATS4HOxdo/maxresdefault.jpg'/></div>
  <div className='slide'><img src='https://p325k7wa.twic.pics/high/elden-ring/elden-ring/04-retailers/00-beautyshots/04-Standard/ER_standard_keyart.jpg?twic=v1/step=10/quality=80/max=760'/></div>
  <div className='slide'><img src='https://cdn.cloudflare.steamstatic.com/steam/apps/570940/capsule_616x353.jpg?t=1668145065'/></div>
  <div className='slide'><img src='https://images2.alphacoders.com/204/thumb-1920-204972.jpg'/></div>
  <div className='slide'><img src='https://i.ytimg.com/vi/H4rYVsJ4v9Y/maxresdefault.jpg'/></div>
  <div className='slide'><img src='https://cdn.akamai.steamstatic.com/steam/apps/12210/capsule_616x353.jpg?t=1618853493'/></div>
</Carousel>;
Enter fullscreen mode Exit fullscreen mode

Personally, I recommend putting the carousel in its own component in case you need to use it in different places throughout your app. Putting it in its own component will also make it significantly easier to see what the placement will look like in your app.

After that, you're pretty much done. This will give you the basic foundation for your carousel. It can be customized to your liking by changing fonts, speeds, styles, transitions, and image size. I recommend playing around with these to see what you prefer and what works best with your personal style and project. You can use this for a slide show or even a loading page if you wanted to. Happy coding!

Latest comments (0)