CSS: Selector Syntax

By Xah Lee. Date: . Last updated: .

Here's complete list of CSS Selectors syntax. For a tutorial, see CSS: Selector Tutorial

Match by Tag Name

(This is called universal selector)

Match any element. [see HTML Tags Complete List]

/* make everything red */
* {color:red;}
(This is called type selector)

Match any element with tag name tag.

/* make all paragraphs red */
p {color:red;}

Match by Attribute

Match by Checking Parent

Match by Checking Children


Match tag that has no children.

🛑 WARNING: It must not have any inner-text, not even space or newline.

Match by Checking Sibling Relations



Match element with tag name tag if it does not match selector expr.

/* match p, only if it is not class x */
p:not([class="x"]) {

Pseudo-Class Selectors

CSS Selectors