How to render narrow non-breaking spaces in HTML for Windows?

FroMage picture FroMage · Feb 27, 2009 · Viewed 14.7k times · Source

In French, typography requires that we use narrow non-breaking space (U+202F) at various places (“Comme ça !”).

Apparently every browser on windows fails to support that and they all display a weird character instead. This works on most browsers on Mac OS X as well as Linux.

Does anyone know how to make Windows browsers render it correctly?

(I’m assuming it’s a Windows bug rather than a browser bug since Firefox and Safari both support it as long as it’s not on Windows).

Answer

Verdy_p picture Verdy_p · Oct 15, 2009

Hmmm... no. If the only problem is the fact that   (U+2009) is still breaking, I will prefer to use:

<span style="white-space:nowrap">&thinsp;</span>

to correct the breaking behavior. Why?

  • Because the French fine is effectively using a nearly fixed width between one sixth to one fourth of a cadratin (0.166 ca. to 0.25 ca., when the standard space is 0.5 ca.) The choice of the width depends on the approach already present within the glyphs defined in a given font.

  • Fonts are made to adjust the width of their thin space (U+2009): if these fonts were made by French typographs (for rendering French), the approche (or gaps between letters in words) is narrower than in fonts designed for English: this is because French texts generally contain more letters than equivalent English texts (for exemple the printed Bible), and to avoid increasing the number of printed pages, the glyphs in French fonts were made a bit narrower and with a reduced approach; to compensate this reduction, the French fine was increased in size. (It is often said that U+2009 is one fifth of a cadratin, i.e. 0.2 ca., but this is wrong as this value is just a reasonnable median value, which should effectively be adjusted in fonts according to their design).

  • In English with an English typography, the inter-character gaps is already large enough to justify the fact that a no thin space is used in texts near most double punctuation signs. However, if French is rendered with a font using an English typography (which has larger inter-character gaps), the fine should be narrower and should be reduced to 1/6th cadratin.

  • So yes, U+2009 (&thinsp; in the SGML repository) is slightly adjustable, depending on fonts.

  • In addition it may be partically justified (when full justification is used, where not just the usual inter-word spaces have their width increased, but also all gaps between characters and normal or ''fine'' spaces (but the other quad spaces MUST NOT have their width adjusted: they are really fixed).

When you are rendering a document whose page layout is already precomputed (with known fonts and with exact metrics), the thin space (U+2009) is already what you want (because you won't have to worry about the breaking behavior.

Unfortunately, Unicode forgot to assign to these quad spaces U+2000..U+2006 (and to the thin space U+2009) the non-breaking behavior in the line-breaking properties.

The only way for Unicode to correct it (for plain text documents only), was to add another character, namely U+202F (the NARROW NON-BREAKING SPACE) in Unicode 5.1, which was later given the SGML symbolic name "nnbsp" for character references (but the mapping of this named character entity to U+202F is not part of any HTML or XML standard, so this named entity should not be used as well, unless your document defines it explicitly in its embedded DTD !)

But unfortunately, most browsers have forgotten to apply this addition and why it was needed: they assume that the character should be in fonts, but this is clearly not the case.

ALL browsers SHOULD treat U+202F as non-breaking (this is already the case, even if they don't know the character in their internal copy of the UCD).

However, browsers SHOULD NOT depend on the fact that U+202F is defined in a font, instead, they SHOULD provide a fallback to U+2009 (THIN SPACE) when rendering it, each time U+202F is not mapped in the current font, but U+2009 is mapped in the same font (this is generally the case with many fonts).

So this is a problem in HTML renderers (i.e. browsers); I also think that this is more than just a problem of fonts, it is really a BUG of browsers (rather than a bug or limit in fonts), if they don't provide such fallbacks for whitespaces. Of course, all new fonts should map U+202F to the same glyph as U+2009.

Given that the thin space (U+2009, or &thinsp;) is very well supported in many fonts, and has the correct width for rendering French texts with fonts made with French typographic metrics, or for rendering English texts made with English typographic metrics, this should really be the correct fallback to use each time the narrow non-breaking space is not available !

You can perfectly emulate the desired behavior of U+202F in HTML, by just using U+2009 and making it non-breaking using CSS's "white-space:nowrap". It will always be better than changing the font-size to display a pseudo half-space (because this is not correct with many fonts for which this will still be too large, and also because this does not work as expected in spans of text that have colored backgrounds: changing the font-size modifies the line-height).

So please use this code instead in your HTML or SVG documents (keep U+202F only for plain-text documents):

<span style="white-space:nowrap">&thinsp;</span>

You can save this sequence in a reusable template, that you can name Template:nnbsp in MediaWiki for example, for transcluding it in your pages as {{nnbsp}}.

Note that it is still preferable to reference the thin space symbolically as &thinsp; rather than forcing an exact Unicode code point like &#x2009; : the named entity can be remapped by the renderer, or according to user preferences to another working whitespace.

Note that MS-word really uses U+2009 and not U+202F for representing its own fine. It is correct, given that Word documents have a precomputed layout, and given that MS-Word enforces locally the non-breaking behavior when computing the page layout. Word documents are not plain-text documents.

  • Exemple of rendering (using background colors to exhibit that the line-height is not modified, but unfortunately this site does not allow setting background colors except in <code> sections like here, which use monospace fonts) :

Exemple de « fine » insécable française correctement codée !

  • The same without the <code> container does not display the background color, but it does use the normal proportional fonts, so that the thin space is effectively rendered as thin:

Exemple de « fine » insécable française ; correctement codée !

  • Example using &#x202F; (NNBSP which is generally not supported in most fonts, but this may eventually work with your current browser and the fonts installed on your system, such as DejaVu Sans):

Exemple de « fine » insécable française ; correctement codée !

  • Example using &#x2006; (SIXTH OF CADRATIN, may work but may be too narrow for your fonts, and may not exhibit the non-breaking property):

Exemple de « fine » insécable française ; correctement codée ! (hmmm... not really)

  • Example using &nbsp; (which is almost always too large):

Exemple de « fine » insécable française ; correctement codée ! (hmm... not really)