CSS ::first-letter Pseudo Element
Use the ::first-letter CSS pseudo-element for selecting and styling the first-letter of the line. Read about the pseudo-element and try examples.
The ::first-letter pseudo-element applies styles to the first letter of the first line in a block-level container. It does not select inline-level elements, such as images or inline-tables.
The ::first-letter pseudo-element does not match punctuation marks that precede or immediately follow the first letter. It only applies to alphabetic characters, not numbers or symbols.
CSS3 specification introduced the ::first-letter to distinguish pseudo-classes from pseudo-elements.
Allowable properties
Here are the CSS properties that can be used with the ::first-letter pseudo-element:
Font properties: font, font-style, font-feature-settings, font-kerning, font-language-override, font-stretch, font-variant, font-variant-alternates, font-variant-caps, font-variant-east-asian, font-variant-ligatures, font-variant-numeric, font-weight, font-size, font-size-adjust, line-height and font-family.
Background properties: background, background-origin, background-position, background-repeat, background-size, background-attachment, background-blend-mode, background-color, background-image, and background-clip.
Margin properties: margin, margin-top, margin-right, margin-bottom, margin-left.
Padding properties: padding, padding-top, padding-right, padding-bottom, padding-left.
Border properties: shorthands, border-style, border-color, border-width, border-radius, border-image, longhands.
The color property.
The text-decoration, text-shadow, text-transform, letter-spacing, word-spacing (when appropriate), text-decoration-color, text-decoration-line, text-decoration-style, box-shadow, float, vertical-align (only float: none;).
Version
Syntax
CSS ::first-letter syntax example
::first-letter {
css declarations;
}Example of the ::first-letter pseudo-element:
CSS ::first-letter code example
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
p::first-letter {
font-size: 35px;
color: #1c87c9;
}
</style>
</head>
<body>
<h2>::first-letter selector example</h2>
<p>Lorem ipsum is simply dummy text...</p>
</body>
</html>Result

Example of the ::first-letter pseudo-element with punctuation mark and a digit:
::first-letter code example
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
p::first-letter {
font-size: 35px;
color: #1c87c9;
}
</style>
</head>
<body>
<h2>::first-letter selector example</h2>
<p>-Lorem ipsum is simply dummy text...</p>
<p>1Lorem ipsum is simply dummy text...</p>
</body>
</html>Practice
How does the CSS ::first-letter pseudo-element selector work?