This is a card in Dave's Virtual Box of Cards.

Fix HTML documents displaying elements with small monospace fonts

Created: 2024-10-23

One long-standing annoyance with HTML documents is that browsers display monospace fonts smaller than the surrounding text!

It’s not your imagination, the text in <pre> and <code> tags really is smaller.

The fix, as pointed out by Stack Overflow user vector001, is to set the font size for these elements to the root document default like so:

pre, code { font-size: 1rem; }

Note the use of "rem" rather than "em". You can’t use a relative size like "1em" because that’s relative to its existing size. The "r" in "rem" stands for "root".

To quote MDN:

rem - Represents the font-size of the root element (typically <html>). When used within the root element font-size, it represents its initial value. A common browser default is 16px, but user-defined preferences may modify this.

Anyway, that’s that fixed.

Back to web stuff.