Close Menu
    Facebook X (Twitter) Instagram Pinterest YouTube Bluesky WhatsApp TikTok Threads RSS
    WikiTechLibrary
    • Converters & Media
    • Web Tools
    • Finance & Tax
    • Utility & Bills
    • Vehicle Tax
    WikiTechLibrary

    Custom Radio Buttons | HTML & CSS

    By Ali RehmanNovember 10, 2022Updated:September 8, 2026No Comments4 Mins Read
    Facebook Twitter WhatsApp Threads Copy Link
    custom radio buttons

    Disappointed with the radio buttons’ usual appearance? And you looking for a custom radio button to complement your user interface or website’s visual style? If so, you’ve found the right guide! To make radio inputs seem good in CSS, you need to do more than just change their background color and border width.

    There are a few different methods that have emerged to style these radio buttons, but they’re all very difficult. Here we won’t need any fancy techniques or graphics to make a unique checkbox that fits your needs exactly. Just use plain old CSS and you’re good to go. Here, the ‘labels’ and ‘:checked’ selectors will be used as a useful little trick.

    Let’s get started with the HTML portion of our guide right now. To start, we’ll make a box to enclose and centrally locate our radio inputs. In the following step, we’ll make two inputs called “radio” for our radio. Keep in mind that the names of the radio buttons must match.

    HTML Code

    The next step is to give each of these radio inputs a label. Using the identifiers, we connect the inputs to their respective labels. Two labels are generated, label for=’opt1′ and label for=’opt2′. In this case, we’re making a YES/NO radio button, therefore let’s put the words “Yes” and “No” within a span element for the labels.

    <div class="container">
       <input type="radio" name="radio" id="opt1">
       <label for="opt1" class="label1">
           <span>YES</span>
       </label>
       <input type="radio" name="radio" id="opt2">
       <label for="opt2" class="label2">
           <span>NO</span>
       </label>
    </div>

    CSS Code

    Centering The Container

    To get started with CSS, we must first remove the default padding and margin from the content by setting them to 0. We then use the hex code #f5f5f5 to fill the rest of the page with a soothing off-white hue. Flex layout is being used to concentrate our container in this example.

    body {
       background-color: #f5f5f5;
       padding: 0;
       margin: 0;
       height:100vh;
       width: 100vw;
       display: flex;
       justify-content: center;
       align-items: center;
    }

    Styling The Container

    The next step is to provide the container’s dimensions: 260px*90px. So that the container looks to be floating above the ground, we give it a very slight box shadow.

    .container {
       background-color: white;
       height: 90px;
       width: 260px;
       position: absolute;
       box-shadow: 0 0 30px 0px #d1d1d1;
       overflow: hidden;
    }

    Hiding Radio Inputs

    First and foremost, we need to ensure that our radio buttons for default input are set to display none.

    input[type="radio"] {
       display: none;
    }

    Styling Labels

    We need to add labels on these previously hidden radio buttons. We need to specify a width and height for labels to do this. Please keep in mind that the height of our labels should be precise twice the height of the container when we are making those adjustments. Labels should also be exactly half as wide as their respective containers. These labels will serve as radio buttons from now on.

    We have decided to go with a solid linear gradient made up of the colors #ffffff and #2c2c2c as the background image. The gradient’s direction is chosen from top to bottom. Since the height of the backdrop is now equal to that of the container, it appears to be spilling out of its containers. In this case, we need to hide the container’s overflow. Because of the overflow background has disappeared.

    To ensure that the labels transition properly, we set it to 0.5 seconds.

    .label1,.label2 {
       display: block;
       height: 180px;
       width: 130px;
       background-size: 130px 180px;
       background:linear-gradient(
    	   to bottom,
    	   white 0,white 90px,
     	   #2c2c2c 90px, #2c2c2c 180px
    	   );
       position: absolute;
       top:0;
       transition: 0.5s;
       color: #2c2c2c;
    }

    Positioning Labels

    Position this ‘No’ option to the right side of container by setting the right property to 0. Keep in mind that absolute position is being used here.

    .label2 {
       right: 0;
    }

    Basic Typography

    Make both span elements appear better by applying some simple typography styling. The flex property is used once more to center the span element’s content.

    span {
       display: flex;
       height: 90px;
       width: 130px;
       justify-content: center;
       align-items: center;
       font-family: 'Rubik',sans-serif;
       font-weight: 500;
       font-size: 22px;
    }

    Styling for ‘:checked’ state

    Finally, when a user selects an input, we utilize the ‘input: checked + label’ selector to highlight the adjacent label element. When the user selects a label, the related radio button is checked. We moved the labels’ background position up 90px to make the checked labels seem highlighted in black (#2c2c2c). Finally, we’ll change the font color to white.

    input:checked + label {
       background-position: 0 -90px;
       color: white;
       transition: 1s;
    }

    After this, there will be no further tutorials. I’m hoping you’ve acquired some comfort with changing the appearance of radio buttons to meet your requirements.

    Share. Facebook Twitter Pinterest LinkedIn Email WhatsApp Threads
    Ali Rehman

      Rehman is focusing on delivering easy-to-follow tutorials related to social media, technology, and daily life hacks. With a passion for simplifying digital tasks, he provides practical guides that help readers enhance their social media presence and tackle everyday challenges with ease.

      Related Articles

      image

      TCL’s 75-Inch QD-Mini LED Art TV Is $600 Off for Black Friday

      Rockchip Motherboard Suppliers in China: Buyer Checklist and Uniwin-Global Overview

      A Lip-Synced Rap Clip From Face Photos You Already Have

      Why Shopping For Quotes Online Could Save Your Business Time and Money

      tcl-60xe-nxtpaper-5g-puts-a-different-screen-at-the-center-of-its-169-99-offer

      TCL 60XE NXTPAPER 5G puts a different screen at the center of its $169.99 offer

      A Practical Workflow for Managing a Multilingual Restaurant Menu

      JOIN THE CONVERSATION

      A little discussion goes a long way.

      Ask a question, share your experience, or help someone find an answer.

      0 comments
      NewestOldestMost helpfulUnanswered
      ◇

      There is room for your perspective.

      No discussions match this view yet.

      This discussion is closed to new comments.

      MOST VIEWED
      how to clean macbook screen safely How To

      How To Safely Clean Your MacBook Screen Without Damaging It

      By Muqadas Fatima
      roblox grimoires era Gaming

      Grimoires Era Codes 2024

      By Ahmad Ali
      lost souls codes Gaming

      All Lost Souls Codes

      By Ali Raza
      gunfight arena codes Gaming

      Gunfight Arena Codes 2024

      By Ahmad Ali
      What's New

      AI Video Generator Clips Need a Real Compression Preview

      November 12, 2026
      image

      Made in America and Priced at $7,999: StarBot Launches Spark Humanoid Robot

      November 5, 2026
      tiktok adds voice notes and image carousels in comments

      TikTok Adds Voice Notes and Image Carousels in Comments

      September 4, 2026
      google messages adds ai detection to chat photos

      Google Messages Adds AI Detection to Chat Photos

      September 3, 2026
      © 2026 WIKITECHLIBRARY | All Right Reserved
      • About Us
      • Contact Us
      • Privacy Policy
      • Terms & Conditions
      • Disclaimer

      Type above and press Enter to search. Press Esc to cancel.