CKTIS / CSS
::before — generated content before an element’s contents
The ::before pseudo-element creates styleable content before an element’s actual contents, inside that element. The content property specifies this content; :before is the backward-compatible spelling of the same pseudo-element.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
selector::before { content: "..."; }
/* Legacy equivalent: selector:before { content: "..."; } */::before represents a pseudo-element immediately before its originating element’s actual contents—not before the element itself as a sibling. Generated content is not a text node added to the DOM.
Set content to specify the content. The value none prevents generation; the default normal also generates no content here. Using content: "" allows an empty pseudo-element, for example for decoration. Its default is display: inline; it can be styled and inherits inheritable properties from its originating element.
The spelling :before denotes the same pseudo-element and is accepted for compatibility with older CSS. Prefer ::before in new code to distinguish a pseudo-element clearly from a pseudo-class. Do not rely on it for replaced elements such as images.
In the example, content adds the prefix [i] , and the other declarations style only that prefix. The paragraph’s actual text remains unchanged. Keep essential content in HTML rather than making it depend on CSS decoration.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>::before example</title>
<style>
.note::before {
content: "[i] ";
color: navy;
font-weight: bold;
}
</style>
<p class="note">Save your work.</p>
</html>Result
[i] Save your work.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.