CKTIS / CSS
::first-line — the first formatted line
The ::first-line pseudo-element styles the first line of content after the browser lays out the text. Its scope depends on line breaking, not source-code lines. The :first-line spelling is an older, equivalent syntax.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
selector::first-line { color: navy; }
/* Legacy equivalent: */
selector:first-line { color: navy; }::first-line represents the contents of an element’s first formatted line. It does not select a separate DOM element or the first line of the HTML file. Container width and font metrics affect which text fragments it covers; its scope can change when layout changes.
The pseudo-element has an effect on block containers, not ordinary elements with display: inline. When a container holds block-level content, its first line can come from its first in-flow block-level child. An empty first line also counts.
Applicable properties include font properties, color, backgrounds, text-transform, and text decorations. This is not an ordinary box for arbitrary layout: do not use it to set a line’s width or margins. writing-mode, direction, and text-orientation are excluded.
Use ::first-line in new code. The older spelling :first-line denotes the same pseudo-element, not a pseudo-class. In the example, an explicit line break separates alpha beta from gamma delta; only the first line should become navy and uppercase.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>::first-line example</title>
<style>
.sample {
width: 30em;
font: 20px/1.5 monospace;
color: black;
}
.sample::first-line {
color: navy;
text-transform: uppercase;
}
</style>
<p class="sample">alpha beta<br>gamma delta</p>
</html>Result
ALPHA BETA gamma delta
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.