Pseudo-elements allow us to target specific parts of an element, such as the first letter or the first line. They can also add extra content to the page without modifying the HTML structure.
Pseudo-elements are denoted with a double colon (::), and they target parts that are not separate HTML elements. Examples include ::before, ::after, ::first-line, and ::selection.
| Pseudo-element | Description |
|---|---|
| ::before | Inserts content before the element. |
| ::after | Inserts content after the element. |
| ::first-line | Styles the first line of the element. |
| ::first-letter | Styles the first letter of the element. |
| ::selection | Styles the selected text. |
With pseudo-elements, you can add unique styling to text, for example highlighting the first letter or first line of paragraphs.
In the following example, the first line of a paragraph is bold and blue, while the first letter is larger and red.
With ::before and ::after pseudo-elements, you can add content to the page without modifying the HTML. This is useful for icons, decorations, or additional text.
Pseudo-elements can greatly enrich design and improve user experience. Here are some tips:
✨ Ask Lara — your AI study partner
Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.
Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.