Zero-width space
The zero-width space (rendered: ; HTML entity: ​ or ​), abbreviated ZWSP, is a non-printing character used in computerized typesetting to indicate where the word boundaries are, without actually displaying a visible space in the rendered text. This enables text-processing systems for scripts that do not use explicit spacing to recognize where word boundaries are for the purpose of handling line breaks appropriately.
The zero-width space is Unicode character U+200B
, and is located in the Unicode General Punctuation block. In HTML, it can be represented by the character entity reference ​
.
Purpose
[edit]The zero-width space marks a potential line break without hyphenation. Its semantics and HTML implementation are similar to the soft hyphen, but soft hyphens display a hyphen character at the point where the line is broken.
The zero-width space can be used to mark word breaks in languages without visible space between words, such as Thai, Myanmar, Khmer, and Japanese.[1]
In justified text, the rendering engine may add inter-character spacing, also known as letter spacing, between letters separated by a zero-width space, unlike around fixed-width spaces.[1]
Example
[edit]To show the effect of the zero-width space in text, the following words have been separated with zero-width spaces:
LoremIpsumDolorSitAmetConsecteturAdipiscingElitSedDoEiusmodTemporIncididuntUtLaboreEtDoloreMagnaAliquaUtEnimAdMinimVeniamQuisNostrudExercitationUllamcoLaborisNisiUtAliquipExEaCommodoConsequatDuisAuteIrureDolorInReprehenderitInVoluptateVelitEsseCillumDoloreEuFugiatNullaPariaturExcepteurSintOccaecatCupidatatNonProidentSuntInCulpaQuiOfficiaDeseruntMollitAnimIdEstLaborum
By contrast, the following words have not been separated:
LoremIpsumDolorSitAmetConsecteturAdipiscingElitSedDoEiusmodTemporIncididuntUtLaboreEtDoloreMagnaAliquaUtEnimAdMinimVeniamQuisNostrudExercitationUllamcoLaborisNisiUtAliquipExEaCommodoConsequatDuisAuteIrureDolorInReprehenderitInVoluptateVelitEsseCillumDoloreEuFugiatNullaPariaturExcepteurSintOccaecatCupidatatNonProidentSuntInCulpaQuiOfficiaDeseruntMollitAnimIdEstLaborum
The first text is broken into lines but only at word boundaries, and resizing the browser window will re-break the text accordingly, while the second text is not broken at all.
Usage
[edit]HTML
[edit]In HTML pages, the HTML element <wbr>
functions as a zero-width space. In Internet Explorer 6, the zero-width space was not supported in some fonts.[2]
Unspecific use
[edit]The zero-width space should not be used to prevent automatic conversion of certain character combinations into emojis, because it marks a line break opportunity.[note 1] To prevent systems from converting sequences like :)
into emoji like ☺ or 🙂, the zero-width non-joiner or any other non-breaking non-displayed character should be used.[3][note 2]
Prohibition in domain names
[edit]ICANN rules prohibit domain names from containing non-displayed characters, including the zero-width space, and most browsers prohibit their use within domain names because they can be used to create a homograph attack, where a malicious URL is visually indistinguishable from a legitimate one.[4][5]
Encoding
[edit]The zero-width space character is encoded in Unicode as U+200B ZERO WIDTH SPACE.[6]
In HTML, it can be referenced as ​
, ​
or ​
. Additionally, the character entities ​
, ​
, ​
, and ​
all also refer to the zero-width space, contrary to what their names suggest.[7]
In HTML 'mailto:' tags[clarify], %E2%80%8B renders a zero-width space (but may interfere with correctly copying the email link).
The TeX representation is \hskip0pt
; the LaTeX representation is \hspace{0pt}
;[8] and the groff representation is \:
.[9]
See also
[edit]- Hair space
- Whitespace character – including a table comparing various space-like characters
- Word divider
- Word wrapping
- Word joiner (U+2060: ), as well as zero-width no-break space (U+FEFF: )
- Zero-width joiner (U+200D: )
- Zero-width non-joiner (U+200C: )
References
[edit]Note
[edit]- ^ Due to the zero-width space marking a line break opportunity, when the zero-width space is used to prevent an ASCII equivalent from being parsed as such and converted to the corresponding emoji, the line could be broken between constituents of the sequence. E.g. when a zero-width space is added between the colon and the parenthesis of
:)
, the:
could end up at the line end, and the)
could end up at the line start. That makes the zero-width space unfit for this use, no matter how legitimate this use is otherwise. - ^ This reference is not directly related to the subject matter, but it describes a similar use case, and the recommendation is transposable, as in one case, the purpose is to prevent a sequence of digits from being parsed as a single numerator rather than as a whole part and a numerator, and in the case at hand here, the purpose is to prevent an ASCII sequence from being parsed as an emoji. The reference states that "Any zero-width, invisible character will do the trick." But obviously this character needs to be no-break, and the quotation ends: "something like U+200C ZERO WIDTH NON-JOINER or U+2060 WORD JOINER will also work." None of these two is breaking, and it is not stated that U+200B ZERO WIDTH SPACE would also work. Because yes, it does work, but additionally it marks a line break opportunity, and that is obviously not part of the intended behavior. There is really no research needed to notice this. What we need to do is to make sense of what we read.
Citations
[edit]- ^ a b "23.2 Layout Controls". The Unicode® Standard Version 15.0 – Core Specification (PDF). The Unicode Consortium. September 2022. p. 918. ISBN 978-1-936213-32-0.
- ^ Dunae, Alex. "Better Web Typography with Spaces and Hyphens". dunae.ca. Archived from the original on December 14, 2010. Retrieved December 3, 2009.
- ^ "How to display the fraction 15/16 nicely in Unicode?". Retrieved 2024-09-07.
- ^ "Network.IDN.blacklist_chars". mozillaZine. Retrieved 2018-02-07.
- ^ "Unicode Character 'Zero Width Space'". FileFormat.Info. Retrieved 2018-02-07.
- ^ "General Punctuation – Unicode" (PDF). Retrieved 2013-07-20.
- ^ Entities/ZeroWidthSpace in MathML Version 2.0
- ^ "The LaTeX Companion. Chapter 3: Basic Formatting Tools" (PDF). Retrieved 2019-07-16.
- ^ "groff(7) – Linux manual page". Retrieved 2014-02-08.
Sources
[edit]- Mair, Victor H.; Liu, Yongquan (1991), Characters and computers, IOS Press