CSS Selector :checked

Description

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.

Example


<!DOCTYPE HTML> 
<html> 
    <head> 
        <style> 
        :checked + span { <!--from w w w.j a va 2  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

The code above generates the following result.

:checked




















Home »
  HTML CSS »
    HTML CSS Reference »




HTML Tag Reference
CSS Reference
CSS Selector Reference
Encoding Reference