How to Create a Slider using HTML and CSS? Last Updated : 17 Jun, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report A slider (also called a slideshow) is a sequence of content frames that users can navigate through. Creating a slider using just HTML and CSS is efficient because it doesn't require JavaScript, making it lightweight and fast. The slider can contain images, text, or any other content you want to showcase.Step-by-Step Guide to Create a SliderSet up a Container: Use a container that holds the slides and input radio buttons.Create Radio Inputs: Use radio buttons to control the slider frames.Create Slides: Design the slides with individual classes (e.g., frame_1, frame_2) inside the container.CSS Transitions: Apply sliding effects using CSS by adjusting the container’s margin-left for smooth transitions.Navigation Controls: Add labels for the radio buttons to act as navigation controls for the slider.Responsiveness: Use media queries to ensure the slider looks good on smaller screens.Example: Working Slider with HTML and CSSIn this example, we will see how to create a working slider using HTML and CSS. index.html <!DOCTYPE html> <html> <head> <title>Slider Using CSS</title> <link rel="stylesheet" href="style.css"> </head> <body> <div id="frame"> <input type="radio" name="frame" id="frame1" checked /> <input type="radio" name="frame" id="frame2" /> <input type="radio" name="frame" id="frame3" /> <input type="radio" name="frame" id="frame4" /> <div id="slides"> <div id="overflow"> <div class="inner"> <div class="frame frame_1"> <div class="frame-content"> <h2>Slide 1</h2> </div> </div> <div class="frame frame_2"> <div class="frame-content"> <h2>Slide 2</h2> </div> </div> <div class="frame frame_3"> <div class="frame-content"> <h2>Slide 3</h2> </div> </div> <div class="frame frame_4"> <div class="frame-content"> <h2>Slide 4</h2> </div> </div> </div> </div> </div> <div id="controls"> <label for="frame1"></label> <label for="frame2"></label> <label for="frame3"></label> <label for="frame4"></label> </div> <div id="bullets"> <label for="frame1"></label> <label for="frame2"></label> <label for="frame3"></label> <label for="frame4"></label> </div> </div> </body> </html> style.css #frame { margin: 0 auto; width: 800px; max-width: 100%; text-align: center; } #frame input[type=radio] { display: none; } #frame label { cursor: pointer; text-decoration: none; } #slides { padding: 10px; border: 5px solid #0F0; background: #00F; position: relative; z-index: 1; } #overflow { width: 100%; overflow: hidden; } #frame1:checked~#slides .inner { margin-left: 0; } #frame2:checked~#slides .inner { margin-left: -100%; } #frame3:checked~#slides .inner { margin-left: -200%; } #frame4:checked~#slides .inner { margin-left: -300%; } #slides .inner { transition: margin-left 800ms cubic-bezier(0.770, 0.000, 0.175, 1.000); width: 400%; line-height: 0; height: 300px; } #slides .frame { width: 25%; float: left; display: flex; justify-content: center; align-items: center; height: 100%; color: #FFF; } #slides .frame_1 { background: #90C; } #slides .frame_2 { background: #F90; } #slides .frame_3 { background: #606; } #slides .frame_4 { background: #C00; } #controls { margin: -180px 0 0 0; width: 100%; height: 50px; z-index: 3; position: relative; } #controls label { transition: opacity 0.2s ease-out; display: none; width: 50px; height: 50px; opacity: .4; } #controls label:hover { opacity: 1; } #frame1:checked~#controls label:nth-child(2), #frame2:checked~#controls label:nth-child(3), #frame3:checked~#controls label:nth-child(4), #frame4:checked~#controls label:nth-child(1) { background: url(https://image.flaticon.com/icons/svg/130/130884.svg) no-repeat; float: right; margin: 0 -50px 0 0; display: block; } #frame1:checked~#controls label:nth-last-child(2), #frame2:checked~#controls label:nth-last-child(3), #frame3:checked~#controls label:nth-last-child(4), #frame4:checked~#controls label:nth-last-child(1) { background: url(https://image.flaticon.com/icons/svg/130/130882.svg) no-repeat; float: left; margin: 0 0 0 -50px; display: block; } #bullets { margin: 150px 0 0; text-align: center; } #bullets label { display: inline-block; width: 10px; height: 10px; border-radius: 100%; background: #ccc; margin: 0 10px; } #frame1:checked~#bullets label:nth-child(1), #frame2:checked~#bullets label:nth-child(2), #frame3:checked~#bullets label:nth-child(3), #frame4:checked~#bullets label:nth-child(4) { background: #444; } @media screen and (max-width: 900px) { #frame1:checked~#controls label:nth-child(2), #frame2:checked~#controls label:nth-child(3), #frame3:checked~#controls label:nth-child(4), #frame4:checked~#controls label:nth-child(1), #frame1:checked~#controls label:nth-last-child(2), #frame2:checked~#controls label:nth-last-child(3), #frame3:checked~#controls label:nth-last-child(4), #frame4:checked~#controls label:nth-last-child(1) { margin: 0; } #slides { max-width: calc(100% - 140px); margin: 0 auto; } } Output Comment More infoAdvertise with us Next Article How to Create a Slider using HTML and CSS? K kunaljain2608 Follow Improve Article Tags : Technical Scripter Web Technologies Web Templates Technical Scripter 2020 Similar Reads How to create a slideshow with HTML and CSS ? A slideshow can be used to display text or images that continuously scroll from one slide to the other to display its content. This article shows an approach to building a slideshow with the use of only HTML and CSS. It consumes less browser memory and takes less computation power as there is no Jav 3 min read How to Create Image Accordion using HTML and CSS ? In this article, we will see how to create an image accordion using HTML & CSS that is basically used for advertising purposes on e-commerce websites. An Accordion is often used to open multiple sections at full width & also content pushes the page content downward.Approach:Create an HTML fi 2 min read How to create image slider using HTML CSS and JavaScript ? An image slide, or slideshow, is a dynamic display of images that automatically transitions from one to the next, often with animations. To create an image slide, use HTML to structure the images, CSS for styling and animations, and JavaScript to control the timing and transitions between images.App 3 min read How to create Image Comparison Slider using CSS ? In this article, we will see how to create an Image Comparison Slider using CSS. The Image Comparison Slider essentially aids in the distinction of two photographs or products. As a result, the user can quickly determine which of the two products or two images in a better way.Approach: The approach 2 min read How to create a Portfolio Gallery using HTML and CSS ? The portfolio gallery is useful when your website contains different types of content or so much content. With the help of a portfolio gallery, you can easily display all the content on your front page to the user. To create a portfolio gallery we will need only HTML and CSS. We can use JavaScript a 4 min read Like