How to Create a Slider using HTML and CSS? Last Updated : 16 Oct, 2024 Comments Improve Suggest changes 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.Approach 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. 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 How to create a revealing sidebar using HTML CSS and JavaScript? A revealing sidebar is a hidden UI element that becomes visible upon user interaction, such as clicking or swiping, providing navigation links. The content of the page will rotate and the navigation bar will reveal itself when the menu button is clicked. ApproachCreate an HTML file with headings and 3 min read How To Create Toggle Switch by using HTML and CSS? A toggle switch allows users to switch between two states, typically "on" and "off," and is commonly used in forms and interactive elements. To create a toggle switch, we will use HTML and CSS. We can add different styles to the checkbox element to create a toggle switch.1. Basic Circular Toggle Swi 3 min read How to Create Sliding Text Reveal Animation using HTML & CSS ? In this article, we will implement sliding text reveal animation which can be used in personal portfolios, websites, and even in YouTube introduction videos to add an extra edge to our videos so that it looks more interesting and eye-catchy at first instance and the best part is that we will do that 3 min read How to create Image Stack Illusion using HTML and CSS ? In this article, we are going to create an illusion of images below the main image. It is the same as the image set of the gallery in an older version of Android. This is a simple project, we can achieve our target only by using HTML AND CSS.Overview of the project:Approach:Create a main div in whic 3 min read How to add a Range Slider using HTML ? In this article, we will learn how to add a Range Slider in HTML. So Geeks as we know that a Range Slider is used to select a particular value from a range of numbers. We have default range values from 0 to 100. Approach: First, we create an HTML document that contains an <form> element.Create 1 min read Like