CSS ::first-line Selector


Example

Select and style the first line of every <p> element:

p::first-line {
  background-color: yellow;
}
Try it Yourself »

Definition and Usage

The ::first-line selector is used to add a style to the first line of the specified selector.

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

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

Note: The ::first-line selector can only be used with block-level elements.

Version: CSS1

Browser Support

The numbers in the table specifies the first browser version that fully supports the selector.

Selector
::first-line 1.0 9.0 1.0 1.0 7.0

CSS Syntax

::first-line {
  css declarations;
} Demo

Related Pages

CSS tutorial: CSS Pseudo elements


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.