C. CSS Selectors, Levels 3 and 4

C

CSS Selectors, Levels 3 and 4

The following table lists the selectors in the Selectors Level 4 Editor’s Draft (, December 2017).

Note that selectors marked “(Level 4)” are new and may not yet be implemented by browsers. Check and be sure to test well if you use them. All other selectors are part of CSS3 and are generally well supported.

Selector

Type of selector

Description

Simple selectors and combinators

*

Universal selector

Matches any element.

A

Type selector

Matches the name of an element.

A, B

Compound selector

Matches elements A and B.

A B

Descendant combinator

Matches element B only if it is a descendant of element A.

A>B

Child combinator

Matches any element B that is a child of element A.

A+B

Next-sibling combinator

Matches any element B that immediately follows any element A, where A and B share the same parent.

A~B

Subsequent-sibling combinator

Matches any element B that is preceded by A, where A and B share the same parent.

Class and ID selectors

.classname A.classname

Class selector

Matches the value of the class attribute in all elements or in a specified element.

#idname A#idname

ID selector

Matches the value of the id attribute in an element.

Attribute selectors

A[att]

Simple attribute selector

Matches any element A that has the given attribute defined, whatever its value. ...

Get Learning Web Design, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.