CSS Selector :checked








Radio buttons and check boxes that are checkable can be selected through the :checked selector.

You can combine :checked with the negation selector to select unchecked elements.

Summary

CSS Version
3

CSS Syntax

:checked { 
   style properties 
}

Browser compatibility

:checked Yes 9.0 Yes Yes Yes




Example

An example showing how to use :checked CSS selector.

<!DOCTYPE HTML> 
<html> 
    <head> 
        <style> 
        :checked + span { <!-- w  ww .ja v  a2  s.c o m-->
            background-color: red; 
            color: white; 
            border: medium solid black; 
        } 
        </style> 
    </head> 
    <body> 
        <form method="post" action="http://yourServer/form"> 
            <input type="checkbox" id="myID" name="myName"/> 
        </form> 
    </body> 
</html>

Click to view the demo

There is no specific selector for unchecked elements, but you can combine :checked with the negation selector.