What is ::first-letter pseudo-element in CSS?
The ::first-letter pseudo-element is used to apply a style to the first letter of the first line of the block-level element.
Syntax
::first-letter {
// css styles
}
Code
In the code above, we created a div element with some text. In the CSS we added style to the ::first-letter pseudo-element for the div. The defined style is applied to the first character of the first line of the div.
The allowable properties for the pseudo-element
::first-lettercan be found here.
In the code above, we used the ::first-letter pseudo-element to apply a style for the first letter.
The style is also included for punctuation, because ::first-letter also matches the punctuation before and after the first letter.
If we add some content in the ::before or ::after pseudo-element, then the style is applied to the first letter of the final generated text. In the example above, we added:
div::before{
content: "Before Content";
}
The style above will add the Before Content string before the div element. In this case, the ::first-letter styles are applied to the first letter B of the Before Content string.