::first-line CSS Pseudo Element

Description

The ::first-line pseudo-element sets the style of the first line of formatted text. The length of this line depends on many factors, such as the font used, the size of the browser window, the width of the block, language, etc. In the style rules, it is permissible to use only properties related to the font, color change of the text and background.

Syntax

element::first-line { … }

Example

<p>Lorem ipsum dolor sit amet<br>consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.,</p>
<p>Duis aute irure dolor in reprehenderit in<br> voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
p::first-line { 
border: 1px solid red;
background: #000;
color: red;
font-weight: bold;
}

Notes

In CSS3, pseudo-elements were denoted by two colons to make the syntax different from pseudo-classes. In CSS2, they are indicated by a single colon. Browsers generally understand both syntaxes.

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
??????
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
?????X