Color scheme

Marker, Backdrop, and Selection

Most pseudo-elements target content you create, like ::before and ::after. The three pseudo-elements on this page are different. They target parts of the browser's own rendering: the bullet or number in front of a list item, the overlay behind a modal dialog, and the highlight color when a user selects text. These are things that have always existed visually, but for most of CSS history you had no direct way to style them. Now you do.

All three pseudo-elements enjoy full support in modern browsers. Each one has a deliberately limited set of allowed properties, so understanding what you can and cannot style is just as important as knowing the syntax.

::marker

The ::marker pseudo-element selects the marker box of a list item. That is the bullet in an unordered list or the number in an ordered list. Before ::marker existed, the only way to customize a bullet was to hide it with list-style: none and fake one using ::before. That approach works, but it throws away the browser's built-in marker behavior, including proper alignment, counter management, and accessibility semantics. With ::marker, you style the real marker directly.

The most important thing to understand about ::marker is that it only accepts a limited set of CSS properties. You can use color, content, white-space, direction, unicode-bidi, text-combine-upright, all font properties (like font-size, font-family, and font-weight), and all animation and transition properties. That is it. You cannot set background, padding, width, transform, or anything else. The specification notes that additional properties may be supported in the future, but for now the list is short.


        /* Change bullet color and size */
        li::marker {
            color: teal;
            font-size: 1.4em;
        }

        /* Replace bullets with emoji */
        ul li::marker {
            content: "✦ ";
        }

        /* Style ordered list numbers */
        ol li::marker {
            color: var(--accent);
            font-weight: 700;
        }
    

The content property is what makes ::marker truly flexible. You can replace the default bullet or number with any string, emoji, or even a CSS counter expression. When you combine content with the counter() function, you can build completely custom numbering formats while still using the native counter system:


        ol {
            counter-reset: steps;
        }
        ol li {
            counter-increment: steps;
        }
        ol li::marker {
            content: "Step " counter(steps) ". ";
            color: var(--accent);
            font-weight: 700;
        }
    

One useful detail: ::marker is not limited to <li> elements. It works on any element with display: list-item. That includes the <summary> element inside a <details> disclosure, and you can apply display: list-item to headings or other elements to give them markers too.

If you need full control over the marker, including backgrounds, transforms, or positioning, ::marker is not the right tool. In those cases, hide the native marker with list-style: none and use ::before instead. Use ::marker for what it does well: quick, clean changes to color, font, and content.

::backdrop

The ::backdrop pseudo-element is a box the size of the viewport that the browser renders immediately behind any element placed in the top layer. Three things trigger it: a <dialog> opened with showModal(), an element with the popover attribute that has been shown, and an element placed in fullscreen mode via the Fullscreen API. In all three cases, the backdrop sits between the top layer element and everything else on the page.

By default, a modal dialog's backdrop is a semi-transparent black overlay. You can style it however you want, including solid colors, gradients, or even a backdrop-filter blur that makes the page content behind the dialog appear frosted:


        /* Simple dark overlay */
        dialog::backdrop {
            background: rgb(0 0 0 / 0.6);
        }

        /* Frosted glass effect */
        dialog::backdrop {
            background: rgb(0 0 0 / 0.3);
            backdrop-filter: blur(8px);
        }

        /* Branded gradient */
        dialog::backdrop {
            background: linear-gradient(
                135deg,
                rgb(15 23 42 / 0.8),
                rgb(30 58 138 / 0.6)
            );
        }
    

One important behavior to understand: ::backdrop does not inherit from any element, and nothing inherits from it. It exists in its own isolated box. That means custom properties defined on :root or body are not automatically available inside ::backdrop. If you want to use your design tokens, you may need to redeclare them or use a strategy like setting custom properties on the dialog element and referencing them from there.

Popover elements also get a ::backdrop, though its default styling is transparent. Unlike a modal dialog, a popover does not make the rest of the page inert, so using a heavy backdrop behind a popover can confuse users. The MDN guide on using the Popover API covers the relationship between popovers, dialogs, and their backdrops in detail.

You can animate a ::backdrop in and out alongside a dialog or popover using @starting-style, transition-behavior: allow-discrete, and the overlay property. This is a more advanced technique that your teammates will learn about in Unit 6 when the course covers transitions and animations.

::selection

The ::selection pseudo-element targets text that the user has highlighted, typically by clicking and dragging with a mouse or using keyboard shortcuts. Every browser has a default selection style, usually a blue background with white text. The ::selection pseudo-element lets you replace those defaults to match your site's design.


        /* Global selection style */
        ::selection {
            color: #fff;
            background-color: #2563eb;
        }

        /* Different selection style for a specific element */
        blockquote::selection {
            color: #1a1a1a;
            background-color: #fcd34d;
        }
    

Like ::marker, the ::selection pseudo-element only accepts a limited set of properties. The ones you will actually use are color, background-color, and text-shadow. A few other properties are technically allowed (text-decoration, stroke-color, fill-color, and -webkit-text-stroke-color), but the core three are what matter in practice. Notably, background-image is explicitly ignored.

Accessibility and Contrast

MDN's documentation includes a clear caution about overriding selection styles: do not change them purely for visual flair. Some users customize their own selection colors for readability. If you do override them, make sure the contrast ratio between your chosen text color and background color is high enough for people with low vision to read. A selection style that looks great on your screen but fails a contrast check is worse than the browser default.

A good rule of thumb is to test your selection colors the same way you test your body text: run them through a contrast checker and aim for at least a 4.5:1 ratio. Light text on a dark selection background (or vice versa) usually works well. Avoid subtle combinations like light gray text on a slightly different light gray background.

Live Demo

The demo below shows all three pseudo-elements in action. The list uses ::marker to set custom colors and content. The button opens a modal dialog with a styled ::backdrop. And the paragraph text uses a custom ::selection color. Try selecting any text on the page to see the highlight change:

::marker

  • Custom bullet via content
  • Color set with the accent token
  • Font size scaled up
  1. Numbers styled bold and green
  2. No extra classes needed
  3. Native counter still works

::backdrop

Click the button to open a modal dialog with a frosted backdrop.

This dialog's ::backdrop uses a dark overlay with a backdrop-filter: blur(4px) to create a frosted glass effect behind the modal.

::selection

Try selecting this text with your mouse. The highlight color is purple with white text, set using the ::selection pseudo-element. This applies to all text inside the demo container.

Here is the CSS behind the three pieces of the demo:


        /* Marker: custom bullets and styled numbers */
        ul li::marker {
            content: "✦ ";
            color: #2563eb;
            font-size: 1.1em;
        }
        ol li::marker {
            color: #059669;
            font-weight: 700;
        }

        /* Backdrop: frosted overlay behind a modal dialog */
        dialog::backdrop {
            background: rgb(15 23 42 / 0.5);
            backdrop-filter: blur(4px);
        }

        /* Selection: purple highlight with white text */
        ::selection {
            background-color: #7c3aed;
            color: #fff;
        }
    

Resources

Use these references to deepen your understanding and find ideas for your teaching video:

Teaching Video Checklist

You do not need to follow this order, but your teammates should come away understanding each of these concepts:

  • What ::marker targets, which properties it allows, and when to use ::before instead
  • A working demo showing custom bullet content, emoji markers, or styled ordered list numbers using ::marker
  • What ::backdrop is, which elements trigger it (modal dialogs, popovers, fullscreen), and that it does not inherit from any other element
  • A working demo showing a styled dialog::backdrop with a color, gradient, or blur effect
  • How ::selection works, its limited property support, and why contrast matters for accessibility when overriding selection colors