CSS Selectors

You are Here:

CSS Selectors

CSS selectors define the elements to which a set of CSS rules apply.

The following table provides a list of all CSS selectors.

SelectorQuick LookExplanationExample
**Selects all elementsRun
elementh2Select all <h2> elementsRun
element,elementh2, pSelects all <h2> elements and all <p> elementsRun
element elementdiv pSelects all <p> elements inside <div> elementsRun
element > elementdiv > kbdSelects only <kbd> that are direct children of <div>Run
element + elementh2 + pSelects all <p> elements that are placed immediately after <h2> elementsRun
element ~ elementh2 ~ pSelects all <p> elements that are placed after <h2> elementsRun
.class.pointSelects all element with class name 'point' i.e) class="point"Run
.class.class.point.myClassSelects all element with both class '.point' and '.myClass'.Run
.class .class.point .myClassSelects all elements with a class name '.myClass' inside the element with a class name '.point'Run
#id#pointSelects an element with id name 'point' i.e) id="point"Run
[attribute][target]Selects all elements with a target attributeRun
[attribute=value][target="_self"]Selects all elements with target="_self"Run
[attribute~=value][title~=fruit]Selects all elements with a title attribute containing the word "fruit"Run
[attribute|=value] [title|=fruit]Selects all elements with a title attribute value starting with "fruit-"Run
[attribute^=value][title^=fruit]Selects all elements with a title attribute value starting with "fruit"Run
[attribute$=value][title$=fruit]Selects all elements with a title attribute value ending with "fruit"Run
[attribute*=value][title*=fruit]Selects all elements with a title attribute value contains the substring of "fruit"Run
:linka:linkSelects all unvisited linksRun
:visiteda:visitedSelects all visited linksRun
:activea:activeSelects all active linksRun
:hovera:hoverSelects links on mouse overRun
:focusinput:focusSelects the input with focusRun
:validinput:validSelects all input elements with a valid valueRun
:invalidinput:invalidSelects all input elements with an invalid valueRun
:requiredinput:requiredSelects input elements with the "required" attribute specifiedRun
:optionalinput:optionalSelects input elements with no "required" attributeRun
:read-writeinput:read-writeSelects input elements whose value can be editedRun
:read-onlyinput:read-onlySelects input elements whose value CANNOT be editedRun
:in-rangeinput:in-rangeSelects input elements with a value within a specified rangeRun
:out-of-rangeinput:out-of-rangeSelects input elements with a value outside a specified rangeRun
:enabledinput:enabledSelects all enabled <input> elementRun
:disabledinput:disabledSelects all disabled <input> elementRun
:defaultinput:defaultSelects all default <input> elementRun
:checkedinput:checkedSelects all checked <input> elementRun
::placeholderinput::placeholderSelects input elements with placeholder textRun
:indeterminateinput:indeterminateSelects input elements that are in an indeterminate stateRun
:target#section1:targetSelects the target element with an id matching the URL's fragment.Run
:root:rootSelects the root element of a tree representing the documentRun
:lang(languageCode)p:lang(zh-Hans)Selects all <p> element with a lang attribute equal to "zh-Hans" Chinese (Simplified)Run
:emptyp:emptySelects all empty <p> elementRun
::beforea::beforeInsert something before the link of each <a> elementRun
::aftera::afterInsert something after the link of each <a> elementRun
::first-letterp::first-letterSelects the first letter of every <p> elementRun
::first-linep::first-lineSelects the first line of every <p> elementRun
::selection::selectionSelects the portion of an element that is selected by a userRun
:first-childp:first-childSelects every <p> element that is the first child of its parentRun
:first-of-typep:first-of-typeSelects every <p> element that is the first element of its type among a group of sibling elementsRun
:not(selector):not(p)Selects all element that is not a <p> elementRun
:nth-child(n)p:nth-child(3)Selects every <p> element that is the third child of its parentRun
:nth-last-child(n)P:nth-last-child(3)Selects every <p> element that is the third child of its parent, counting from the last childRun
:nth-last-of-type(n)p:nth-last-of-type(3)Selects every <p> element that is the third <p> element of its parent, counting from the last childRun
:nth-of-type(n)p:nth-of-type(3)Selects all <p> element that is the third <p> element of its parentRun
:only-of-typep:only-of-typeSelects all <p> element that is the only <p> element of its parentRun
:only-childp:only-childSelects all <p> element that is the only child of its parentRun
:last-childp:last-childSelects all <p> element that is the last child of its parentRun
:last-of-typep:last-of-typeSelects all <p> element that is the last <p> element of its parentRun

Reminder

Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in CSS.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author