(Edit: I only need this for the 10 digits 0..9, can I hardcode the letter width for each one of the 10 digits in the CSS file?)
I have read CSS - Make sans-serif font imitate monospace font but the CSS rule letter-spacing doesn't seem to be enough:
How to imitate a monospace fixed font from a standard sans-serif font?
This doesn't work perfectly:
.text {
font-family: sans-serif;
letter-spacing: 10px;
}
<div class="text">
ABCDEFGHIJKLMNOPQR<br>
STUVWXYZ0123456789
</div>


TL;DR: imitating monospace fonts always introduces issues
font-variant-numeric: tabular-numsif you only need to get tabular numbersAll these hacks are actually way more expensive and "wobbly" with regards to a predictable cross-browser rendering. However let's summarize these hacks:
Hack 1: Wrap all characters in inline-block elements
Apart from changing the actual font metrics in a font editor and compiling a new font you could split up all letters into an array of
<span>elements via javaScript.Each character will be wrapped in a span with an
inline-blockdisplay property.Besides all characters are centered via
text-align:center.The above script will also compare the widths of all characters to set the largest width as the span width.
Admittedly, this is not very handy
but this approach might suffice for design/layout purposes and won't change the actual font files.
As illustrated in the snippet:
In monospace fonts the widest letters like "W" are desined in a kind of squeezed manner (not distorted) whereas the thinner ones like "i" are designed visually stretched (e.g by adding bottom serifs).
So proper monospace fonts can't really be emulated.
Hack 2: Substitute only digits
Quite a few web fonts also include tabular numerals which can be applied via CSS property
font-variant-numeric: tabular-nums.Apply additional font only to numbers
We can specify a unicode-range in the
@font-facerule to apply a font only to numbersHack 3: (very experimental!)
text-transform: full-widthThis property normalizes rendered character-widths to a uniform value. This feature is currently only supported by Firefox.
Why
letter-spacingdoesn't workletter-spacingjust evenly inserts whitespace between all letters (...hence the name).It won't normalize characters/glyphs to have the same widths.
We would need a css property like
letter-widthwhich doesn't exist.Most likely we'll never get a similar property as text nodes don't add selectable sub nodes for each character – this would be kind of an overkill.