In this blog we will cover some of the lesser used but pretty useful Pseudo Elements.
::selection CSS pseudo-element styles the part of a document that is selected by a user (such as clicking and dragging the mouse across text to highlight it).
::marker CSS pseudo-element selects the marker box of a list item and generally contains a bullet or number. It works on any element or pseudo-element where the
display property is set to
display: list-item), such as
::placeholder CSS pseudo-element can be used to target the placeholder text in an
::slotted() CSS pseudo-element represents any element that has been placed into a
slot inside an HTML template.
This only works when used inside CSS placed within a Shadow DOM. Note also that this selector won't select a text node placed into a slot, but targets actual elements.
Just as the name suggests, the
::first-letter CSS pseudo-elements applies styles to the first line and the first letter respectively (of a block-level element). In case of
::first-line, the length of the first line depends on many factors, including the width of the element, the width of the document, the font size of the text and may even depend on the screen size.
::first-letter only styles the first letter when not preceded by other content (such as images or inline tables).
I have deliberately skipped some pseudo-elements like
::target-text as its difficult to create an example in a codepen sandbox for it, and some like
::spelling-error as no browser supports it as of yet.
Reach out to me on: