CSS ::first-line (:first-line) Selector
Example
p::first-line {
font-size: 1.2rem;
font-weight: bold;
text-decoration: underline;
}
Meaning
The ::first-line selector applies styles to the first line of a block-level element.
The following properties apply to the ::first-line pseudo-element:
- font
- color
- background
- word-spacing
- letter-spacing
- text-decoration
- vertical-align
- text-transform
- line-height
- clear
Notes:
The ::first-line pseudo-element can only be applied to block-level elements.
The ::first-line selector is same as :first-line changed under CSS3 to make pseudo-elements obvious.
The effects of ::first-line are limited by the length and content of the first line of text in the element.
The length of the first line depends on many factors, including the width of the element, the width of the document, and the font size of the text. ::first-line has no effect when the first child of the element, which would be the first part of the first line, is an inline block-level element, such as an inline table.
Version: CSS1
Standard Syntax
::first-line (:first-line) {
css declarations;
}
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
Status
Allowable properties
Only a small subset of CSS properties can be used with the ::first-line pseudo-element:
- All font-related properties: font, font-kerning, font-style, font-variant, font-variant-numeric, font-variant-position, font-variant-east-asian, font-variant-caps, font-variant-alternates, font-variant-ligatures, font-synthesis, font-feature-settings, font-language-override, font-weight, font-size, font-size-adjust, font-stretch, and font-family
- All background-related properties: background-color, background-clip, background-image, background-origin, background-position, background-repeat, background-size, background-attachment, and background-blend-mode
- The color property
- word-spacing, letter-spacing, text-decoration, text-transform, and line-height
- text-shadow, text-decoration, text-decoration-color, text-decoration-line, text-decoration-style, and vertical-align.