Plumeria logoPlumeria

Pseudo

Overview

This page provides a comprehensive reference for CSS pseudo-classes and pseudo-elements that you can use in Plumeria with css.create().

All standard CSS pseudo-selectors are supported and can be used as keys in your style objects.

Usage

import { css } from '@plumeria/core';

const styles = css.create({
  button: {
    background: 'blue',
    ':hover': {
      background: 'darkblue',
    },
    ':active': {
      background: 'navy',
    },
    '::before': {
      content: '"→ "',
    },
  },
});

Pseudo-Classes

Pseudo-classes target elements based on their state, position, or user interaction.

Interactive States

Pseudo-ClassDescriptionExample Use Case
:hoverElement when mouse hovers over itChange background on hover
:activeElement when being activated (clicked)Button press effect
:focusElement that has focusInput field outline
:focus-visibleElement with visible focus (keyboard navigation)Show focus ring for keyboard users
:focus-withinElement containing a focused descendantStyle form when any input is focused

Form States

Pseudo-ClassDescriptionExample Use Case
:checkedChecked checkboxes or radio buttonsStyle checked inputs
:disabledDisabled form elementsGray out disabled buttons
:enabledEnabled form elementsStyle active inputs
:requiredRequired form elementsHighlight required fields
:optionalNon-required form elementsStyle optional fields
:validValid form elementsGreen border for valid inputs
:invalidInvalid form elementsRed border for invalid inputs
:in-rangeInput values within valid rangeHighlight valid range
:out-of-rangeInput values outside valid rangeHighlight invalid range
:read-onlyRead-only form elementsStyle read-only inputs
:read-writeEditable form elementsStyle editable textareas
:placeholder-shownInputs showing placeholderStyle inputs with placeholders
:indeterminateIndeterminate checkboxesStyle indeterminate state
:defaultDefault element in a groupHighlight default button
:autofillAuto-filled form elementsCustomize autofill appearance

Structural Pseudo-Classes

Pseudo-ClassDescriptionExample Use Case
:first-childFirst child of parentStyle first paragraph
:last-childLast child of parentStyle last list item
:only-childOnly child of parentStyle lone element
:first-of-typeFirst sibling of its typeStyle first heading
:last-of-typeLast sibling of its typeStyle last paragraph
:only-of-typeOnly one of its typeStyle single heading
:nth-child(n)Nth child of parentStyle every other row
:nth-last-child(n)Nth child from endStyle second-to-last item
:nth-of-type(n)Nth element of typeStyle every third div
:nth-last-of-type(n)Nth of type from endStyle last few items
:emptyElements with no childrenHide empty containers
Pseudo-ClassDescriptionExample Use Case
:linkUnvisited linksStyle unvisited anchors
:visitedVisited linksStyle visited links
:any-linkAny link (visited or unvisited)Style all links uniformly

Other Pseudo-Classes

Pseudo-ClassDescriptionExample Use Case
:rootRoot element (html)Define CSS variables
:targetElement targeted by URL fragmentHighlight linked section
:not(selector)Elements not matching selectorStyle all except specific class
:is(selector)Elements matching any selectorCombine multiple selectors
:where(selector)Like :is() but with zero specificityFlexible selector grouping
:has(selector)Elements containing specific descendantsStyle parent based on children
:lang(language)Elements with specific languageStyle for specific languages
:dir(direction)Elements with text directionStyle for RTL/LTR
:fullscreenElement in fullscreen modeStyle fullscreen video
:modalModal dialogsStyle modal elements
:openOpen details/dialog elementsStyle open accordions
:definedDefined custom elementsStyle web components

Pseudo-Elements

Pseudo-elements style specific parts of an element or insert generated content.

Content Generation

Pseudo-ElementDescriptionExample Use Case
::beforeInsert content before elementAdd icons or decorations
::afterInsert content after elementAdd arrows or indicators

Text Styling

Pseudo-ElementDescriptionExample Use Case
::first-letterFirst letter of textDrop caps
::first-lineFirst line of textEmphasize opening line
::selectionSelected textCustom highlight color

Form Elements

Pseudo-ElementDescriptionExample Use Case
::placeholderPlaceholder textStyle input placeholders
::markerList item markersCustom bullet styles

Media Elements

Pseudo-ElementDescriptionExample Use Case
::cueWebVTT cues (subtitles)Style video subtitles
::cue(selector)Specific WebVTT cuesStyle specific subtitle parts

Other Pseudo-Elements

Pseudo-ElementDescriptionExample Use Case
::backdropDialog/fullscreen backdropStyle modal background
::part(name)Shadow DOM partsStyle component internals
::slotted(selector)Slotted shadow DOM contentStyle slot content
::spelling-errorSpelling errorsHighlight misspellings
::grammar-errorGrammar errorsHighlight grammar issues

View Transitions

Special pseudo-elements for the View Transitions API.

Pseudo-ElementDescription
::view-transitionRoot of view transition
::view-transition-group(name)Transition group
::view-transition-image-pair(name)Image pair during transition
::view-transition-old(name)Old content
::view-transition-new(name)New content

Notes

  • All pseudo-classes start with a single colon (:)
  • All pseudo-elements start with double colons (::)
  • Some older pseudo-elements (like ::before and ::after) can use single colon for backwards compatibility
  • Functional pseudo-classes like :nth-child() accept arguments
  • Not all pseudo-classes work in all browsers - check compatibility when needed

On this page