CSS pseudo-elementPseudo-elements

::first-letter

Styles the first letter of the first line in a block of text. The classic way to make a drop cap at the start of an article.

On this page

Example

#
CSS
.article p:first-of-type::first-letter {
  float: left;
  margin: 4px 8px 0 0;
  font-family: Georgia, serif;
  font-size: 3.4em;
  line-height: 0.8;
  color: #c4b5fd;
}
Preview

Definition and usage

#

The ::first-letter pseudo-element selects the first letter (or digit) of the first line of a block element. It is most often used for a drop cap: a large, decorative letter at the start of an article, familiar from books and newspapers.

The browser also includes any punctuation right before the letter, for example an opening quotation mark: in text starting with “Ala the whole fragment “A becomes the initial. The pseudo-element works only on block-level elements (block, inline-block, list-item, table cells), so on a plain span it changes nothing.

It supports text and box properties: font, colour, background, margins, padding, border, and float. A multi-line drop cap is made with float: left, a large font-size, and a matching line-height.

Syntax

#
Syntax
selector::first-letter { property: value; }

Common styles

#
  • font-size

    A larger, coloured first letter, still in the text line.
  • float: left

    A drop cap that the text wraps around over several lines.
  • background

    The first letter in a coloured tile. ::first-letter supports background, padding, and margins.

Common styles in practice

#

font-size

A larger, coloured first letter, still in the text line.
.demo::first-letter { font-size: 2em; color: #a78bfa; }

float: left

A drop cap that the text wraps around over several lines.
.demo::first-letter {
  float: left;
  margin: 4px 8px 0 0;
  font-family: Georgia, serif;
  font-size: 3.2em;
  line-height: 0.8;
  color: #a78bfa;
}

background

The first letter in a coloured tile. ::first-letter supports background, padding, and margins.
.demo::first-letter {
  margin-right: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  background: #7c3aed;
  color: #fff;
  font-weight: 700;
}

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Combine ::first-letter with :first-of-type so that only the first paragraph of an article gets the drop cap, not every one.
  • A drop cap is pure decoration. Don’t split the first letter into a separate HTML element, because screen readers may then read the word in pieces.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.