CSS ::first-line pseudo-element

Definition and usage

CSS ::first-line Pseudo-elements are used to set the style of the first line of block-level elements.

Note:The following properties can be used with ::first-line Used together:

  • All font properties
  • All background properties
  • color
  • text-shadow
  • word-spacing
  • letter-spacing
  • text-transform
  • text-decoration
  • text-decoration-color
  • text-decoration-line
  • text-decoration-style
  • vertical-align
  • line-height

Example

Select and set the style of the first line for each <p> element:

p::first-line {
  font-size: 20px;
  text-decoration: underline;
  background-color: lightgreen;

Try it yourself

CSS Syntax

::first-line {
  css declarations;

Technical details

Version: CSS1

Browser support

The numbers in the table specify the first browser version to fully support this pseudo-element.

Chrome Edge Firefox Safari Opera
1.0 9.0 1.0 1.0 7.0

Related pages

Tutorial:CSS Pseudo-element