CSS pseudo-element 2026-11-05
A CSS pseudo-element represents an abstract styling target associated with an element, such as a typographic portion or generated content. Examples include
::first-line, ::before and ::after. It allows CSS to style parts of the rendering that need not be separate HTML elements in the ordinary document tree.[ref]CSS Pseudo-Elements Module Level 4 by World Wide Web Consortium. Abstract and introductory pseudo-element model
For example,
p::before { content: "Note: "; font-weight: bold; } can generate a bold prefix before a paragraph's content. The prefix participates in the rendering under the pseudo-element's rules, while the paragraph's ordinary text nodes remain unchanged. Reading the paragraph's textContent is therefore not a general way to recover every word a user sees on screen.A typographic example is
p::first-line. Which characters belong to the first rendered line depends on layout width, fonts and wrapping. Changing the width can move text into or out of that pseudo-element without inserting or deleting any DOM text nodes. Pseudo-elements also differ in which properties apply to them.[ref]CSS Pseudo-Elements Module Level 4 by World Wide Web Consortium. Typographic pseudo-elements, ::first-line; Generated Content, ::before and ::after
A CSS pseudo-class instead adds a matching condition such as focus or sibling position. The visual similarity of their names does not make the two mechanisms interchangeable. Modern pseudo-element syntax uses a double colon; some older single-colon spellings persist for compatibility, so a spelling alone should be interpreted using the specified selector rules.
CSS selector 2026-11-05
A CSS selector describes which elements a styling rule matches. It can constrain an element's type, HTML attributes, structural relationships or state. The declarations in a rule then apply to matching elements, subject to the CSS cascade; matching and choosing a winning declaration are separate operations.[ref]
Selectors Level 4 by World Wide Web Consortium. §3, selector structure and matching; simple, compound and complex selectors
For example,
p.warning matches a paragraph whose class list contains warning. Writing p .warning instead uses a descendant CSS combinator: it matches a classed element inside a paragraph, rather than requiring the paragraph itself to carry that class. The space is therefore meaningful syntax.A child CSS combinator changes the relationship again.
article > p.warning matches warning paragraphs directly inside an article, while article p.warning also permits intervening elements. A comma-separated selector list can describe alternatives, and a CSS pseudo-class such as :hover can test an element's state.[ref]Selectors Level 4 by World Wide Web Consortium. Descendant and Child Combinators; Selector Lists; User Action Pseudo-classes
A successful match says nothing by itself about whether one declaration defeats another. If both
p.warning and #notice match an element, CSS specificity and earlier cascade priorities help choose the result. A CSS selector should also be distinguished from a CSS pseudo-element, which can address an abstract part or generated box rather than simply selecting another existing HTML element.