CSS pseudo-classes are used to add special effects to some selectors.
The syntax of pseudo-classes:
CSS classes can also be used with pseudo-classes:
Links can be displayed in different ways in a CSS-supporting browser:
Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective!
Note: a:active MUST come after a:hover in the CSS definition in order to be effective!
Note: Pseudo-class names are not case-sensitive.
Pseudo-classes can be combined with CSS classes:
If the link in the example above was visited, it will be displayed in red.
The :first-child pseudo-class matches a specified element that is the first child of another element.
Note: For :first-child to work in IE a <!DOCTYPE> must be declared.
In the following example, the selector matches any <p> element that is the first child of any element:
In the following example, the selector matches the first <i> element in all <p> elements:
In the following example, the selector matches all <i> elements in <p> elements that are the first child of another element:
The :lang pseudo-class allows you to define special rules for different languages.
Note: Internet Explorer 8 (and higher) supports the :lang pseudo-class if a <!DOCTYPE> is specified.
In the example below, the :lang class defines the quotation marks for q elements with lang="no":
Add different styles to hyperlinksThis example demonstrates how to add other styles to hyperlinks.
Use of :focusThis example demonstrates how to use the :focus pseudo-class.
The "CSS" column indicates in which CSS version the property is defined (CSS1 or CSS2).
Your Query was successfully sent!