The :checked pseudo-class in CSS selects elements when they are in the selected state. It is only associated with input (<input>) elements of type radio and checkbox . The :checked pseudo-class selector matches radio and checkbox input types when checked or toggled to an on state. If they are not selected or checked, there is no match.

So when a checkbox is checked, and you are targeting the label immediately after it:

input[type=checkbox] + label {
  color: #ccc;
  font-style: italic;
input[type=checkbox]:checked + label {
  color: #f00;
  font-style: normal;

The label text will turn from grey italic to red normal font.

<input type="checkbox" id="ossm" name="ossm"> 
<label for="ossm">CSS is Awesome</label> 

The above is an example of using the :checked pseudo-class to make forms more accessible. The :checked pseudo-class can be used with hidden inputs and their visible labels to build interactive widgets, such as image galleries.

More Resources

Browser Support

Chrome Safari Firefox Opera IE Android iOS
Any 3.1+ Any 9+ 9+ any any


    Permalink to comment#

    “:checked” selector work to find out the checkbox who are checked .

    html code::

    jQuery code::
    alert($(“#Demo :checked”).attr(‘id’));


    • Paul Garcia
      Permalink to comment#

      Not just to find out the element checked but also to style it:

      #Demo:checked { color:red; text-decoration:underline; } or
      input[type=”radio”]:checked{ color:red; … }

  2. Kuro
    Permalink to comment#

    CSS is Awesome

    if I move the order, how to write the css code?
    I’ve repetition something like that, but confuse how to make it simpler like you had

  3. Kevin Boucher
    Permalink to comment#

    The above is an example of using the :checked pseudo-class to make forms more accessible.

    I’m using this technique to hide/show navigation menus in a responsive layout. However, I’m discovering that since the LABEL tag cannot have FOCUS, that this technique is not at all accessible (at least not to keyboard users). Is there a way around this?

    Also, in my experience the adjacent sibling selector (‘+’) does not work in iOS (must use the general sibling selector ‘~’).

    • Camilla
      Permalink to comment#

      IOS 8 seems to be sensitive to this. Fixed my problem to change from + to ~ ! Thanks!

  4. Dennis Claassen
    Permalink to comment#

    Might be worth mentioning that unchecked checkboxes can be specifically targeted by using :not(:checked).

    Browser support is almost the same. See http://css-tricks.com/almanac/selectors/n/not/

    • Klaus Schleusener
      Permalink to comment#

      Hello Dennis, thank you very much for your comment.

  5. Skumbabs
    Permalink to comment#


    any ideas/tricks to use it on ie8 as long as :checked does not exist?


    • Tanya

      Hi, for ie8 I add class ‘checked’ and use
      input[type=checkbox].checked + label {
      color: #f00;
      font-style: normal;

    Permalink to comment#

    there are various types of input fields in a HTML page such as text, number, email, radio, checkbox. Now how will i modify style to all input
    except radio and check box. is it right code if i do that this way :

    input:not([typy=”radio & checkbox”]){



  7. Richard Bultitude
    Permalink to comment#

    Sadly putting the label after the relevant field means that the field/label pair are not accessible according to the WCAG 2.0. There are a lot of examples of this field + label pattern out there but in order for the markup to make sense to all users and assistive technology the label should come first.

    I await the day we can use selectors which target the preceding item

    • Richard Bultitude
      Permalink to comment#

      Apologies, the above statement isn’t actually correct, it was the Surfright standards that stipulated this. Labels after radios and checkboxes are valid. The WCAG 2.0 guidelines state that radiobuttons and checkboxes can have the label positioned after and (as far as I can tell) that this is a matter of visual positioning only.

  8. every
    Permalink to comment#

    Thank you man!

  9. Gunnar Bittersmann
    Permalink to comment#

    Browser support: Android: any?

    No, unfortunately not. You named it. Android 4.2 is still affected. Your proposed hack has severe performance issues on some devices.

    I don’t have an other solution, though.

  10. mikhil jose
    Permalink to comment#

    Is there any solution if we want to repeat the “id” along with “check box” more times????? I need more check boxes and labels in my project..
    (Excuse me for my worst English)

  11. Jugal
    Permalink to comment#

    Can any one tell this

    i have two radio button.

    If i check one radio button , i want that other radio button should be checked. means check other radio button on another radio button’s checked.

  12. Jugal
    Permalink to comment#


    One more thing it should be done by HTML and CSS. Without any use of javascript

    • Jamie
      Permalink to comment#

      Hey Jugal. You can’t do that with radio inputs. Only one radio input can be selected at a time. Instead you want to use:
      However you will need to use some JS to toggle other inputs if one is selected. Can’t be done solely with HTML and CSS.

  13. Somnath Mukherjee
    Permalink to comment#

    All CSS3 pseudo-classes are pretty cooool. They not just make the life of a web designer so easy but also they focus on more semantic, clean & simpler code. Not to mention, CSS4 has already offered us more yummy awesomeness.

  14. Jay Tell
    Permalink to comment#

    Be warned this code will NOT work as expected in Safari 5.0.1 if you apply it to UL element.

  15. Tim Plummer

    Has anyone tried to do this with :focus?

    • Xahjck
      Permalink to comment#

      I just finished something using the :focus selector yesterday. I styled my label as if it were a ‘<div>‘ inside of an actual <div>. The :focus selector runs a check on the checkbox, not the label itself so you can’t use display:none on it. To combat that, I simply moved it up and left 9999px from the page. Also, I need a checkbox for each of my labels(‘<div>‘s) so I have to have CSS instructions for each one individually which is why I’ve numbered my id tags. This works for me because I have a known amount of boxes on my page.

      If someone knows an easier (or more efficient way) of using selectors, feel free to correct me. I just started dawdling with CSS about a week ago.

      I’m using Firefox 38.0.5 for all of this on a Windows 7.


      #cb1_id:focus + label:nth-of-type(1) {
        *--What to do when focused--*
      #cb1_id:not(:focus) + label:nth-of-type(1) {
        *--What to do when focus is lost--*


      <input id="cb1_id type="checkbox" style="position:fixed; left:-9999px; top:-9999px;">
      <label for="cb1_id" class="main_div">
  16. Marc
    Permalink to comment#

    I’ve implemented an off canvas menu on my site but the sitewrap won’t slide out to reveal the menu on iOS 4 and 5, it works just fine on all other devices and browsers. Nothing happens at all when the nav trigger is pressed so I’m assuming it’s something to do with the pseudo element ‘:checked’.

    I would appreciate any help anyone can give, it’s driving me nuts Lol!

    Here’s a link to my code on codepen:

    Thanks in advance


  17. Marc
    Permalink to comment#

    I didn’t realise anonymous pens on codepen couldn’t be submitted…Hope this one works:



  18. Mat Harden
    Permalink to comment#

    It seems to be broken again for Chrome on iOS 9. See this issue https://code.google.com/p/chromium/issues/detail?id=534210

    :checked + p /* works */
    :checked ~ p /* fails */
  19. adir
    Permalink to comment#

    this works without JS

  20. vbvbvb
    Permalink to comment#


  21. MJB
    Permalink to comment#

    How would I use css to select read only radio buttons?

  22. MJB
    Permalink to comment#

    How would I use css to select radio buttons that are both read-only and checked?

    • Mat
      Permalink to comment#

      But readonly is ignored on radio buttons, so it’s nonsensical.

  23. siva
    Permalink to comment#

    How to disable radio button after selection

  24. Ajay Gopal Shrestha
    Permalink to comment#

    how much will it make a difference if I use label as parent and span or div as the sibling and not use for and id.
    for list of checkbox, id might have to be generated unique and if we donot have to use id, would be a lot cleaner

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

We have a pretty good* newsletter.