Skip to content

Commit

Permalink
New module: CSS pseudo-elements (#28153)
Browse files Browse the repository at this point in the history
* New module: CSS pseudo-elements

* work in jury duty

* Complete: pseudo module

* slotted is functional

* redundant link

* added correct link

* Apply suggestions from code review

Co-authored-by: Dipika Bhattacharya <dipika@foss-community.org>

* changed file name

* File renamed

* link case

* remove mudule from title

* intro paragraphs

* Update files/en-us/web/css/css_pseudo-elements/index.md

Co-authored-by: Dipika Bhattacharya <dipika@foss-community.org>

* tweaks

* space

---------

Co-authored-by: Dipika Bhattacharya <dipika@foss-community.org>
  • Loading branch information
estelle and dipikabh authored Jul 26, 2023
1 parent 823ea49 commit ceb7507
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 5 deletions.
2 changes: 1 addition & 1 deletion files/en-us/web/css/css_cascade/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ The opposite also occurs. Sometimes there are no declarations defining the value
## See also

- [CSS selectors module](/en-US/docs/Web/CSS/CSS_selectors)
- [CSS pseudo-elements module](/en-US/docs/Web/CSS/CSS_pseudo)
- [CSS pseudo-elements module](/en-US/docs/Web/CSS/CSS_pseudo-elements)
- [CSS paged media module](/en-US/docs/Web/CSS/CSS_paged_media)
- [CSS conditional rules module](/en-US/docs/Web/CSS/CSS_conditional_rules)
- [Shorthand properties](/en-US/docs/Web/CSS/Shorthand_properties)
111 changes: 111 additions & 0 deletions files/en-us/web/css/css_pseudo-elements/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
title: CSS pseudo-elements
slug: Web/CSS/CSS_pseudo-elements
page-type: css-module
spec-urls: https://drafts.csswg.org/css-pseudo/
---

{{CSSRef}}

The **CSS pseudo-element** module defines abstract elements that are not directly present in the document tree. These abstract elements, called pseudo-elements, represent portions of the render tree that can be selected and styled. Pseudo-elements are used to create abstractions about the document tree beyond those provided by the document tree.

Pseudo-elements are prefixed with a double colon (`::`). You add pseudo-elements to selectors (as in `p::first-line`) to target and style these faux elements.

Pseudo-elements enable targeting entities not included in HTML and sections of content that cannot be targeted otherwise without adding extra markup. Consider the placeholder of an {{HTMLelement("input")}} element. This is an abstract element and not a distinct node in the document tree. You can select this placeholder by using the {{CSSXref("::placeholder")}} pseudo-element. As another example, the {{CSSXref("::selection")}} pseudo-element matches the content currently highlighted by a user, allowing you to style what is matched as the user interacts with the content and changes the selection. Similarly, the {{CSSXref("::first-line")}} pseudo-element targets the first line of an element, updating automatically if the character count of the first line changes, without having to query the element's line length.

## Reference

### Selectors

- {{CSSXref("::after")}}
- {{CSSXref("::before")}}
- {{CSSXref("::file-selector-button")}}
- {{CSSXref("::first-letter")}}
- {{CSSXref("::first-line")}}
- {{CSSXref("::grammar-error")}}
- {{CSSXref("::marker")}}
- {{CSSXref("::placeholder")}}
- {{CSSXref("::selection")}}
- {{CSSXref("::spelling-error")}}
- {{CSSXref("::target-text")}}

### Interfaces

- {{DOMxRef("CSSPseudoElement")}} interface
- {{DOMxRef("CSSPseudoElement.element")}} property
- {{DOMxRef("CSSPseudoElement.type")}} property

### Terms

- {{Glossary("Pseudo-element")}} glossary term

## Guides

- [CSS pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements)

- : Alphabetical list of pseudo-elements defined by all the CSS specifications and WebVTT.

- [Building blocks: Pseudo-classes and pseudo-elements](/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements)

- : Part of CSS building blocks section on selectors. This article defines what a pseudo-element is and how it can be combined with pseudo-classes and be used for generating content with `::before` and `::after` pseudo-elements.

- [How to create fancy boxes using pseudo-elements](/en-US/docs/Learn/CSS/Howto/Create_fancy_boxes#pseudo-elements)

- : Example of styling generated content using `::before` and `::after` pseudo-elements for visual effects.

## Related concepts

- {{cssxref("::backdrop")}}

- Web Video Text Tracks Format (WebVTT) cues:

- {{cssxref("::cue")}}
- {{cssxref("::cue", "::cue()")}}
- {{cssxref("::cue-region")}}

- CSS scoping module

- {{CSSXref(":host")}}
- {{CSSXref(":host_function", ":host()")}}
- {{CSSXref(":host-context", ":host-context()")}}
- {{CSSXref("::slotted", "::slotted()")}}

- [CSS shadow parts](/en-US/docs/Web/CSS/CSS_shadow_parts) module

- {{CSSXref("::part")}}

- [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors)

- [Attribute selectors](/en-US/docs/Web/CSS/Attribute_selectors)
- [Combinators](/en-US/docs/Web/CSS/CSS_Selectors/selectors_and_combinators#combinators)
- [Class selectors](/en-US/docs/Web/CSS/Class_selectors)
- [ID selectors](/en-US/docs/Web/CSS/ID_selectors)
- [Type selectors](/en-US/docs/Web/CSS/Type_selectors)
- [Pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes)
- [Universal selectors](/en-US/docs/Web/CSS/Universal_selectors)

- [`placeholder`](/en-US/docs/Web/HTML/Element/input#placeholder) attribute of the `<input>` element
- [`:placeholder-shown`](/en-US/docs/Web/CSS/:placeholder-shown) selector

- [CSS generated content](/en-US/docs/Web/CSS/CSS_generated_content)

- {{cssxref("content")}} property
- {{cssxref("quotes")}} property

- [Text fragments](/en-US/docs/Web/Text_fragments)

- {{DOMXref("AnimationEvent.pseudoElement")}} property
- {{DOMXref("KeyframeEffect.pseudoElement")}} property
- {{DOMXref("TransitionEvent.pseudoElement")}} property

## Specifications

{{Specifications}}

## See also

- [Specificity](/en-US/docs/Web/CSS/Specificity)
- [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module
- [CSS shadow-parts](/en-US/docs/Web/CSS/CSS_shadow_parts) module
- [CSS generated content](/en-US/docs/Web/CSS/CSS_generated_content) module
- [CSS positioned layout](/en-US/docs/Web/CSS/CSS_positioned_layout) module
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ The {{cssxref("is", ":is()")}} and {{cssxref(":where", ":where()")}} pseudo-clas
- {{DOMXref("Document.querySelector()")}}
- {{DOMXref("Document.querySelectorAll()")}}
- [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module
- [CSS pseudo-elements](/en-US/docs/Web/CSS/CSS_pseudo) module
- [CSS pseudo-elements](/en-US/docs/Web/CSS/CSS_pseudo-elements) module
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Multiple pseudo-classes can be combined to create [compound selectors](#compound

## Pseudo-element selectors

Not all CSS selectors are defined in the [CSS selectors module](/en-US/docs/Web/CSS). CSS pseudo-element selectors are defined in the [CSS pseudo-elements](/en-US/docs/Web/CSS/CSS_pseudo) module.
Not all CSS selectors are defined in the [CSS selectors module](/en-US/docs/Web/CSS). CSS pseudo-element selectors are defined in the [CSS pseudo-elements](/en-US/docs/Web/CSS/CSS_pseudo-elements) module.

CSS [pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements), prefixed with two colons (`::`), represent entities that are not included in HTML. For example, the simple {{cssxref("::marker")}} selector selects list item bullets, and the compound selector [`p::first-line`](/en-US/docs/Web/CSS/::first-line) matches the first line of all {{HTMLElement("p")}} elements.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/css/css_shadow_parts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ By default, elements in a shadow tree can be styled only within their respective

## See also

- [CSS pseudo elements](/en-US/docs/Web/CSS/CSS_pseudo) module
- [CSS pseudo elements](/en-US/docs/Web/CSS/CSS_pseudo-elements) module
- [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module
- [Using shadow DOM](/en-US/docs/Web/API/Web_components/Using_shadow_DOM)
- [Templates: Styling outside of the current scope](https://web.dev/learn/html/template/#styling-outside-of-the-current-scope) on web.dev (2023)
2 changes: 1 addition & 1 deletion files/en-us/web/css/pseudo-elements/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ T

## See also

- [CSS pseudo-element](/en-US/docs/Web/CSS/CSS_pseudo) module
- [CSS pseudo-element](/en-US/docs/Web/CSS/CSS_pseudo-elements) module
- [Pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes)
- [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module
- [CSS building blocks: Pseudo-classes and pseudo-elements](/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements)

0 comments on commit ceb7507

Please sign in to comment.