Skip to content

Custom Radio Buttons and Checkboxes with CSS

Accessible custom radio buttons and checkboxes with CSS are fairly straightforward to produce nowadays, but they do involve a fair bit of CSS.

The CSS features used for custom radio buttons and checkboxes include pseudo-elements, absolute/relative positioning, use of the appearance property, rounded corners, along with some borders and transforms to create a checkmark shape. The code below is the base styles for the radio buttons and checkboxes, but the demo includes some extra styles for aesthetic reasons.

I’ve included some comments in the code to indicate what each part does, should you need to customize it.

/* Context for relative positioning */ label { position: relative; } /* Base styles for both types of inputs */ input[type="radio"], input[type="checkbox"] { appearance: none; background: #fff; border: 2px solid #777; height: 1.5em; width: 1.5em; border-radius: 100%; vertical-align: text-bottom; position: relative; } /* Remove the circular shape from checkboxes */ input[type="checkbox"] { border-radius: 0; } /* Styles for the pseudo-elements */ input[type="radio"]::before, input[type="checkbox"]::before { content: ""; position: absolute; margin: auto; left: 0; right: 0; bottom: 0; overflow: hidden; top: 0; } /* Center of the checked radio button */ input[type="radio"]:checked::before { border: 5px solid transparent; border-radius: 100%; background: hotpink; margin: 4px; } /* The checkmark shape */ input[type="checkbox"]:checked::before { border-right: 5px solid hotpink; border-bottom: 6px solid hotpink; height: 90%; width: 30%; transform: rotate(50deg) translateY(-20%) translateX(-10%); } /* Some focus styles for accessibility */ input[type="radio"]:focus, input[type="checkbox"]:focus { outline: solid 1px; outline-offset: 2px; }
Code language: CSS (css)

For a full discussion of this topic along with some notes on accessibility, check out Scott O’Hara’s post and his full interactive demo. Full demo for this snippet is below.

Louis Lazaris

0 Comments
Inline Feedbacks
View all comments
Note: To the best of our knowledge, the information above and the snippet are accurate and up to date. However, in case you notice something wrong, please report snippet or leave a comment below.
Back to Snippets

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!

Most Searched Articles

Best JavaScript Libraries and Frameworks: Try These 14 in 2024

In this post, we look at the best JavaScript libraries and frameworks to try out this year. Why? Well, with JavaScript being available in every web browser, this makes it the most accessible programming language of ...

30 Best Free WordPress Themes for 2024 (Responsive, Mobile-Ready, Beautiful)

If you're looking for only the best free WordPress themes in the market for this year, then you're in the right place. We have more than enough such themes for you right ...

12 Best WordPress Hosting Providers of 2024 Compared and Tested

Looking for the best WordPress hosting that you can actually afford? We did the testing for you. Here are 10+ best hosts on the market ...

Handpicked Articles

How to Make a WordPress Website: Ultimate Guide for All Users – Beginners, Intermediate, Advanced

Many people wonder how to make a WordPress website. They’ve heard about WordPress, its incredible popularity, excellent features and designs, and now they want to join the pack and build a WordPress website of their own. So, where does one get ...

How to Start an Ecommerce Business: Ultimate Guide for 2024

Is this going to be the year you learn how to start an eCommerce business from scratch? You’re certainly in the right place! This guide will give you a roadmap to getting from 0 to a fully functional eCommerce business. ...