Quick Reference
This is a quick reference list of CSS selectors and how they work in selecting HTML elements to apply styling.
- CSS – * SelectorThe * selector selects all HTML elements in the document, and if used together with another element can be used to select all that element’s child elements.
- CSS – :active SelectorThe :active selector is used to select the active link, which becomes active when it’s clicked.
- CSS – ::after SelectorThe ::after pseudo-element inserts something after the content of a selected element.
- CSS – [attribute] SelectorThe selector selects every HTML element with the specified attribute.
- CSS – [attribute=value] SelectorThe selector selects every element with both the specified attribute and specified value.
- CSS – [attribute~=value] SelectorThe selector selects every element with a specific attribute that has a value containing a specified stand-alone word.
- CSS – [attribute|=value] SelectorThe selector selects every element with a specific attribute that has a value equal to or starting with a specified value.
- CSS – [attribute^=value] SelectorThe selector selects every element with a specific attribute that starts with a value beginning with a specified string.
- CSS – [attribute$=value] SelectorThe selector selects every element with a specific attribute that has a value ending in a specified string.
- CSS – [attribute*=value] SelectorThe selector selects every element with a specific attribute that has a value containing a specified string even as part of another word.
- CSS – ::before SelectorThe ::before pseudo-element inserts something before the content of a selected element.
- CSS – :checked SelectorThe :checked selector matches every checked input element for radio buttons, checkboxes, and option elements.
- CSS – .class SelectorThe .class selector selects all HTML elements with a specific class, which may include multiple elements on the page.
- CSS – :default SelectorThe :default selector selects the default form element in a group of related elements, and can only be used on button, input type=”checkbox”, input type=”radio”, and option elements.
- CSS – :disabled SelectorThe :disabled selector matches all disabled form elements.
- CSS – Element SelectorThe element selector selects all HTML elements with a specific element tag name.
- CSS – Element > Element SelectorThe element > element selector is used to select elements with a specific parent. The element > element selector can be used along with the #id, .class, and any other selector.
- CSS – Element + Element SelectorThe Element + Next selector selects the very next element specified after (not within) the first specified element. The element + element selector can be used along with the #id, .class, and any other selector.
- CSS – Element ~ Element SelectorThe element ~ element selector selects sibling elements that appear after the specified element. Both of the specified elements must share the same parent.
- CSS – : empty SelectorThe :empty selector selects empty HTML elements, which means an element without any child elements or text.
- CSS – :enabled SelectorThe :enabled selector matches all enabled form elements.
- CSS – :first-child SelectorThe :first-child selector selects all HTML elements of a specified type that are also the first child of their parent element.
- CSS – ::first-letter SelectorThe ::first-letter selector is used to select the first letter of a specified, block-level element such as a paragraph or heading.
- CSS – ::first-line SelectorThe ::first-line selector is used to select the first line of text of a specified, block-level element such as a paragraph or heading.
- CSS – :first-of-type SelectorThe :first-of-type selector selects all elements that are the first child of a specified type of their parent element.
- CSS – :focus SelectorThe :focus selector selects the element that currently has focus.
- CSS – :fullscreen SelectorThe :fullscreen selector is used to select any elements that are in full-screen mode.
- CSS – :hover SelectorThe :hover selector selects elements when you mouse over them, and is commonly used for links and images with links, but can be used on any element.
- CSS – #id SelectorThe #id selector selects an HTML element with a specific id. HTML only allows for one unique #id per document.
- CSS – :in-range SelectorThe :in-range selector selects elements with a value that is within a specified range, and only works for input elements with min/max attributes.
- CSS – :indeterminate SelectorThe :indeterminate selector selects form elements that are in an indeterminate state, and can only be used on input type=”checkbox”, input type=”radio”, and progress elements.
- CSS – :invalid SelectorThe :invalid selector selects form elements with a value that does not validate according to the element’s settings.
- CSS – :lang SelectorThe :lang selector is used to select elements with a lang attribute with a specified value (e.g., lang = “en” or lang = “en-us”).
- CSS – :last-child SelectorThe :last-child selector selects all HTML elements of a specified type that are also the last child of their parent element.
- CSS – :last-of-type SelectorThe :last-of-type selector selects all elements that are the last child of a specified type of their parent element.
- CSS – :link SelectorThe :link selector is used to select unvisited links, and will not style links you have already visited.
- CSS – ::marker SelectorThe ::marker selector selects the marker of a list item (the bullet in an unordered list or number in an ordered list).
- CSS – :not() SelectorThe :not() selector selects all elements except the specified element.
- CSS – :nth-child() SelectorThe :nth-child() selector selects all specified elements that are the nth child of their parent, regardless of all the children’s types.
- CSS – :nth-last-child() SelectorThe :nth-last-child() selector selects all specified elements that are the nth child of their parent counting from the last child.
- CSS – :nth-last-of-type() SelectorThe :nth-last-of-type() selector selects all elements that are the nth child of a specified type, of their parent, counting from the last child.
- CSS – :nth-of-type() SelectorThe :nth-of-type() selector selects all elements that are the nth child of a specified type, of their parent.
- CSS – :only-child SelectorThe :only-child selector selects every element that is the only child of its parent. If the parent has multiple child elements, it will NOT be selected.
- CSS – :only-of-type SelectorThe :only-of-type selector selects every element that is the only child of its type, of its parent.
- CSS – :optional SelectorThe :optional selector selects form elements which are optional (those without the required attribute).
- CSS – :out-of-range SelectorThe :out-of-range selector selects elements with a value that is NOT within a specified range, and only works for input elements with min/max attributes.
- CSS – ::placeholder SelectorThe ::placeholder selector selects form inputs with placeholder text.
- CSS – :read-only SelectorThe :read-only selector selects form inputs which are “readonly” (those with a “readonly” attribute).
- CSS – :read-write SelectorThe :read-write selector selects form inputs which are “readable” and “writeable” (those with no “readonly” or “disabled” attributes).
- CSS – :required SelectorThe :required selector selects form inputs which are required (those with the required attribute).
- CSS – :root SelectorThe :root selector matches the document’s root element, which is always the HTML element.
- CSS – ::selection SelectorThe ::selection selector matches the portion of an element that is selected by a user, and is most often used to set the background color of selected text.
- CSS – :target SelectorThe :target selector selects the current active target anchor element on the page (the element being linked to).
- CSS – :valid SelectorThe :valid selector selects form inputs with a value that properly validates according to the element’s settings.
- CSS – :visited SelectorThe :visited selector is used to select already visited links.
CSS Notes:
- The “inherit”, “initial” and “unset” keywords can be used with any CSS property to set its value
- In CSS there are many ways to express a color value in a property
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.