brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ::marker styles list bullets without extra markup

Web-Development
~/tips/tip-css-marker-pseudo-element

ul li::marker {

Colours or replaces the bullets and numbers of a list directly in CSS.

For years I wrapped list text in a span or switched to list-style: none and drew a fake bullet. ::marker styles the real one.

MDN says ::marker selects the marker box of a list item, which typically holds a bullet or a number. It works on li and summary and on any element with display: list-item.

ul li::marker {
  color: tomato;
  font-size: 1.2em;
}

summary::marker {
  content: "+ ";
}

The first rule colours the bullets and makes them a bit larger without touching the text. The second replaces the disclosure triangle of a details element with a plus sign. Numbers in an ol get the same treatment, which is useful for a coloured counter, and the font-variant-numeric font property can keep the digits aligned.

The caveat is the short list of properties that are allowed. MDN lists all font properties, color, content, white-space, the animation and transition properties, counter-increment and counter-reset, quotes, direction and a few more. Padding, margin and background do nothing on a marker. If you need spacing or a background behind the bullet, you still need ::before on the item. MDN also marks ::marker as having limited availability, so check the compatibility table for the browsers you must support. A browser that ignores the rule simply shows the default bullet.

Further reading: MDN: ::marker

More Web-Development tips ab -n 200 -c 10 https://example.com/ console.assert(items.length > 0, 'cart is empty', items) document.designMode = "on" function save(item) { Save draft All Web-Development tips (67) All topics

Link