first-line property CSS Reference



Definition and Usage

The ::first-line CSS pseudo-element applies styles only to the first line of an element. The amount of the text on the first line depends of numerous factors, like the width of the elements or of the document, but also of the font size of the text. As all pseudo-elements, the selectors containing ::first-line does not match any real HTML element.

A first line has only meaning in a block-container box, therefore the ::first-line pseudo-element has only an effect on elements with a display value of block, inline-block, table-cell or table-caption. In all other cases, ::first-line has no effect.

Only a small subset of all CSS properties can be used inside a declaration block of a CSS ruleset containing a selector using the ::first-line pseudo-element:

As this list will be extended in the future, it is recommended that you not use any other properties inside the declaration block, in order to keep the CSS future-proof.


Examples

p::first-line { text-transform: uppercase }
Change the letters of the first line of every paragraph to uppercase.
Reference Result
LOREM IPSUM DOLOR SIT AMET,  consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore. DUIS AUTE IRURE DOLOR IN reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
 
p::first-line { margin-left: 20px }
Does nothing, margin-left cannot be applied to a first-line pseudo-element.
Reference Result
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
 
p::first-line { text-indent: 20px }
Does nothing, text-indent cannot be applied to a first-line pseudo-element.
Reference Result
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Compatibility

Desktop browsers

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support1.01.0 (1.7 or earlier)9.07.01.0 (85)
Old one-colon syntax (:first-line)1.01.0 (1.7 or earlier)5.53.51.0 (85)

Mobile browsers

FeatureAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic supportNA1.0 (1)Not supportedNANA
Old one-colon syntax (:first-line)NA1.0 (1)NANANA

Relative articles