CSS ::first-letter Selector

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 4 Examples
Typography

What You’ll Learn

The ::first-letter pseudo-element styles the first character of the first line inside a block container. It is a classic tool for drop caps and editorial typography.

01

First char

One letter only.

02

Drop cap

Magazine style.

03

:: syntax

Pseudo-element.

04

Block boxes

p, article…

05

float

Wrap text.

06

Font props

Size, color.

Introduction

The ::first-letter selector in CSS is a pseudo-element used to apply styles to the first letter of the first line of text inside a block container.

It is commonly used to create drop caps in articles, blog posts, and book-style layouts where the opening letter appears larger and more decorative than the rest of the paragraph.

Definition and Usage

Append ::first-letter to a selector with no space before the colons: p::first-letter or article p::first-letter. Only the first character of the element’s first formatted line is styled.

💡
Beginner Tip

::first-letter targets exactly one character. If the text starts with a quotation mark, number, or emoji, that character receives the styling — not the first alphabetic letter after it.

📝 Syntax

The syntax for the ::first-letter pseudo-element is:

syntax.css
element::first-letter {
  /* CSS properties */
}

Here, element is a block container such as p, article, or h2. The pseudo-element selects only the first letter inside that element’s first line.

Basic Example

first-letter-dropcap.css
p::first-letter {
  font-size: 2.5rem;
  font-weight: 700;
  color: #2563eb;
  float: left;
  margin-right: 0.35rem;
  line-height: 1;
}
p::first-letter article p::first-letter h1::first-letter .lead::first-letter

Syntax Rules

  • Use double colons :: for pseudo-elements in modern CSS.
  • Works on block containers, list items, table cells, and inline-block elements.
  • Plain inline elements like <span> do not support it unless display is changed.
  • Only the first character of the first formatted line is matched.
  • Pair with float: left and larger font-size for classic drop caps.

Supported Properties

Property groupExamples
Fontfont-size, font-weight, font-family, font-style
Color & backgroundcolor, background, background-color
Spacingmargin, padding, letter-spacing
Text & layouttext-transform, text-decoration, float, line-height
Bordersborder, border-radius, box-shadow

Related Selectors

  • ::first-line — styles the entire first line of text
  • ::before / ::after — insert generated content before or after an element
  • ::selection — styles text highlighted by the user
  • initial-letter — modern CSS property for drop caps (limited support)

⚡ Quick Reference

QuestionAnswer
Selector typePseudo-element
What it stylesFirst character of the first formatted line
Common useDrop caps in articles and blog posts
Typical patternp::first-letter { font-size: 2.5rem; float: left; }
Inline elementsNot supported on plain span without display change
Browser supportAll modern browsers

When to Use ::first-letter

::first-letter adds editorial polish to long-form content:

  • Article openings — Create a magazine-style drop cap on the lead paragraph.
  • Chapter starts — Emphasize the beginning of a story or section.
  • Blog posts — Give the first paragraph a distinctive branded letter.
  • Pull quotes — Accent the opening character of a highlighted quote block.
  • Headings — Subtly enlarge the first letter of a title for decorative effect.

👀 Live Preview

The opening “W” is styled with a larger blue drop cap via p::first-letter:

Welcome to the world of CSS! This paragraph demonstrates how you can use the ::first-letter pseudo-element to create a styled drop cap effect that wraps naturally with the rest of the text.

Examples Gallery

Practice ::first-letter with basic drop caps, serif editorial styling, colored backgrounds, and heading accents.

📜 Drop Cap Patterns

Style the opening letter of paragraphs and articles.

Example 1 — Basic paragraph drop cap

Enlarge and float the first letter to create a classic drop cap on a paragraph.

first-letter-basic.html
<style>
  p::first-letter {
    font-size: 2.5rem;
    font-weight: 700;
    color: #2563eb;
    float: left;
    margin-right: 0.35rem;
    line-height: 1;
  }
</style>

<p>
  Welcome to the world of CSS! This paragraph demonstrates how you can use the
  ::first-letter selector to create a styled drop cap effect.
</p>
Try It Yourself

How It Works

float: left pulls the enlarged letter to the left so body text wraps around it. line-height: 1 keeps the cap aligned cleanly with the first line.

Example 2 — Editorial serif drop cap

Use a serif font and larger size for a book-chapter feel inside an article.

first-letter-serif.css
article p::first-letter {
  font-size: 3rem;
  font-family: Georgia, serif;
  float: left;
  line-height: 0.9;
  margin-right: 0.5rem;
  color: #1e293b;
}
Try It Yourself

How It Works

Scoping to article p limits the effect to article body copy, leaving navigation and sidebar text unchanged.

🎨 Decorative Effects

Add background color and accent styling to the opening character.

Example 3 — Colored background on the first letter

Give the first letter a pill-shaped background for a modern badge-like accent.

first-letter-bg.css
.lead::first-letter {
  font-size: 1.75rem;
  font-weight: 700;
  color: #fff;
  background: #7c3aed;
  padding: 0.15rem 0.4rem;
  border-radius: 0.35rem;
  margin-right: 0.25rem;
}
Try It Yourself

How It Works

Background and padding on ::first-letter create a badge effect without extra HTML markup.

Example 4 — Accent the first letter of a heading

Apply a subtle color and size change to the opening letter of a title.

first-letter-heading.css
h2::first-letter {
  font-size: 1.4em;
  color: #ea580c;
  font-weight: 800;
  text-transform: uppercase;
}
Try It Yourself

How It Works

Headings are block containers, so h2::first-letter works without float. Use sparingly to avoid distracting from the heading’s meaning.

⚠️ Common Pitfalls

  • Inline elementsspan::first-letter does not work on plain inline elements. Use a block container or set display: inline-block.
  • Leading punctuation — A quote mark or number at the start gets styled, not the first letter after it.
  • One character only — You cannot style the first two letters with ::first-letter; only the first character matches.
  • Float on small screens — Large floated drop caps can crowd narrow viewports; test responsive layouts.
  • Single vs double colon — Prefer ::first-letter (pseudo-element) over legacy :first-letter in new code.

♿ Accessibility

  • Decorative only — Drop caps are visual enhancements; the full word remains in the DOM for screen readers.
  • Do not convey meaning — Never use letter styling alone to communicate important information.
  • Contrast — Ensure colored or background-styled first letters meet WCAG contrast ratios.
  • Readability — Very large drop caps should not reduce readability of the opening lines on mobile.

🧠 How ::first-letter Works

1

Browser finds block containers

Elements like p and article that support ::first-letter are selected.

Match
2

First character is isolated

The browser creates a pseudo-element for the first letter of the first formatted line.

Pseudo
3

Styles apply to that letter

Font, color, float, and spacing properties render on the single character.

Render
=

Drop cap typography

The opening letter stands out with editorial flair.

🖥 Browser Compatibility

The ::first-letter pseudo-element is supported in all modern browsers and has been widely available for years.

Baseline · Universal support

Drop caps everywhere

::first-letter works reliably in Chrome, Firefox, Safari, Edge, and Opera.

99% Universal support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All modern versions
Full support
::first-letter pseudo-element 99% supported

Bottom line: ::first-letter is safe for drop caps and typographic accents in modern projects.

🎉 Conclusion

The ::first-letter pseudo-element is a powerful typographic tool for styling the opening character of block-level text. From simple drop caps to colored badge accents, it adds editorial character without extra HTML.

Remember that only the first character is styled, block containers are required, and leading punctuation counts as the first letter. Pair with float and careful sizing for polished long-form layouts.

💡 Best Practices

✅ Do

  • Use ::first-letter (double colon) in new code
  • Apply drop caps to lead paragraphs only
  • Combine float: left with tuned line-height
  • Test on mobile for crowded drop caps
  • Scope with article p::first-letter

❌ Don’t

  • Apply to plain inline span elements
  • Expect styling on the second character
  • Ignore leading quotes or numbers
  • Overuse on every paragraph
  • Rely on drop caps to convey meaning

Key Takeaways

Knowledge Unlocked

Five things to remember about ::first-letter

Use these points when styling opening characters.

5
Core concepts
:: 02

Pseudo-element

Double colon.

Syntax
📖 03

Drop cap

float + size.

Pattern
p 04

Block boxes

p, article.

Targets
🌐 05

99% support

All browsers.

Compat

❓ Frequently Asked Questions

The ::first-letter pseudo-element matches the first letter of the first line inside a block container. It lets you style that single character independently — commonly for drop caps in articles.
Block containers such as p, div, article, and h1–h6, plus list items, table cells, and elements with display:inline-block. Plain inline elements like span do not support it unless you change their display.
::first-letter styles only the first character. ::first-line styles the entire first line of text inside the element.
Use the double-colon ::first-letter syntax. It is the modern standard for pseudo-elements. Single-colon :first-letter still works in browsers for backward compatibility.
Yes. All modern browsers support ::first-letter for drop caps and typographic accents. Test decorative float layouts on small screens.

Practice in the Live Editor

Open the HTML editor and experiment with ::first-letter drop caps and typography effects.

HTML Editor →

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.

5 people found this page helpful