The Stiz Media, LLC

Making your website work for you

  • Styles for Genesis
    • FAQs
  • Cart
  • My Account
  • Home
  • Web Design
  • Portfolio
  • Resources
  • Blog
  • Contact

Powerful websites, with style.

Home » Blog » Radio buttons as toggle buttons with CSS

Radio buttons as toggle buttons with CSS

November 17, 2015 Andhi 46 Comments

Radio button toggles

Updated: March 15, 2019 to use Flexbox instead of float 🙌

Form inputs are annoying, let’s face it. There is a ton of data showing the more fields you have in a form, the higher the bounce rate of that form. I decided to play with radio buttons and try make them more like simple toggle buttons. After a bit of playing, I got it working in a clean, easy to use style. This makes your form very clear and fast to fill out for your user. Win.

Let’s see it in action

You can play with the CodePen below to see/feel it actually working.

See the Pen Radio button toggle switch by Mike Hemberger (@JiveDig) on CodePen.

Some key points to note:

  • The regular radio input is hidden with “appearance: none;” “display:none;” screen reader text CSS taken from Genesis.
  • The input label actually becomes the pseudo-buttons

Other then that, it’s pretty straightforward. Give it a try and let me know what you think in the comments!

Related Posts

  • Remove Avatar
    Remove Avatar from Genesis Author Box
  • A really organized life
    Genesis Page Templates in a subdirectory
  • Show Field Keys in ACF Pro
    Show Field Keys in Advanced Custom Fields Pro

Tutorials

‹ Front End Post Editing with Caldera Forms
Grid Column Generator ›

Try The Most Powerful Genesis Child Theme Ever Created

Mai Theme is the most customizable Genesis child theme (and plugin!) available. Check it out now!

Learn More @ MaiTheme.com

Our posts, directly to your inbox

Comments

  1. Robin says

    November 17, 2015 at 11:00 am

    Really slick–much more fun than the radio buttons! Nicely done!

    Reply
    • JiveDig says

      November 17, 2015 at 11:21 am

      Woot! Thanks Robin.

      Reply
  2. Trisha Cupra says

    November 25, 2015 at 8:52 pm

    Very nicely done, Mike. Great idea and elegant execution of it.

    Reply
    • JiveDig says

      November 26, 2015 at 12:32 am

      Thanks Trisha!

      Reply
  3. Fisya says

    February 26, 2016 at 1:29 pm

    i think so hard, but very easy.. Thanks Jive…

    Reply
    • JiveDig says

      February 26, 2016 at 1:31 pm

      Thanks Fisya. I thought the same thing. Turned out to be less code than anticipated. Very helpful for some forms with toggle buttons make more sense.

      Reply
  4. alexander says

    April 20, 2016 at 11:42 am

    How do i go with this when I have multiple questions that I want to use this code on the same page

    Reply
    • JiveDig says

      April 20, 2016 at 11:51 am

      Hey Alexander, just use the same CSS classes to target all the radio buttons.

      Reply
      • alexander says

        April 20, 2016 at 12:18 pm

        for some reason I have it that if I have 2 different fiends in the same form, when I check it the second one – the first one is being targeted

        Reply
        • alexander says

          April 20, 2016 at 3:28 pm

          Does anybody know how to fix my problem?

          Reply
          • alexander says

            April 20, 2016 at 5:25 pm

            I got it! I need to give every one of them a efferent ID FOR & NAME .. Thanks for this awesome design idea!!

  5. Mike says

    May 23, 2016 at 1:31 pm

    How do I animate the toggle so it slides right and left when switching instead of fading in and out?

    Reply
    • JiveDig says

      May 23, 2016 at 2:06 pm

      That would be really cool. There may be a CSS transition method, but it’s probably easiest to use a little jQuery. That’s beyond this tutorial/snippet, but let me know if you get something working!

      Reply
  6. Sandeep says

    May 31, 2016 at 5:23 am

    Awesome dude

    Reply
    • JiveDig says

      May 31, 2016 at 9:09 pm

      Thanks Sandeep.

      Reply
  7. navitha says

    June 10, 2016 at 2:45 am

    thanks for your help…it’s so useful…

    Reply
    • JiveDig says

      June 10, 2016 at 8:52 am

      Glad you liked it!

      Reply
  8. Richard says

    July 18, 2016 at 11:50 am

    How do you make it so you can tab on the toggle buttons. It looks good but doesnt seem accesible for keyboard only users. I would really like to use it but as long as it is accessible.

    Reply
    • JiveDig says

      August 26, 2016 at 3:18 pm

      I would really like to know the answer to that too.

      Reply
  9. phpMick says

    August 3, 2016 at 5:01 am

    Great, I will be using this in lots of places.

    Reply
  10. Damjan says

    August 26, 2016 at 2:41 pm

    Thanks a lot. You really knocked this out of the park. This is a really great solution for gravity form developers who want to make slicker forms. It’s helped me a lot.

    Reply
    • Len says

      August 3, 2017 at 2:06 pm

      @Damjan – I’m struggling to implement this in Gravity Forms. I think I’m very close, but I’m definitely missing something. Any chance you can share how you did it, or even share the final code snippets? I’ll buy you an expensive frothy coffee or something…

      Reply
      • mb says

        February 12, 2020 at 3:31 pm

        Did you get this to work with gravity forms ?

        Reply
        • Nicholas says

          June 2, 2021 at 9:40 pm

          I got it to work by making some minor adjustments and turning off the default css provided by gravity forms. Not sure how garbled my css will get posting in a comment, but here it goes. I also added “switch-field gf_list_inline” to my field’s css class list.


          /* radio as switch button */
          .switch-field .gfield_radio {
          display: flex;
          margin-bottom: 36px;
          overflow: hidden;
          }

          .switch-field .gfield_radio input {
          position: absolute !important;
          clip: rect(0, 0, 0, 0);
          height: 1px;
          width: 1px;
          border: 0;
          overflow: hidden;
          }

          .switch-field .gfield_radio label {
          background-color: #e4e4e4;
          color: rgba(0, 0, 0, 0.6);
          font-size: 14px;
          line-height: 1;
          text-align: center;
          padding: 4px 16px;
          margin-right: -7px;
          border: 1px solid rgba(0, 0, 0, 0.2);
          box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
          transition: all 0.1s ease-in-out;
          }

          .switch-field .gfield_radio label:hover {
          cursor: pointer;
          }

          .switch-field .gfield_radio input:checked + label {
          background-color: #a5dc86;
          box-shadow: none;
          }

          .switch-field .gfield_radio > div:first-of-type label {
          border-radius: 4px 0 0 4px;
          }

          .switch-field .gfield_radio > div:last-of-type label {
          border-radius: 0 4px 4px 0;
          }

          Reply
  11. Jagadish says

    September 29, 2016 at 10:02 am

    Its greatly working. Thank you..

    Reply
    • JiveDig says

      September 29, 2016 at 11:05 am

      Great! Thanks!

      Reply
  12. Ganesh says

    February 7, 2017 at 3:15 am

    It won’t change the checked attribute when input changed

    Reply
    • JiveDig says

      February 7, 2017 at 11:59 am

      Good catch. I’ve since started using the screen-reader-text CSS from Genesis to hide the element but keep it available. I’ve updated the post, this should work now for :checked.

      Reply
  13. motorola says

    February 13, 2017 at 9:41 am

    JiveDig, great idea. Ellegant, simple and clean. But (always a but) what you think of change background colors? Example: Yes (green), No (red)? Excuse my bad english

    Reply
    • JiveDig says

      February 13, 2017 at 2:41 pm

      No prob. You can target a specific button by


      .switch-field label[for=switch_right] {
      background-color: red;
      }

      Reply
      • motorola says

        February 14, 2017 at 7:48 am

        problem solved! thanks 🙂

        Reply
  14. eric says

    June 19, 2017 at 4:06 pm

    Where do you add this code?

    Reply
    • JiveDig says

      July 10, 2017 at 10:54 am

      You probably wouldn’t use this code as-is. You would modify it to fit the situation or the form HTML that you are using.

      Reply
  15. Paul Montgomery says

    February 16, 2018 at 9:43 pm

    Oh! Thanks. I will mod this to fit my issues, but clearly this is a sweet idea. Thank you.

    Reply
    • JiveDig says

      May 2, 2018 at 8:58 am

      No prob 🙂

      Reply
  16. vinit says

    May 2, 2018 at 2:43 am

    Awesome bro!

    Reply
    • JiveDig says

      May 2, 2018 at 8:58 am

      Thanks!

      Reply
  17. Flor says

    July 20, 2018 at 7:21 pm

    Wicked man! 🙂

    Reply
  18. thetizmedia says

    May 15, 2019 at 1:51 am

    Great style to those buttons. Don’t use xhtml closers () with html5, use html5 ones! () , thanks!

    Reply
    • JiveDig says

      May 15, 2019 at 11:05 am

      Thanks, but what do you mean closers?

      Reply
  19. Brent says

    July 23, 2019 at 1:13 pm

    It never updates the checked value. how are you supposed to get the value back from this when the form submits?

    Reply
    • JiveDig says

      July 23, 2019 at 2:30 pm

      This is just CSS, the form submitting is part of your HTML. We’re using this in a bunch of places without issue. Can you confirm the radio buttons submit properly without any custom CSS?

      Reply
  20. inkorea says

    July 25, 2019 at 5:01 am

    great!!!
    better than bootstrap button component

    Reply
  21. Alastair says

    August 1, 2019 at 11:49 am

    Hi Mike,

    I really love this, and I’m implementing it on my site (thanks). One thing I found is that on iPhone Safari, there’s a flicker when you move between options. I found that adding the following to .switch-field label removed the annoying flicker, making it smooth:

    -webkit-tap-highlight-color: transparent;

    Thought I’d let you know incase you want to include it.

    Thanks again

    Alastair

    Reply
    • JiveDig says

      February 12, 2020 at 3:43 pm

      Wow cool! I’ll have to test on mobile. TY.

      Reply
  22. fran says

    February 17, 2021 at 12:21 pm

    awesome!, thanks

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Our posts, directly to your inbox


Howdy, I'm Mike Hemberger. I like to build nice websites and web apps with WordPress and Genesis Framework.

I'm passionate about everything I do, and it resonates in all of my work.

Feel free to email, and you'll be speaking directly with me.

Recent Posts

Restful P2P Example

Create Posts 2 Posts ‘connections’ with the WordPress Rest API

EA Share Count SMS button

Add SMS share button to EA Share Count plugin

ACF Extras

ACF Extras officially launched! A community of code snippets and field groups

Remove Items from TinyMCE editor

Remove Buttons/Items From The WordPress TinyMCE Editor

  • My Account
  • Affiliate Area
  • Log In|Log Out
  • GitHub
  • Instagram
  • Twitter
  • YouTube

Copyright © 2025 · The Stiz Media, LLC · All Rights Reserved