Non-breaking space
Special character in text processing
From Wikipedia, the free encyclopedia
In word processing and digital typesetting, a non-breaking space ( ), also called NBSP, required space,[1] hard space, or fixed space (in most typefaces,[b] it is not of fixed width), is a space character that prevents an automatic line break at its position. In some formats, including HTML, it also prevents consecutive whitespace characters from collapsing into a single space. Non-breaking space characters with other widths also exist.
Non-breaking space | |
|---|---|
| U+00A0 NO-BREAK SPACE ( ,  ) | |
| See also | |
| U+202F NARROW NO-BREAK SPACE Other types of spaces |
Behavior
Despite having layout and uses similar to those of whitespace, it differs in contextual behavior.[2][3]
Text-processing software generally assumes that an automatic line break may be inserted anywhere a space character occurs; a non-breaking space prevents this from happening, if it is supported by the software.
To show the effect of the non-breaking space in text, the following words have been separated with non-breaking spaces. No matter the width of the window, no line breaks are displayed:
Lorem Ipsum Dolor Sit Amet Consectetur Adipiscing Elit Sed Do Eiusmod Tempor Incididunt Ut Labore Et Dolore Magna Aliqua Ut Enim Ad Minim Veniam Quis Nostrud Exercitation Ullamco Laboris Nisi Ut Aliquip Ex Ea Commodo Consequat Duis Aute Irure Dolor In Reprehenderit In Voluptate Velit Esse Cillum Dolore Eu Fugiat Nulla Pariatur Excepteur Sint Occaecat Cupidatat Non Proident Sunt In Culpa Qui Officia Deserunt Mollit Anim Id Est Laborum
By contrast, words separated with ordinary spaces will reflow as the window size changes:
Lorem Ipsum Dolor Sit Amet Consectetur Adipiscing Elit Sed Do Eiusmod Tempor Incididunt Ut Labore Et Dolore Magna Aliqua Ut Enim Ad Minim Veniam Quis Nostrud Exercitation Ullamco Laboris Nisi Ut Aliquip Ex Ea Commodo Consequat Duis Aute Irure Dolor In Reprehenderit In Voluptate Velit Esse Cillum Dolore Eu Fugiat Nulla Pariatur Excepteur Sint Occaecat Cupidatat Non Proident Sunt In Culpa Qui Officia Deserunt Mollit Anim Id Est Laborum
In this example, most spaces are non-breaking, but every third space is an ordinary breaking space. This shows how groups of words can be prevented from being divided across lines by automatic line breaks:
Lorem Ipsum Dolor Sit Amet Consectetur Adipiscing Elit Sed Do Eiusmod Tempor Incididunt Ut Labore Et Dolore Magna Aliqua Ut Enim Ad Minim Veniam Quis Nostrud Exercitation Ullamco Laboris Nisi Ut Aliquip Ex Ea Commodo Consequat Duis Aute Irure Dolor In Reprehenderit In Voluptate Velit Esse Cillum Dolore Eu Fugiat Nulla Pariatur Excepteur Sint Occaecat Cupidatat Non Proident Sunt In Culpa Qui Officia Deserunt Mollit Anim Id Est Laborum
Uses
Numbers with units
Text-processing software can divide expressions like "100 km" when they do not quite fit at the end of a line. A non-breaking space between "100" and "km" prevents this, and guarantees that "100 km" will not be broken—if it does not fit at the end of a line, it is moved in its entirety to the next line. Many style guides recommend that numbers and the associated units not be split across lines; non-breaking spaces are used to ensure this.[4][5]
Spacing punctuation in French
In French typography, non-breaking spaces are used before "high punctuation" (:, ;, ?, and !), on the interior side of guillemets (« and »), and before footnote references. In the case of ;, ?, !, and footnote references (unless enclosed by parentheses), a narrow non-breaking space is used.[6][7]
Multi-part abbreviations in German
In German typography, it is used between multi-part abbreviations (e.g., "z. B.", "d. h.", "v. l. n. r.").[8]
Computer languages
Non-collapsing behavior
Non-breaking spaces are used in plain text file formats such as SGML, HTML, TeX and LaTeX, whose rendering engines are programmed to treat sequences of whitespace characters (space, newline, tab, form feed, etc.) as if they were a single character (but this behavior can be overridden). Such "collapsing" of whitespace allows the author to neatly arrange the source text using line breaks, indentation and other forms of spacing without affecting the final typeset result.[9][10]
To show the non-collapsing behavior of the non-breaking space, the following words have been separated with an increasing number of non-breaking spaces:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
In contrast, the first few words of this phrase have been separated with many ordinary spaces but are displayed (rendered by the Browser engine) as single spaces:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
Non-void or non-missing behavior
In programming languages or in software analysis languages (such as SAS or R) non-breaking spaces can be useful to fill character-type variables with spaces that are not to be considered insignificant. In general, a string filled with spaces can be interpreted as an empty string or a string of missing data. Replacing ordinary spaces with non-breaking spaces helps resolving the ambiguity between "space", "void" and "missing".
Variations
Narrow non-breaking space
U+202F NARROW NO-BREAK SPACE (NNBSP) is a non-breaking space that is narrower than the standard non-breaking space (U+00A0). For Mongolian, its is usually one third the width of a normal space;[11] in other contexts, its width is about 70% of the normal space, but may resemble that of the thin space (U+2009), at least with some fonts.[citation needed]
This text replaces spaces with narrow non-breaking spaces:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
Narrow non-breaking space was introduced in 1999 in Unicode 3.0 for Mongolian,[12] to separate a suffix from the word stem without indicating a word boundary. It also triggers special shaping of those suffixes.[13] Starting in Unicode 16.0, it is no longer recommended for this purpose, with the Mongolian vowel separator (U+180E) taking on this function.[14][15]
In French typography, it is called espace fine insécable[14] and is used before ;, ?, and ! (with the exception of : before which a regular non-breaking space is used).[6][7] Additionally, a footnote reference is preceded by a narrow non-breaking space[7] (unless it is enclosed by parentheses, in which case a regular non-breaking space is used).[6]
The narrow non-breaking space is used in numbers as a group separator in French (starting in Unicode CLDR 34[16]) and Venetian (starting in Unicode CLDR 44[17]). In Spanish, the Royal Spanish Academy and Association of Academies of the Spanish Language's Diccionario panhispánico de dudas prescribes a small space as the number group separator,[18] although this is not the case in Unicode's Common Locale Data Repository (CLDR).[19]
Figure space
A figure space is a non-breaking space whose width is equal to the figure (0–9) characters.
Unicode
Unicode has multiple non-breaking space characters:
- U+00A0 NO-BREAK SPACE ( ,  )
- U+2007 FIGURE SPACE ( )
- U+202F NARROW NO-BREAK SPACE
- U+FEFF ZERO WIDTH NO-BREAK SPACE is a byte order mark, whose use in text is deemed an "unsupported character" in Unicode (U+2060 WORD JOINER should be used if the need arises).[20]
See also
- Hyphen § Nonbreaking hyphens
- Punctuation – Marks to indicate pacing of written text
- Sentence spacing in digital media – Horizontal width of inter-sentence space
- Space (punctuation) – Blank area that separates text
- Space (punctuation) § Non-breaking space, for applications
- Zero-width space – Special character in text processing, a non-spacing break
- Word joiner – Character in text processing, prevents line-breaking without producing a space
- Widows and orphans – In typography, an isolated line of text starting/ending a page
- Non-printing character in word processors – Formatting marks for content design
- Typographic alignment § Justified
Notes
- with the execption of Monospaced fonts