CSS ::first-letter Selector

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The ::first-letter pseudo-element styles the first letter of the first line in a block container, when nothing else (like an image) comes before that letter.

It is often used for drop caps. Nearby punctuation is included in the match. Prefer the double-colon form; browsers still accept legacy :first-letter.

Baseline · Widely available.

Not deprecated. Core support is broad; some details (digraphs, SVG text) vary by browser.

Limited support:

Language digraphs such as Dutch IJ, and ::first-letter on SVG <text>, are incomplete in many engines. Keep drop caps simple for production.

CSS Syntax

syntax.css
E::first-letter { { … }

Example: p::first-letter { font-size: 1.5rem; color: brown; }

Selector Forms

FormDescriptionTry it
p::first-letterStyle the opening letter of paragraphsTry it
Drop capLarger letter with float: leftTry it
PunctuationLeading quotes/marks are includedTry it
Adjacent combinatore.g. h2 + p::first-letter for the first paragraph after a headingTry it

How to Use ::first-letter

Target a block of text, then style only the allowed properties on the opening letter.

  1. Choose a block container (p, div, heading, …).
  2. Write E::first-letter (or a more specific selector like h2 + p::first-letter).
  3. Set font, color, background, padding, or float for a drop cap.
  4. Skip unsupported properties (for example most layout/grid controls).
PieceRequired?Role
Block containerYesHolds the text whose first letter you style
::first-letterYesSelects the opening letter (and nearby punctuation)
Allowed propertiesYesFont, color, background, box, float, …

Live Preview

Toggle presets on the sample paragraph. Styles apply through real ::first-letter rules.

::first-letter presets

Only a subset of CSS properties can affect ::first-letter.

Paragraph

Scientists exploring the bay found a rare fish on a week-long expedition.

Preset: color

CSS Examples

Each snippet focuses on ::first-letter. Extra styles stay minimal for study. Use Try It Yourself for a live editor.

Example 1 — Color and Size

Make the opening letter larger and bold.

CSS
<style>
  p::first-letter {
    font-size: 1.5rem;
    font-weight: bold;
    color: brown;
  }
</style>

<p>Scientists exploring the bay found a rare fish.</p>
Try It Yourself

How It Works

  1. Target the block. p::first-letter selects the opening letter.
  2. Grow the letter. font-size and font-weight are allowed.
  3. Set color. Brown applies only to that letter.
  4. Rest stays normal. The remaining text uses default paragraph styles.

Example 2 — Drop Cap

Float a large first letter beside the text.

CSS
<style>
  p::first-letter {
    float: left;
    font-size: 250%;
    padding: 6px 3px;
    margin-right: 6px;
    color: #fff;
    background: #0f172a;
  }
</style>

<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.</p>
Try It Yourself

How It Works

  1. Float the letter. float: left lets following lines wrap beside it.
  2. Scale up. A large font-size creates the drop-cap look.
  3. Add padding. Space inside the letter box keeps it readable.
  4. Gap. margin-right separates the letter from the text.

Example 3 — Punctuation Is Included

Leading quotes and marks join the first-letter match.

CSS
<style>
  p::first-letter {
    color: #dc2626;
    font-size: 150%;
  }
</style>

<p>"Hello," she said.</p>
Try It Yourself

How It Works

  1. Opening quote counts. Punctuation next to the first letter is included.
  2. Style both. The quote and H share the red, larger look.
  3. Rest is normal. ello and the following text stay default.
  4. Useful for dialogue. Drop caps still look correct with quotes.

Edge Cases & Pitfalls

Most surprises come from content before the letter or disallowed properties.

props

Only some properties work

Font, color, background, margin, padding, border, float, and related text styles are allowed. Many layout properties are ignored.

before

::before can steal the letter

If ::before injects text via content, ::first-letter styles that generated text first.

inline

Needs a block container

A plain span usually will not apply ::first-letter until it becomes block or inline-block.

vs line

Not the whole first line

For the entire first line, use ::first-line.

a11y

Keep contrast readable

Large decorative letters still need enough contrast. Avoid relying on float drop caps alone for meaning.

Browser Support

::first-letter is a browser CSS pseudo-element. Node.js, Deno, and Bun do not evaluate it.

✓ Baseline · Widely available

::first-letter

Core drop-cap styling is widely supported (Chrome 1+, Firefox 1+, Safari 1+, Edge 12+, IE 9+). Digraphs and SVG text support remain incomplete.

97% Core support
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 7+
Full support
Samsung Internet 1+
Full support
Internet Explorer 9+
Full support
::first-letter Widely supported

Bottom line: Safe for everyday drop caps. Treat digraphs and SVG text as progressive enhancement. It is not a JavaScript runtime API.

Key Takeaways

  • Role: style the first letter of a block’s first line.
  • Syntax: prefer ::first-letter (pseudo-element).
  • Limits: only a subset of CSS properties apply.
  • Drop caps: combine large type with float: left.

One line: ::first-letter styles the opening letter of a block for emphasis or drop caps.

Frequently Asked Questions

It styles the first letter of the first line in a block container, when that letter is not preceded by other content such as an image.
Prefer the double-colon ::first-letter form for pseudo-elements. Browsers still accept the older single-colon :first-letter for compatibility.
Block containers such as p, div, and headings. Plain inline spans do not, unless you change their display to a block-level type.
::first-letter styles only the opening letter (plus nearby punctuation). ::first-line styles the whole first line of text.
No. Only a limited set works—mainly font, color, background, margin, padding, border, text-decoration, float, and a few related properties.
No. It is a CSS pseudo-element evaluated by the browser layout engine, not a Node.js or server runtime feature.

Next: ::first-line

Style the first line of a block with the ::first-line pseudo-element.

::first-line tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful