How to use JavaScript Slick library to make interactive Carousel

Siddharth Rastogi
2 min readFeb 13, 2022

In this post, we will learn how to use the Javascript Slick library to make an interactive and responsive carousel. Slick.js is the Javascript library that uses jQuery to implement the slider/carousel in the component. It is easy to implement.

So, Let’s start and see how anyone can implement it in their projects.

What are the prerequisites of Slick.js ?

Before starting this, we have to import the jQuery library into our project, so that slick can use and help us to make the carousel.

Copy jQuery CDN link for your reference and pasted it in script tag:

https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js

Include the script and styling

There are two ways to use the script and styling of the Slick slider.

  • To download the slick.js and slick.css file from here and copy both files into the project. Then use this below script.

// For script

<script src=’PROJECT_PATH/js/slick.js’></script>

// For Styling

<link rel=”stylesheet” href=”PROJECT_PATH/css/slick.css”>

  • Another way is to use the CDN links that are easy and don’t require any other file.

https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js

https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css

Let’s understand with the example

Suppose, we have slides to show in the carousel.

<div class=”carousel-container”>
<div class=”slide”>Slide-1</div>
<div class=”slide”>Slide-2</div>
<div class=”slide”>Slide-3</div>
<div class=”slide”>Slide-4</div>
<div class=”slide”>Slide-5</div>
<div class=”slide”>Slide-6</div>
</div>

Now, it’s time to initialize the slick to the carousel-container class.

// initialize the slick function$(“.carousel-container”).slick({
autoplay: true,
slidesToShow: 3,
slidesToScroll: 1,
speed: 350,
});

The above piece of code has three slides to show at the same time and one slide scroll with a speed of 350 milliseconds.

We can handle most of the features in the slick, for example, slideToshow, slideToScroll, Dots, etc.

So this is a basic example of how to make a carousel. Now, we will discuss the features to make it responsive and more cool and interactive carousel.

For more cool features and customized properties, you can visit here

--

--

Siddharth Rastogi

I am a full stack developer, I have an expertise in Web Development. I write tech stuff and share my knowledge with others through blogs & articles.