The first-line pseudo-element

The first-line pseudo-element allows you to style the first line of a text.

Syntax

cssselector::first-line {
  
}

Example

Let's color the first line of a text in each paragraph red:

html<p>
  some long text
</p>
<p>
  some long text
</p>
cssp::first-line {
  color: red;
}
p {
  width: 300px;
  text-align: justify;
}

Результат:

Example

Let's set the paragraph width as a percentage. Run the given code and change the width of the browser window:

html<p>
  some long text
</p>
<p>
  some long text
</p>
cssp::first-line {
  color: red;
}
p {
  width: 50%;
  margin: 0 auto;
  text-align: justify;
}

Результат: