CSS ::first-line pseudoelement

Definition and usage

CSS ::first-line Pseudoelements 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 of 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 indicate the first browser version that fully supports this pseudoelement.

Chrome Edge Firefox Safari Opera
1.0 9.0 1.0 1.0 7.0

Related pages

Tutorial:CSS pseudoelement