DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Setting Up a Local Development Environment With IntelliJ, DevContainers, and Amazon Linux 2023
  • Login With Google Using ReactJS
  • Upload and Retrieve Files/Images Using Spring Boot, Angular, and MySQL
  • Add Material-UI Table In ReactJS Application

Trending

  • The Cypress Edge: Next-Level Testing Strategies for React Developers
  • How to Convert XLS to XLSX in Java
  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  • Measuring the Impact of AI on Software Engineering Productivity
  1. DZone
  2. Coding
  3. Java
  4. How to Use Owl Carousel in ReactJS

How to Use Owl Carousel in ReactJS

In this article, see how to use Owl Carousel in ReactJS.

By 
Sanwar Ranwa user avatar
Sanwar Ranwa
DZone Core CORE ·
Feb. 25, 20 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
48.2K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

In this article, we will learn how we can use the Owl Carousel in a React application. Carousel is a slideshow for cycling a series of images or videos.

Prerequisites

  • Basic knowledge of React.js
  • Visual Studio Code IDE

Create ReactJS Project

Let's first create a React application using the following command:

JavaScript
 




xxxxxxxxxx
1


 
1
npx create-react-app matform 


  

Open the newly-created project in Visual Studio Code and Install bootstrap in this project by using the following command:

Java
 




xxxxxxxxxx
1


 
1
npm install --save bootstrap 


    

Now, open the index.js file and import Bootstrap:

Java
 




xxxxxxxxxx
1


 
1
import 'bootstrap/dist/css/bootstrap.min.css';    



You might also be interested in: React.js Essentials

Install Owl Carousel

Now install Owl Carousel by using the following command:

Java
 




xxxxxxxxxx
1


 
1
npm install react-owl-carousel --save



Now open index.html, add jquery reference, add the following line in head 

Java
 




xxxxxxxxxx
1


 
1
  <script src="https:code.jquery.com/jquery-3.4.1min.js"><script>



Now, right-click on the public folder. Add a new folder 'assets', and under it, add a new folder and rename that to 'img' and add some demo images to this folder:

Now go to src folder and create a new component 'Owldemo1.js' and add the following reference in this component

Java
 




xxxxxxxxxx
1


 
1
import OwlCarousel from 'react-owl-carousel';  
2
import 'owl.carousel/dist/assets/owl.carousel.css';  
3
import 'owl.carousel/dist/assets/owl.theme.default.css';  



Add the following code in this component.

Java
 




xxxxxxxxxx
1
40


 
1
import React,{Component} from 'react';  
2
import OwlCarousel from 'react-owl-carousel';  
3
import 'owl.carousel/dist/assets/owl.carousel.css';  
4
import 'owl.carousel/dist/assets/owl.theme.default.css';  
5
import './owl.css';  
6
export class Owldemo1 extends Component {  
7
        render()  
8
        {  
9
          return (  
10
            <div>  
11
          <div class='container-fluid' >      
12
           <div className="row title" style={{marginBottom: "20px"}} >      
13
           <div class="col-sm-12 btn btn-info">      
14
           Owl Carousel In React Application   
15
           </div>      
16
           </div>  
17
       </div>  
18
       <div class='container-fluid' >            
19
        <OwlCarousel items={3}  
20
          className="owl-theme"  
21
          loop  
22
          nav  
23
          margin={8} >  
24
           <div ><img  className="img" src= {'assets/img/img1.jpg'}/></div>  
25
           <div><img  className="img" src= {'assets/img/img2.jpg'}/></div>  
26
           <div><img  className="img" src= {'assets/img/img4.jpg'}/></div>  
27
           <div><img  className="img" src= {'assets/img/img3.jpg'}/></div>  
28
           <div><img className="img" src= {'assets/img/img5.jpg'}/></div>  
29
           <div><img className="img" src= {'assets/img/img6.jpg'}/></div>  
30
           <div><img className="img" src= {'assets/img/img7.jpg'}/></div>  
31
      </OwlCarousel>  
32
      </div>  
33
  
34
      </div>  
35
          )  
36
        }  
37
      }  
38
        
39
  
40
export default Owldemo1  



Now create a CSS file named owl.css and add the following CSS:

Java
 




xxxxxxxxxx
1


 
1
.title  
2
{  
3
        margin-bottom: 20px;  
4
        padding:20px  
5
}  
6
.img  
7
{  
8
        height: 260px;width:100%  
9
}  



Import this file in the owldemo1.js component.

Open the app.js file and add the following code:

Java
 




xxxxxxxxxx
1
15


 
1
import React from 'react';  
2
import logo from './logo.svg';  
3
import './App.css';  
4
import Owldemo1 from './Owldemo1'  
5
import OwlDemo from './Owldemo'  
6
  
7
function App() {  
8
  return (  
9
    <div className="App">  
10
      <Owldemo1></Owldemo1>  
11
    </div>  
12
  );  
13
}  
14
  
15
export default App;  



Run the project by using 'npm start' and check the result.

Now create another component named 'owldemo.js'. In this component, we create auto owl carousel. Add the following code in this component:

Java
 




xxxxxxxxxx
1
35


 
1
import React,{Component} from 'react';  
2
import OwlCarousel from 'react-owl-carousel';  
3
import 'owl.carousel/dist/assets/owl.carousel.css';  
4
import 'owl.carousel/dist/assets/owl.theme.default.css';  
5
import './owl.css';  
6
export class OwlDemo extends Component {  
7
        render()  
8
        {      
9
          return (  
10
              <div>  
11
            <div class='container-fluid' >      
12
            <div className="row title" style={{marginBottom: "20px"}} >      
13
            <div class="col-sm-12 btn btn-info">      
14
            Owl Carousel with Auto Play Property In React Application   
15
            </div>      
16
            </div>  
17
        </div>  
18
        <div class='container-fluid' >   
19
          <OwlCarousel items={3} margin={8} autoplay ={true} >  
20
        <div ><img  className="img" src= {'assets/img/img1.jpg'}/></div>  
21
           <div><img  className="img" src= {'assets/img/img2.jpg'}/></div>  
22
           <div><img  className="img" src= {'assets/img/img4.jpg'}/></div>  
23
           <div><img  className="img" src= {'assets/img/img3.jpg'}/></div>  
24
           <div><img className="img" src= {'assets/img/img5.jpg'}/></div>  
25
           <div><img className="img" src= {'assets/img/img6.jpg'}/></div>  
26
           <div><img className="img" src= {'assets/img/img7.jpg'}/></div>  
27
      </OwlCarousel>  
28
      </div>  
29
      </div>  
30
          )  
31
        }  
32
      }  
33
        
34
  
35
export default OwlDemo  



Run the project and check that the images are auto slide.

Summary 

In this article, we learned how to implement the Owl Carousel in a ReactJS application.

Further Reading

Everything React: Tutorials for Beginners and Experts Alike

Java (programming language) Visual Studio Code

Opinions expressed by DZone contributors are their own.

Related

  • Setting Up a Local Development Environment With IntelliJ, DevContainers, and Amazon Linux 2023
  • Login With Google Using ReactJS
  • Upload and Retrieve Files/Images Using Spring Boot, Angular, and MySQL
  • Add Material-UI Table In ReactJS Application

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!