:checked

In this chapter you will learn:

  1. Definition for Selector :checked
  2. An example showing how to use :checked CSS selector

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> <!--   j  a  v a 2s. c  o  m-->
<html> 
    <head> 
        <style> 
        :checked + span { 
            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

Next chapter...

What you will learn in the next chapter:

  1. Definition for Selector :not
  2. An example showing how to use :not CSS selector
Home » HTML CSS Tutorial » CSS Selector Reference
.class
#id
*
element
element,element
element element
element>element
element+element
element1~element2
:lang
:link
:visited
:active
:hover
:focus
:first-letter
:first-line
:first-child
:last-child
:only-child
:nth-child(n)
:nth-last-child(n)
:before
:after
:first-of-type
:last-of-type
:only-of-type
:nth-of-type(n)
:nth-last-of-type(n)
:root
:empty
:target
:enabled
:disabled
:checked
:not
::selection
[attribute]
[attribute=value]
[attribute~=value]
[attribute|=value]
[attribute^=value]
[attribute$=value]
[attribute*=value]