Dr. Rob Tutoring

a small sheep logo

Attribute Selectors


Presence and Value Selectors

These help select based on whether or not there is an attribute present. The following all select exact match plus other stuff.Using the attribute "class" as an example:

with the following CSS:


    li[class] {
    font-size: 120%;
    }

    li[class="a"] {
    background-color: yellow;
    }

    li[class~="a"] {
    color: red;
    }

    li[class|="a"] {
    font-style: italic;
    }

Substring matching selectors


    li[class^="c"] {
    font-size: 150%;
    }

    li[class$="c"] {
    background-color: yellow;
    }

    li[class*="c"] {
    color: red;
    }