CSS Portal

::first-letter CSS Pseudo Element

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The ::first-letter pseudo-element in CSS is used to target and style the first letter of the first line of a block-level element, typically for typographic effects. It allows designers to create visual emphasis on the initial character of a paragraph, such as creating drop caps or oversized letters at the start of an article. This pseudo-element only applies to block-level containers, such as p, div, or blockquote, and cannot be used on inline elements like span.

One key feature of ::first-letter is that it can be combined with many CSS properties that affect text and box models, including font-size, font-weight, color, float, margin, and padding. However, certain properties such as background-color may behave differently depending on browser rendering. It is commonly used to create stylistic text enhancements without adding extra HTML markup.

The ::first-letter pseudo-element supports pseudo-class combinations and can be styled along with other pseudo-elements like ::first-line. It is important to note that it only affects the first letter that is a typographical character; punctuation marks, numbers, or symbols may be ignored depending on the browser.

Here is a simple example demonstrating its use:

<p>Typography enthusiasts often use decorative letters at the beginning of paragraphs.</p>
p::first-letter {
    font-size: 3em;
    font-weight: bold;
    color: #2a9d8f;
    float: left;
    margin-right: 0.1em;
}

In this example, the first letter of the paragraph is enlarged, bolded, colored, and floated to the left, creating a visually appealing drop-cap effect. This pseudo-element provides a clean way to enhance textual presentation while maintaining semantic HTML structure.

Syntax

element::first-letter { … }

Example

<article>
<p class="intro-text">
Once upon a time in a land far away, there was a programmer who
wanted to make their typography stand out. By using just a few
lines of CSS, they transformed a simple paragraph into a
classic piece of digital art.
</p>
</article>
/* Target the first letter of the paragraph with the intro-text class */
.intro-text::first-letter {
font-size: 3.5rem;
font-weight: bold;
color: #2c3e50;
float: left;
line-height: 1;
padding-right: 8px;
font-family: "Georgia", serif;
}

/* Optional styling for the rest of the text */
.intro-text {
font-family: sans-serif;
line-height: 1.6;
color: #333;
max-width: 600px;
}

Browser Support

The following information will show you the current browser support for the CSS ::first-letter pseudo element. Hover over a browser icon to see the version that first introduced support for this CSS psuedo element.

This psuedo element is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 31st December 2025

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!