CSS Almanac → Pseudo-Selectors
This is a work in progress — and we could use your help! Learn about writing for CSS-Tricks and how to contribute to the CSS Almanac.
:active
The :active pseudo selector changes the appearance of a link while it is being activated (being clicked on or otherwise […]:activea:active { color: #f8a100; }Continue Reading:any-link
The :any-link pseudo-class in CSS provides a method for selecting elements that are the source anchor of a hyperlink. If […]:any-link.element:any-link { color: red; }Continue Reading:autofill
The :auto-fill pseudo-class in CSS allows us to style <input> elements that contain content auto-filled by the browser. Take a […]:autofillinput:auto-fill { outline: 5px solid rgb(0 0 0 / .5); }Continue Reading::backdrop
The ::backdrop CSS pseudo-element creates a backdrop that covers the entire viewport and is rendered immediately below a <dialog>, an […]::backdrop.element::fullscreen { background: #f8a100; }Continue Reading::before / ::after
The ::before and ::after pseudo-elements in CSS allows you to insert content onto a page without it needing to be […]::before / ::after.element::before { content: "Yo!"; }Continue Reading:blank
Experimental feature
The :blank pseudo-class builds upon the :empty pseudo-class. Like :empty, :blank will select elements that contain nothing at all, or […]:blankp:blank { display: none; }Continue Reading::checkmark
Experimental feature
The ::checkmark::checkmark pseudo-element gives us an indication on whether an element is selected or not, which we can style later on.option::checkmark { /* ... */ }Continue Reading:checked
The :checked pseudo-class in CSS selects elements when they are in the selected state. It is only associated with input […]:checkedinput[type=checkbox]:checked { }Continue Reading:current
:current is a CSS pseudo-selector that matches an element or an ancestor of an element that’s currently in display. So, […]:current:current { color: #fd5a1e; }Continue Reading::details-content
Experimental feature
The CSS ::details-content pseudo-element provides a way to select and apply styles to the inner parts of a <details> element […]::details-contentdetails::details-content { font-size: 1.5rem; }Continue Reading:default
The :default pseudo selector will match the default in a group of associated elements, such as the radio button in […]:defaultinput[type="radio"]:default { }Continue Reading:defined
The :defined pseudo-class selector is part of CSS Selectors Level 4 specification allowing you to target custom elements created with […]:definedelement:defined { visibility: visible; }Continue Reading:dir()
The :dir() pseudo-class in CSS allows elements to be selected based on the direction of the language, as determined in […]:dir().element:dir(rtl) { }Continue Reading:disabled
The :disabled pseudo-class selector provides conditional styling to HTML elements that can receive user input, when the elements have the […]:disabledinput:disabled { }Continue Reading:empty
The CSS :empty pseudo-class selects any element that does not contain children for a given selector. If we were to […]:empty.element:empty { background: red; }Continue Reading:enabled
The :enabled pseudo-class in CSS selects focusable elements that are not disabled, and therefore enabled. It is only associated with […]:enabledinput:enabled + label { color: #333; }Continue Reading::file-selector-button
The ::file-selector-button in CSS is a pseudo-element that selects <input type="file"> in HTML. You’ve undoubtedly come across file upload inputs […]::file-selector-button::file-selector-button { background-color: #f8a100; }Continue Reading::first-letter
::first-letter is a pseudo element which allows you to style the first letter in an element, without needing to stick […]::first-letterp::first-letter { }Continue Reading::first-line
The ::first-line pseudo-element is for applying styles to the first line of an element. Imagine a paragraph that is several […]::first-line.element::first-line { font-size: 1.3rem; }Continue Reading:first
The :first CSS pseudo-class is used with the @page at-rule to select the first page in a printed document. It’s […]:first@page :first { margin: 50%; }Continue Reading:first-child
The :first-child selector allows you to target the first element immediately inside another element. It is defined in the CSS […]:first-child.element:first-child { }Continue Reading:first-of-type
The :first-of-type selector in CSS allows you to target the first occurence of an element within its container. It is […]:first-of-typep:first-of-type { text-indent: 1rem; }Continue Reading:focus
The :focus pseudo class in CSS is used for styling an element that is currently targeted by the keyboard, or […]:focustextarea:focus { background: pink; }Continue Reading:focus-visible
The :focus-visible pseudo-class (also known as the “Focus-Indicated” pseudo-class) is a native CSS way to style elements that: Are in […]:focus-visible.element:focus-visible { }Continue Reading:focus-within
The :focus-within pseudo-selector in CSS is a bit unusual, although well-named and rather intuitive. It selects an element if that […]:focus-withinform:focus-within { background: lightyellow; }Continue Reading:fullscreen
The :fullscreen CSS pseudo-class allows you to select and style any element that is currently in fullscreen mode. You know […]:fullscreen.element::fullscreen { text-size: 3rem; }Continue Reading:future
:future is a CSS pseudo-selector we can use to style upcoming elements during media playback. Think subtitles in videos. We […]:future:future(p) { opacity: .5; }Continue Reading:has()
The CSS :has() pseudo-class selects elements that contain other elements that match the selector passed into its arguments. It’s often […]:has().element:has(img) { }Continue Reading:hover
The :hover pseudo class in CSS selects elements when the mouse cursor is current over them. It’s commonly associated with link (<a>) […]:hovera:hover { color: #f8a100; }Continue Reading:in-range
The :in-range pseudo selector in CSS matches input elements when their value is within the range specified as being acceptable. […]:in-rangeinput:in-range { border: 5px solid green; }Continue Reading:indeterminate
:indeterminate is a pseudo-class selector in CSS named for a state that is neither checked nor unchecked. It’s that in-between […]:indeterminateinput[type="radio"]:indeterminate { }Continue Reading:invalid
:invalid is a pseudo-class selector that enables styling on invalid form elements. :invalid can be added to any form elements, […]:invalidform:invalid { outline: 3px dashed red; }Continue Reading:is
The pseudo-select :is() in CSS allows you to write compound selectors more tersely. For example, rather than writing: We could […]:is:is(ul, ol) li { color: #f8a100; }Continue Reading:lang()
The :lang() pseudo class selector in CSS matches elements based on the context of their given language attribute. Language in […]:lang():lang(en) { }Continue Reading:last-child
The :last-child selector allows you to target the last element directly inside its containing element. It is defined in the […]:last-child.element:last-child { }Continue Reading:last-of-type
The :last-of-type selector allows you to target the last occurence of an element within its container. It is defined in […]:last-of-typep:last-of-type { font-size: 0.75em; }Continue Reading:left
The :left pseudo-class in CSS is used with the @page at-rule to select all left-hand pages in a print document […]:left@page :left { margin: 1in 2in; }Continue Reading:link
The :link selector is a pseudo-class that targets all anchor (<a>) elements on a page that have an href attribute: […]:linka:link { color: #f8a100; }Continue Reading::marker
The ::marker pseudo-element is for styling the stylistic marker of a list element. For example, the bullet point of a default <ul> […]::markerli::marker { color: red; }Continue Reading:not
The :not() property in CSS is a negation pseudo class and accepts a simple selector or a selector list as […]:not:not(.element) { color: #f8a100; }Continue Reading:nth-child
The :nth-child selector allows you to select one or more elements based on their source order, according to a formula. […]:nth-child.element:nth-child(3n - 1) { }Continue Reading:nth-last-child
The :nth-last-child selector allows you select one or more elements based on their source order, according to a formula. It […]:nth-last-childli:nth-last-child(2) { }Continue Reading:nth-last-of-type
The :nth-last-of-type selector allows you select one or more elements based on their source order, according to a formula. It […]:nth-last-of-type.element:nth-last-of-type(2n + 1){ }Continue Reading:nth-of-type
The :nth-of-type selector allows you select one or more elements based on their source order, according to a formula. It […]:nth-of-type.element:nth-of-type(2n + 1) { }Continue Reading:only-child
The :only-child pseudo-class selector property in CSS represents an element that has a parent element and whose parent element has […]:only-child.element:only-child { }Continue Reading:only-of-type
The :only-of-type pseudo-class selector in CSS represents any element that has no siblings of the given type. p:only-of-type { color: […]:only-of-typep:only-of-type { font-size: 120% }Continue Reading:open
Experimental feature
The :open:open pseudo-selector targets elements that support "open" and "closed" states and selects them only in their "open" state.details:open { border: 6px solid #48a100; }Continue Reading:optional
The :optional pseudo class targets inputs (including <select>s) that are not specifically set as required (do not have the required attribute). This can be useful when you […]:optional.element:optional { background: #f8a100; }Continue Reading:out-of-range
The :out-of-range pseudo selector in CSS matches input elements when their value is outside the range specified as being acceptable. […]:out-of-rangeinput:out-of-range { border: 5px solid red; }Continue Reading::picker()
Experimental feature
The ::picker()::picker() pseudo-element targets and styles a form element's open menu of options.::picker(select) { border: 3px solid oklch(65% 0.2 300); }Continue Reading::picker-icon
Experimental feature
The ::picker-icon::picker-icon pseudo-element allows us to style the dropdown icon of a <select> element.::picker-icon { content: "✓"; }Continue Reading::placeholder
The ::placeholder pseudo element (or a pseudo class, in some cases, depending on the browser implementation) allows you to style […]::placeholderinput::placeholder { color: red; }Continue Reading:past
:past is a CSS pseudo-selector that matches elements that have passed along a timeline. Where you’ll see this come into […]:past:past(p) { opacity: .5; }Continue Reading:placeholder-shown
The :placeholder-shown pseudo-class selects the input element itself when placeholder text exists in a form input. Think of it as a nice way to […]:placeholder-showninput:placeholder-shown { border: 5px solid red; }Continue Reading:popover-open
The CSS :popover-open pseudo-class is part of the Popover API that selects a popover element and styles the popover when […]:popover-open:popover-open { border: 0; }Continue Reading:read-write / :read-only
The :read-write and :read-only selectors are two mutability pseudo-classes aiming at making form styling easier based on disabled, readonly and […]:read-write / :read-only.element:read-only { cursor: not-allowed; }Continue Reading:required
The :required pseudo class selector in CSS allows authors to select and style any matched element with the required attribute. […]:requiredinput:required { }Continue Reading:right
The :right pseudo-class in CSS is used with the @page at-rule to select all right-hand pages in a print document […]:right@page :left { margin: 1in 2in; }Continue Reading:root
The :root selector allows you to target the highest-level “parent” element in the DOM, or document tree. It is defined […]:root:root { }Continue Reading::scroll-button()
Experimental feature
The ::scroll-button() pseudo-element adds accessible scroll buttons to scroll containers, giving users an additional way to navigate overflow content. To […]::scroll-button().carousel::scroll-button(right) { content: "⮕"; }Continue Reading::scroll-marker
Experimental feature
The ::scroll-marker::scroll-marker pseudo-element adds accessible scroll markers to scroll containers..element::scroll-marker { content: ""; }Continue Reading::scroll-marker-group
Experimental feature
The ::scroll-marker-group::scroll-marker-group pseudo-element holds the scroll markers generated by the ::scroll-marker pseudo-element. When clicked on, these scroll markers scroll users to a corresponding scroll target within a scroll container in a scroll-snapping fashion. All in all, scroll markers give users an additional way to navigate overflow content..scroll-container::scroll-marker-group { /* ... */ }Continue Reading::selection
Use your cursor select this sentence. Notice how as you select the text a background color fills the space? You […]::selection::selection { background: yellow; }Continue Reading::target-text
The ::target-text pseudo-element selects a text fragment, usually the ones created by search engines.::target-textp::target-text { /* ... */ }Continue Reading:target
The :target pseudo selector in CSS matches when the hash in the URL and the id of an element are […]:target.element:target { background: yellow; }Continue Reading:target-after
Experimental feature
:target-after:target-after is a CSS pseudo-class that selects all scroll markers that come after an active scroll marker (:target-current) within a scroll container.::scroll-marker:target-after { background: red; }Continue Reading:target-before
Experimental feature
The :target-before:target-before CSS pseudo-class selects all scroll markers prior to an active scroll marker (:target-current) within a scroll container.::scroll-marker:target-before { background: hsl(from black h s l / 50%); }Continue Reading:target-current
Experimental feature
The :target-current:target-current CSS pseudo-class selects active scroll markers, meaning it’s only valid when used with the ::scroll-marker pseudo-element::scroll-marker:target-current { background: black; }Continue Reading:user-invalid
The :user-invalid is a CSS pseudo-class that is under proposal in the CSS Selectors Level 4 working draft that selects […]:user-invalidinput:user-invalid { color: red; }Continue Reading::view-transition
The CSS ::view-transition pseudo-element is the top-level — or “root” — containing all animated transitions defined as CSS view transitions […]::view-transition::view-transition { position: fixed; }Continue Reading::view-transition-group
The ::view-transition-group pseudo-element selects one or more containers that group the pieces of an individual view transition. See that transition-name […]::view-transition-group::view-transition-group(transition-name) { animation-duration: 1.25s; }Continue Reading::view-transition-image-new
The CSS ::view-transition-image-new pseudo-element is part of the View Transition API that lets us select the “new” snapshot that is […]::view-transition-image-new::view-transition-image-new(*) { animation-duration: 700ms; }Continue Reading::view-transition-image-old
The CSS ::view-transition-image-old pseudo-element is part of the View Transition API that lets us select the “before” snapshot in a […]::view-transition-image-old::view-transition-image-old(*) { animation-duration: 700ms; }Continue Reading::view-transition-image-pair
The CSS ::view-transition-image-pair pseudo-element is part of the View Transition API that lets us select the “before-and-after” snapshots in a […]::view-transition-image-pair::view-transition-image-pair(root) { animation-duration: 1s; }Continue Reading:valid
:valid is a pseudo-class selector that enables styling on valid form elements. :valid can be added to any form element, […]:validform:valid { outline: 3px dashed green; }Continue Reading:visited
The:visited pseudo-class selector can change some of the styling on an anchor link (<a>) element if the user’s browser has […]:visiteda:visited { color: #777; }Continue Reading:where
The :where() pseudo selector in CSS is functionally identical to the :is() psuedo selector in that it takes a comma-separated […]:wheremain :where(h1, h2, h3) { color: #f8a100; }Continue ReadingAdvertisement