::first-letter CSS Pseudo Element

Description

The ::first-letter pseudo-element defines the style of the first character in the text of the element to which it is added. Only stylistic properties associated with font properties, margins, indents, borders, color and background can be applied to this pseudo-element.

Syntax

element::first-letter { … }

Example

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.,</p>
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
 p { 
font-family: Arial, Helvetica, sans-serif;
font-size: 0.9em;
}
p::first-letter {
font-family: "Times New Roman", Times, serif;
font-size: 2em;
color: red;
}

Notes

In CSS3, pseudo-elements were denoted by two colons to make the syntax different from pseudo-classes. In CSS2, they are indicated by a single colon. Browsers generally understand both syntaxes.

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
??????
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
?????X