Home CSS Selectors ::first-letter CSS ::first-letter Selector Definition
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.
Syntax
CSS Syntax Example: p::first-letter { font-size: 1.5rem; color: brown; }
Approach
How to Use ::first-letter Target a block of text, then style only the allowed properties on the opening letter.
Choose a block container (p, div, heading, …). Write E::first-letter (or a more specific selector like h2 + p::first-letter). Set font, color, background, padding, or float for a drop cap. Skip unsupported properties (for example most layout/grid controls). Piece Required? Role Block container Yes Holds the text whose first letter you style ::first-letterYes Selects the opening letter (and nearby punctuation) Allowed properties Yes Font, color, background, box, float, …
Try it
Live Preview Toggle presets on the sample paragraph. Styles apply through real ::first-letter rules.
Code
CSS Examples Each snippet focuses on ::first-letter. Extra styles stay minimal for study. Use Try It Yourself for a live editor.
1. Basic 2. Drop cap 3. Punctuation Example 1 — Color and Size Make the opening letter larger and bold.
<style>
p::first-letter {
font-size: 1.5rem;
font-weight: bold;
color: brown;
}
</style>
<p>Scientists exploring the bay found a rare fish.</p> Scientists exploring the bay found a rare fish.
How It Works Target the block. p::first-letter selects the opening letter.Grow the letter. font-size and font-weight are allowed.Set color. Brown applies only to that letter.Rest stays normal. The remaining text uses default paragraph styles.Example 2 — Drop Cap Float a large first letter beside the text.
<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> Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.
How It Works Float the letter. float: left lets following lines wrap beside it.Scale up. A large font-size creates the drop-cap look.Add padding. Space inside the letter box keeps it readable.Gap. margin-right separates the letter from the text.Example 3 — Punctuation Is Included Leading quotes and marks join the first-letter match.
<style>
p::first-letter {
color: #dc2626;
font-size: 150%;
}
</style>
<p>"Hello," she said.</p> How It Works Opening quote counts. Punctuation next to the first letter is included.Style both. The quote and H share the red, larger look.Rest is normal. ello and the following text stay default.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 letterIf ::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.
Compatibility
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.
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.
Remember
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 What does the CSS ::first-letter pseudo-element do? 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.
Should I use ::first-letter or :first-letter? Prefer the double-colon ::first-letter form for pseudo-elements. Browsers still accept the older single-colon :first-letter for compatibility.
Which elements support ::first-letter? Block containers such as p, div, and headings. Plain inline spans do not, unless you change their display to a block-level type.
What is the difference between ::first-letter and ::first-line? ::first-letter styles only the opening letter (plus nearby punctuation). ::first-line styles the whole first line of text.
Can I use any CSS property on ::first-letter? No. Only a limited set works—mainly font, color, background, margin, padding, border, text-decoration, float, and a few related properties.
Is ::first-letter a runtime API? No. It is a CSS pseudo-element evaluated by the browser layout engine, not a Node.js or server runtime feature.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion