Producing web pages
* HTML CSS DHTML XHTML A to Z of tags        Accessibility          Design

Pseudo class and element properties

Pseudo-classes and pseudo-elements are designed to let you control the look of things that you cannot define with the style of a tag. There is, for example, no tag that refers to the first line of a paragraph. There are not separate tags for the different states of a link.

Pseudo-classes distinguish among different tag types, for example visited links and active links represent two types of anchors. Pseudo-elements refer to sub-parts of elements, such as the first letter or first line of a paragraph.

Property

Description

Values

Example/p>

active
link
visited
hover

Customises the appearance of links and applies a roll-over effect

n/a

a:active { color:red }
a:link {color:blue}
a:visited {color:maroon}
a:hover { color:red; }

cursor

Changes the shape of the cursor

auto
crosshair
default
hand
move
e-resize
ne-resize
nw-resize
n-resize
se-resize
sw-resize
s-resize
w-resize
text
wait
help
url

{ cursor:hand; }

first-child

Applies a style to the first child of a tag

 

body:first-child {text-style: bold}

first-line

Applies to first line of text only

 

p:first-line {font-variant: small-caps font-weight: bold}

first-letter

Applies to first letter. Use to generate drop-capital effects

 

p:first-letter {font-size: 300% float: left}

focus

Apply style to the tag that is the current focus of input

 

input:focus {background-color: green}

lang

Applies a language to a tag

 

p:lang(en) {text-align: left}

@import

Imports a style sheet

url

@import url(mystyles.css);

!important

 

!important

{ font-weight:bold!important }