Selectors
Selectors are used to target the HTML elements on our web pages that we want to style. There are a wide variety of CSS selectors available, allowing for fine grained precision when selecting elements to style.
Basic Selectors
# Element
Selects an element by its type.
Headline1
Paragraph
Paragraph
# .Class
Selects an element by the class attribute value, which may be reused multiple times per page.
Headline1
Paragraph
Paragraph
# #ID
Selects an element by the id attribute value, which is unique and to only be used once per page.
Headline1
Paragraph
Paragraph
Child Selectors
# Descendant
Selects an element that resides anywhere within an identified ancestor element.
Headline1
Paragraph
Paragraph
Paragraph
# Direct > Child
Selects an element that resides immediately inside an identified parent element.
Headline1
Paragraph
Paragraph
Paragraph
Sibling Selectors
# General ~ Sibling
Selects an element that resides immediately inside an identified parent element.
Paragraph
Headline1
Paragraph
Paragraph
Paragraph
# Adjacent + Sibling
Selects an element that follows directly after the prior element, in which both elements share the same parent.
Paragraph
Headline1
Paragraph
Paragraph
Paragraph
Attribute Selectors
# [Attribute Present]
Selects an element if the given attribute is present.
# [Attribute="Equals"]
Selects an element if the given attribute value exactly matches the value stated.
# [Attribute*="Contains"]
Selects an element if the given attribute value contains at least once instance of the value stated.
# [Attribute^="BeginsWith"]
Selects an element if the given attribute value begins with the value stated.
# [Attribute$="EndsWith"]
Selects an element if the given attribute value ends with the value stated.
# [Attribute~="Spaced Value"]
Selects an element if the given attribute value is whitespace-separated with one word being exactly as stated.
# [Attribute|="Hyphenated-Value"]
Selects an element if the given attribute value is hyphen-separated and begins with the word stated.
Pseudo Classes
# :hover
Selects an element when a user has hovered their cursor over it.
Paragraph
Headline1
Paragraph
# :active
Selects an element when a user has engaged it.
Headline1
# :focus
Selects an element when a user has engaged it.
# :enabled
Selects an element in the default enabled state.
# :disabled
Selects an element in the disabled state, by way of the disabled attribute.
# :checked
Selects a checkbox or radio button that has been checked.
# :first-child
Selects an element that is the first within a parent.
Paragraph
Headline1
Headline1
Paragraph
Paragraph
# :last-child
Selects an element that is the last within a parent.
Paragraph
Headline1
Headline1
Paragraph
Paragraph
# :first-of-type
Selects an element that is the first of its type within a parent.
Paragraph
Headline1
Headline1
Paragraph
Paragraph
# :last-of-type
Selects an element that is the last of its type within a parent.
Paragraph
Headline1
Headline1
Paragraph
Paragraph
# :nth-child()
Selects an element that matches the given number or expression, counting all elements from the beginning of the document tree.
Paragraph
Headline1
Headline1
Paragraph
Paragraph
Headline1
# :nth-last-child()
Selects an element that matches the given number or expression, counting all elements from the end of the document tree.
Paragraph
Headline1
Headline1
Paragraph
Paragraph
Headline1
# :nth-of-type()
Selects an element that matches the given number or expression, counting only elements of its type from the beginning of the document tree.
Paragraph
Headline1
Headline1
Paragraph
# :nth-last-of-type()
Selects an element that matches the given number or expression, counting only elements of its type from the end of the document tree.
Paragraph
Headline1
Headline1
Paragraph
# :target
Selects an element whose ID attribute value matches that of the URI fragment identifier.
Headline1
Click me!# :not()
Selects an element not represented by the stated argument.
Paragraph
Paragraph
Paragraph
Paragraph
# :root
Selects the highest-level parent element in the DOM.
Pseudo Elements
# :before
Creates a pseudo-element inside the selected element at the beginning.
Headline1
# :after
Creates a pseudo-element inside the selected element at the end.
Headline1
# ::selection
Selects the part of a document which has been selected by the user.
Select This text