Netflix Carousel using CSS
Check out the new version of the Netflix Carousel using SwiperJS – Read Article
This tutorial is going to demonstrate how to create a Netflix looking like Carousel just by using CSS3. I will be using SCSS preprocessor to help me tidy things up, but don’t worry as conceptually it isn’t much different from standard CSS3.
The carousel is currently only created to work on Desktop, but it can be easily adapted for tablets and mobile just by doing some Grid or media queries tweaks.
The disadvantage of not using JavaScript is that the next and previous button will rotate with each section. Maybe we can fade out the arrows on the next version? If you fix that problem please comment below and I will update the article.
The first thing that we’ll have to do is to define our HTML5 structure. I am trying to keep everything fairly simple. So the structure goes:


Wrapper
The div with the class wrapper is where I explicitly define a grid with 3 columns and a width of 100%; It was just quicker to do it this way instead of inline blocks or floats.
Anchor Link
I’ve used normal links to anchor each section. Plain and simple, each link has an id that links to a section containing the same id.
Item
Each item contains an image and it’s part of a section grid that has 5 columns and a width of auto.
Item Hover
To get the hover effect I’ve used “transform: scale (1.2)” and I’ve added a transition property to the item so we get that smooth animation.
Smooth Scrolling between sections
To get the smooth scrolling between each section I’ve used the “scroll-behaviour: smooth” property on the “.wrapper div and also html (as the transition didn’t work in some browsers).
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<h1>NETFLIX</h1>
<div class="wrapper">
<section id="section1">
<a href="#section3">‹</a>
<div class="item">
<img src="img1.jpg" alt="Describe Image">
</div>
<div class="item">
<img src="img2.jpg" alt="Describe Image">
</div>
<div class="item">
<img src="img3.jpg" alt="Describe Image">
</div>
<div class="item">
<img src="img4.jpg" alt="Describe Image">
</div>
<div class="item">
<img src="img5.jpg" alt="Describe Image">
</div>
<a href="#section3">›</a>
</section>
<section id="section2">
<a href="#section1">‹</a>
<div class="item">
<img src="img6.jpg" alt="Describe Image">
</div>
<div class="item">
<img src="img7.jpg" alt="Describe Image">
</div>
<div class="item">
<img src="img8.jpg" alt="Describe Image">
</div>
<div class="item">
<img src="img9.jpg" alt="Describe Image">
</div>
<div class="item">
<img src="img10.jpg" alt="Describe Image">
</div>
<a href="#section3">›</a>
</section>
<section id="section3">
<a href="#section2">‹</a>
<div class="item">
<img src="img11.jpg" alt="Describe Image">
</div>
<div class="item">
<img src="img12.jpg" alt="Describe Image">
</div>
<div class="item">
<img src="img13.jpg" alt="Describe Image">
</div>
<div class="item">
<img src="img14.jpg" alt="Describe Image">
</div>
<div class="item">
<img src="img15.jpg" alt="Describe Image">
</div>
<a href="#section1">›</a>
</section>
</div>
</body>
</html>
Create a folder with the name ” css ” and inside this folder create a file called styles.scss
Make sure that you have your SCSS Pre-Processor working so it outputs a file with the name of styles.css. Alternatively, you can write normal CSS
SCSS
$itemGrow: 1.2;
$duration: 250ms;
html {
scroll-behavior: smooth;
}
body {
margin: 0;
background-color: #000;
}
h1 {
font-family: Arial;
color: red;
text-align: center;
}
.wrapper {
display: grid;
grid-template-columns: repeat(3,100%);
overflow:hidden;
scroll-behavior: smooth;
section {
width: 100%;
position: relative;
display: grid;
grid-template-columns: repeat(5, auto);
margin: 20px 0;
.item {
padding: 0 2px;
transition: $duration all;
&:hover {
margin: 0 40px;
transform: scale(1.2);
}
}
a {
position: absolute;
color: #fff;
text-decoration: none;
font-size: 6em;
background:rgb(0,0,0);
width: 80px;
padding: 20px;
text-align: center;
z-index: 1;
&:nth-of-type(1) {
top:0; bottom:0; left:0;
background: linear-gradient(-90deg, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 100%);
}
&:nth-of-type(2) {
top:0; bottom:0; right: 0;
background: linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 100%);
}
}
}
}
Conclusion
You can look at the full code below to get a better understanding of what is going on.
Further improvements could be:
- Make it mobile friendly
- Have the back and forward arrows static
- Add the play icon on each thumbnail on hover
See the Pen Netflix Carousel using CSS Beta1.0 by Radoslav Angelov (@Raddy) on CodePen.
Improved Version
This is a slightly improved version where I have added links inside the items and also heading and duration.
See the Pen Netflix Carousel with Links by Raddy (@Raddy) on CodePen.
please help me making it mobile friendly. I am trying to use the code in reactjs application.
Hi,
You can use the existing code and to add a media query for phones and adjust the size to whatever you like
Made my day, been looking for this on YouTube, but clearly i was looking at the wrong place, came upon this link by chance while at work. Very informative, learned alot. Used up my lunch break for this, worth it ! Thanks alot !
It sounds like your lunch break was well spent. Thank you, and I am glad that you found the article useful
When i click on the next or prev slide the scrollbar jumps down, is it possible that it doesnt move the scrollbar on click?
Hi Shaun,
It might be best just to use the latest one that I did using SwiperJS. It’s a lot better, it works with touch and it’s actually easier to make and maintain. You don’t have to write any JavaScript, it’s literally a few options that you need to set.
Here is the link:
https://www.raddy.co.uk/blog/better-netflix-carousel-using-swiperjs/
Just like the SwiperJS version, the thumbnails are all showing up vertically in both FF & Chrome. I don’t see anything in the CSS that’s different from what you showed in the video that would cause that. Any ideas?
Are you able to share the code?
Thank you!
I made Netflix clone Website using css and Html .
with Discruption and source code
https://www.trendonpedia.in/2020/07/netflix-homepage-design-using-html-and-css/
Awesome bro, that’s really cool. Thanks for sharing
Hi, I want to drop this into an alreaday created site. Inplace of another element. I’m a novice so am coming across probplems. Is there a nice easy step by step method? TIA
All you have to do is copy and paste the HTML where you want it and add the CSS
thanks, really helpful!
Is it possible to add text that is shown in front of each image? So let’s say you want to show the title and duration on top of the image. How do I need to do that?
Thx!
I am glad that you found it helpful!
Also, when making the images clickable with a href tags to point to the page with more details, the carousel gets completely distorted. What would be the correct way to make the images clickable?
Thx!
I have done a super quick example on Codepen:
https://codepen.io/Raddy/pen/GRjYjKY
It will require some work to get it to look nice. Basically, I had to change a few of the classes and then I added the href inside the items. There are many ways you can do that.
I have an old video that shows you how to build cards with similar overlay and animations. Unfortunately, it’s a fairly long video, but feel free to check it out:
https://www.youtube.com/watch?v=VPj8VPFRTeU
I see a problem when you put multiple carousels below each other. When you do this and then jump to a section in the top carousel, it does that perfectly but after that the arrows of the top carousel don’t work anymore to jump to other sections in the top carousel. Do you think this can be fixed?
Unfortunately, that is the default browser behaviour when you click on an anchor link. You could try to figure out some javascript to stop that. I would suggest you use the SwiperJS method that is linked at the top of the article. It’s easier to do, it works with touch gestures and you can do so much more with it.
Instead of seeing the slider horizontal i can see it vertical. What do i do
You can change the CSS path or run it on a local server. Live server in VSC should work
Still Doesnt work!
Hey, send me your code or at least say what’s not working so I can better understand and help
You can email me if you like. I am happy to help
I m sorry! didnt mean to be rude.. I have been trying to do this for a long time and its not working.. Can u give me ur mail id?
Don’t worry, yes of course: hello@raddy.co.uk. We will figure it out 🙂