Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Next.js Tutorial
  • Next.js Components
  • Next.js Functions
  • Next.js Deployment
  • Next.js Projects
  • Next.js Routing
  • Next.js Styles
  • Next.js Server-Side Rendering
  • Next.js Environment Variables
  • Next.js Middleware
  • Next.js Typescript
  • Next.js Image Optimization
  • Next.js Data Fetching
Open In App
Next Article:
How to add Image Carousel in Next.js ?
Next article icon

How to add Image Carousel in Next.js ?

Last Updated : 26 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we are going to learn how we can add an Image Carousel in NextJS. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac.

Approach

To create image carousel in next.js we are going to use a react-responsive carousel package because it is powerful, lightweight, and fully customizable. Install the library, import the carousel component and then add the images as carousels on the homepage using the installed package.

Steps to Create Carousel in Next.js

Step 1: Create a React application using the following command.

npx create-next-app@latest gfg

Step 2: After creating your project folder i.e. gfg, move to it using the following command.

cd gfg

Step 3: Now we will install the react-responsive-carousel package using the below command

npm i react-responsive-carousel

Project Structure: It will look like this.

Project structure

The updated dependencies in the package.json file are:

"dependencies": {
"next": "14.2.4",
"react": "^18",
"react-dom": "^18",
"react-responsive-carousel": "^3.2.23"
}

Creating Image Carousel: To create our image carousel we need some images. So for this example, we are going to use the below images.

  • https://media.geeksforgeeks.org/wp-content/uploads/20211213172224/1.png
  • https://media.geeksforgeeks.org/wp-content/uploads/20211213172225/2.png
  • https://media.geeksforgeeks.org/wp-content/uploads/20211213172226/3.png
  • https://media.geeksforgeeks.org/wp-content/uploads/20211213172227/4.png
  • https://media.geeksforgeeks.org/wp-content/uploads/20211213172229/5.png

Now add the images to the public folder. After the images are ready we just need to add these images to our carousel. 

Example: For this example, we are creating the carousel on our homepage. So add the below code in the index.js file.

JavaScript
// pages/-app.js import "react-responsive-carousel/lib/styles/carousel.min.css"; import { Carousel } from "react-responsive-carousel";  const NextJsCarousel = () => {     return (         <div>             <h2>                 NextJs Carousel - GeeksforGeeks             </h2>             <Carousel>                 <div>                     <img                         src= "https://media.geeksforgeeks.org/wp-content/uploads/20211213172224/1.png"                         alt="image1"                     />                     <p className="legend">                         Image 1                     </p>                 </div>                 <div>                     <img                         src= "https://media.geeksforgeeks.org/wp-content/uploads/20211213172225/2.png"                         alt="image2"                     />                     <p className="legend">                         Image 2                     </p>                 </div>                 <div>                     <img                         src= "https://media.geeksforgeeks.org/wp-content/uploads/20211213172226/3.png"                         alt="image3"                     />                     <p className="legend">                         Image 3                     </p>                 </div>                 <div>                     <img                         src= "https://media.geeksforgeeks.org/wp-content/uploads/20211213172227/4.png"                         alt="image4"                     />                     <p className="legend">                         Image 4                     </p>                 </div>                 <div>                     <img                         src= "https://media.geeksforgeeks.org/wp-content/uploads/20211213172229/5.png"                         alt="image5"                     />                     <p className="legend">                         Image 5                     </p>                 </div>             </Carousel>         </div>     ); };  export default NextJsCarousel; 

In the above example, we are first importing the carousel component from the installed package. Then we are using this component to create our carousel.

Steps to run the application: Run the below command in the terminal to run the app.

npm run dev

Output:


Next Article
How to add Image Carousel in Next.js ?

I

imranalam21510
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • ReactJS
  • Next.js

Similar Reads

    How to Add a Background Image in Next.js?
    Next.js is a powerful React framework that allows for server-side rendering and the generation of static websites. Adding a background image to your Next.js application can enhance the visual appeal of your web pages. This article will guide you through the process of adding a background image to a
    3 min read
    How to import image in Next.js ?
    Next.js is a full-stack React-based framework. Unlike a traditional react app, which loads and renders the entire application on the client, Next.js allows the first-page load to be rendered by the server, which is great for SEO and performance. Some of the key features of Next.js are:  Server-side
    4 min read
    How To Create A Custom Image Loader In NextJS?
    Creating a custom image loader in Next.js allows you to control how images are loaded and optimized. This is useful for integrating with different image services or handling specific image processing needs. Here’s how to create and use a custom image loader: This article will walk you through the st
    4 min read
    How to add Slider in Next.js ?
    Adding a slider in Next.js involves integrating a slider component, like react-range, managing its state using React hooks and applying styles for customization, enhancing user interaction and input precision in your application.ApproachTo add our Slider we are going to use the react-range package.
    2 min read
    How to create Image Slider in ReactJS ?
    Image Slider is a dynamic web element that displays a collection of images and has a slider to switch between the Images. It is the most common feature to show image collection in web applications or mobile apps.Websites like Amazon.com, Flipkart.com, and many e-commerce sites use image sliders to s
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences