CSS Selectors

CSS selectors are patterns used to select the element(s) you want to style.

Examples of some CSS selectors:

SelectorExample
.class.intro
#id#firstname
**
elementp
element,elementdiv, p
element elementdiv p
element>elementdiv > p
element+elementdiv + p
element1~element2p ~ ul
[attribute][target]
[attribute=value][target=_blank]
[attribute~=value][title~=flower]
[attribute|=value][lang|=en]
[attribute^=value]a[href^=”https”]
[attribute$=value]a[href$=”.pdf”]
[attribute*=value]a[href*=”w3schools”]
:activea:active
::afterp::after
::beforep::before
:checkedinput:checked
:disabledinput:disabled
:emptyp:empty
:enabledinput:enabled
:first-childp:first-child
::first-letterp::first-letter
::first-linep::first-line
:first-of-typep:first-of-type
:focusinput:focus
:hovera:hover
:in-rangeinput:in-range
:invalidinput:invalid
:lang(language)p:lang(it)
:last-childp:last-child
:last-of-typep:last-of-type
:linka:link
:not(selector):not(p)
:nth-child(n)p:nth-child(2)
:nth-last-child(n)p:nth-last-child(2)
:nth-last-of-type(n)p:nth-last-of-type(2)
:nth-of-type(n)p:nth-of-type(2)
:only-of-typep:only-of-type
:only-childp:only-child
:optionalinput:optional
:out-of-rangeinput:out-of-range
:read-onlyinput:read-only
:read-writeinput:read-write
:requiredinput:required
:root:root
::selection::selection
:target#news:target
:validinput:valid
:visiteda:visited