VOOZH about

URL: https://www.geeksforgeeks.org/css/how-to-create-an-image-slider-works-with-radio-button/

⇱ How to create an image slider works with radio button? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to create an image slider works with radio button?

Last Updated : 23 Jul, 2025

A slider is a series of images that appear in sequence. Now, we will see an image slider working with radio buttons using HTML & CSS in which the image slides up, on clicking the radio button.

Approach

  • The HTML defines a container for an image slider with five radio buttons to control the slides. Each radio button corresponds to one image, allowing users to navigate through the images.
  • The CSS styles the slider, making it center-aligned within the viewport. It also styles the images, setting their size and making the slider overflow hidden to show only one image at a time.
  • The .imgs_slides class sets the container width to 500%, enabling the five images to be displayed in a horizontal row. Each slide is set to 20% width, ensuring they all fit within the container.
  • The radio buttons are hidden using display: none; to prevent them from showing. When a radio button is checked, CSS rules adjust the margin-left of the .first slide, shifting the visible image accordingly.
  • The navigation buttons are styled to appear below the images. They use the hover effect to change color on mouseover. Clicking a navigation button checks the corresponding radio button, triggering the CSS animation to display the appropriate image.

Example: The example below shows how to create an image slider that works with a radio button.

Output:

👁 OP
Comment