-moz-bullet-font can affect the line height
Reviewing a recent post about my favorite records of 2024, I noticed something off about two lists rendered next to each other. The unordered list has a larger line height than the ordered one, but only in Firefox. Why’s that?
Firefox devtools showed in the Fonts tab that the marker is using a font named -moz-bullet-font
, and not inheriting the font from its ancestors like the Rules panel implied.
The Mozilla Bullet font is defined inline in Firefox’s default stylesheet for HTML, and was introduced three years ago to replace the bullet images previously in use. It contains glyphs for the all the simple symbolic counters: disc
, circle
, and square
, as well as disclosure-open
and disclosure-closed
for all writing modes.
Using a browser-defined font like this is codified in the spec: When used in
list-style-type
, a UA may instead render these styles using a UA-generated image or a UA-chosen font instead of rendering the specified character in the element’s own font. If using an image, it must look similar to the character, and must be sized to attractively fill a 1em by 1em square.
The reason why there’s no rule in the default stylesheet to apply this font…
::marker {
font-family: -moz-bullet-font;
}
…is because the marker must pick up the parent’s font-family
in all other situations, including when changing the marker’s presentation via the content
property. Instead, it’s all handled at the code level, and thus invisible to the Rules tab in devtools. (Technically a bug, but one whose resolution might not justify the effort.)
How to fix the spacing? As with other things that may affect the line height, throwing in line-height: 0
seems to do the trick, and you may very well leave it at that.
::marker {
line-height: 0;
}
But let’s see if we can align Firefox with what other browsers are doing, and inherit the font in all cases.
::marker {
font: inherit;
}
One immediate problem with this is the default character sequence used in unordered lists, "• "
(bullet followed by space), looks dainty and crammed against the text in most fonts. Mozilla Bullet works around that by defining a wider space character. Similarly, Chrome and Safari seem to use internal adjustments to the spacing to make it look a bit better than straight-up rendering the two characters.
As Šime Vidas points out, the possibilities for spacing list markers are quite limited. Moreover, built-in counter styles such as disc
can’t be overriden. The kind of solution robust enough for a CSS reset is therefore a bit verbose, and involves defining new counter styles with better spacing (via space characters, no less). This would be just for fixing the disc
list markers:
@counter-style disc-fixed {
system: cyclic;
/* bullet character… */
symbols: \2022;
/* …followed by three spaces for better spacing */
suffix: " ";
}
ul, menu, dir {
list-style-type: disc-fixed;
}
::marker {
font: inherit;
}
Kind of a hard sell, to be honest. But yeah, that’s where the line-height thing comes from.