Attribute selectors

Unspecified value – a[title]

This selector can be used to change the style of an element that has a certain attribute, regardless of its value.

a[onclick]
{
color: #0000FF;
}

This examples adds the style to all a elements that have an ‘onclick’ attribute.

Exact match - a[href=#]

This allows you to select elements based on exact attributes values. The following example applies the style to all checkboxes.

input[type=checkbox]
{
outline: solid medium #3300CC;
}

Attribute matching – a[href~=# pixelcode.co.uk]

Using this selector multiple (space separated) values can be searched. The example applies the style to radio buttons and checkboxes.

input[type~=checkbox radio]
{
outline: dashed thin #33FFFF;
}

Start matching – p[lang|="en"]

This selector allows you to select attributes that are hyphen separated list of words starting with that selected. The example below with match “en” and “en-US” and any other language that starts with “en”.