CSS :first-line pseudo-element

Complete CSS Reference Complete CSS Reference

Example

How to style the first line of all <p> elements:

p:first-line
{
background-color:yellow;
}

Try it yourself »

Definition and Usage

The :first-line pseudo-element adds a style to the first line of the specified selector.

Note: The following properties apply to the :first-line pseudo-element: 

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

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The :first-line selector is supported in all major browsers.


CSS Version

The :first-line selector was first introduced in:

CSS 1


Related Pages

CSS tutorial: CSS Pseudo elements


Examples

Try it Yourself - Examples

Pseudo-elements can also be combined with other CSS selectors: 

Example

How to style the first line of all <p> elements with class="intro":

p.intro:first-line
{
background-color:yellow;
}

Try it yourself »

Complete CSS Reference Complete CSS Reference