W3Schools

home HOME

CSS Basic
CSS HOME
CSS Introduction
CSS Syntax
CSS How To
CSS Background
CSS Text
CSS Font
CSS Border
CSS Outline
CSS Margin
CSS Padding
CSS List
CSS Table

CSS Advanced
CSS Dimension
CSS Classification
CSS Positioning
CSS Pseudo-class
CSS Pseudo-element
CSS Image Gallery
CSS Image Opacity
CSS Media Types
CSS Don't
CSS Summary

CSS Examples
CSS Examples

References
CSS2 Reference
CSS2 Print
CSS2 Aural
CSS Units
CSS Colors
CSS Colorvalues
CSS Colornames

CSS Quiz
CSS Quiz
CSS Exam

Selected Reading
Web Statistics
Web Glossary
Web Hosting
Web Quality

W3Schools Forum

Helping W3Schools

CSS :first-line pseudo-element


CSS Reference Complete CSS Reference

Definition

The :first-line pseudo-element adds a special style to the first line of a text.

Examples

The "first-line" pseudo-element is used to add special styles to the first line of the text in a selector:

p {font-size: 12pt}
p:first-line {color: #FF0000;font-variant:small-caps}
<p>Some text that ends up on two or more lines</p>

The output could be something like this:

Some text that ends
up on two or more lines

In the example above the browser displays the first line formatted according to the "first-line" pseudo element. Where the browser breaks the line depends on the size of the browser window.

Note: The "first-line" pseudo-element can only be used with block-level elements.

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

Pseudo-elements can also be combined with CSS classes: 

p.article:first-line {color: #FF0000}
<p class="article">A paragraph in an article</p>

The example above will set the first line of all paragraphs with class="article" to red.


Try-It-Yourself Demos

Make the first line special
This example demonstrates how to add a special effect to the first line of a text.

Make the first letter and first line special
This example demonstrates how to add a special effect to the first letter and the first line of a text.


CSS Reference Complete CSS Reference


Want To Be A Web Master?

If you want to be a Web Master, you will have to host your web site with an ISP (Internet Service Provider).

MaximumASP offers seven different configurations of dedicated servers to meet your Windows and .NET hosting needs. Hosted on our multi-tiered Enterprise Class network, these servers provide the performance, security and reliability you need to host your high end web sites and applications.

Visit MaximumASP




Jump to: Top of Page or HOME or Printer Friendly Printer friendly page

W3Schools provides material for training only. We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

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

Validate Validate W3C-WAI level A conformance icon W3Schools was converted to XHTML in December 1999