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: a non-breaking space keeps 10 GB and other number and unit pairs on one line

Web-Development
~/tips/tip-nbsp-number-unit-together

20 GB free. See Fig. 3 and page 12.</p>

Values and their units never end up split across two lines.

A line that ends in “10” with “GB” on the next line is a small thing, but it slows reading. A non-breaking space between the two keeps them together.

<p>The image is about 10&nbsp;GB, so leave at least
20&nbsp;GB free. See Fig.&nbsp;3 and page&nbsp;12.</p>

<!-- narrow no-break space, for example before a percent sign in French -->
<p lang="fr">Une hausse de 12&#8239;%.</p>

&nbsp; looks like a normal space but the browser never breaks a line there. I’d put it between numbers and units, after abbreviations like “Fig.” and “p.”, and between a short word and a number that belong together. The narrow version, &#8239; (U+202F), is the thin space some languages use before units or punctuation.

In a CMS you can usually type it with Option+Space on a Mac keyboard, but then it is invisible in the source, which makes it hard to see later. I prefer the entity because it shows what I meant.

The catch is code. A non-breaking space that sneaks into a command, for example after copying from a page or typing Option+Space by accident, is not a space to the shell. The command fails with a confusing “not found” error. So keep these out of code blocks and commands people will copy.

Further reading: MDN: Entity, MDN: white-space

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