Describe pseudo-elements and discuss what they are used for.
Quiz · CSS
Medium
3 min
css
A CSS pseudo-element is a keyword added to a selector that lets you style a specific part of the selected element(s). They can be used for decoration (:first-line, :first-letter) or adding elements to the markup (combined with content: ...) without having to modify the markup (:before, :after).
:first-lineand:first-lettercan be used to decorate text.- Used in the
.clearfixhack as shown above to add a zero-space element withclear: both. - Triangular arrows in tooltips use
:beforeand:after. Encourages separation of concerns because the triangle is considered part of styling and not really the DOM.
Adapted from the Front End Interview Handbook by Yangshun Tay and contributors (MIT License). Source
Spotted a mistake or a rights concern? Report an issue