::before and ::after Content
Insert generated content before or after elements using ::before and ::after with the content property.
What are Pseudo-elements?
Pseudo-elements create virtual elements that are styled as if they were part of the DOM. They use double colons ::. The most used are ::before and ::after.
::before and ::after
::before inserts generated content before an element's content. ::after inserts it after. Both require the content property to render.
.element::before {
content: ""; /* required even if empty */
display: block;
}
.element::after {
content: "→";
}All lessons in this course
- ::before and ::after Content
- ::placeholder ::selection and ::marker
- CSS Counters with ::before
- Decorative Patterns with Pseudo-elements