[{"data":1,"prerenderedAt":781},["ShallowReactive",2],{"en-html-category-articles":3},[4],{"id":5,"title":6,"articleCover":7,"articleCoverEmbed":8,"articleCoverEmbedUploadDate":8,"articleCoverHeight":9,"articleCoverWidth":10,"authorId":11,"body":12,"categoriesIds":768,"description":769,"enAlternateSlug":770,"extension":771,"meta":772,"navigation":307,"path":773,"ptBrAlternateSlug":774,"publishedAt":775,"seo":776,"sitemap":777,"stem":778,"updatedAt":775,"wordCount":779,"__hash__":780},"blogEn\u002Fen\u002Fblog\u002Fwhat-does-nbsp-mean-in-html.md","What Does &nbsp; Mean in HTML? The Non-Breaking Space Explained","\u002Fimages\u002Fen\u002Fblog\u002Fhtml\u002Fwhat-does-nbsp-mean-in-html.webp",null,720,1280,"thiago-nunes-batista",{"type":13,"value":14,"toc":758},"minimark",[15,23,40,47,50,86,126,129,133,151,154,192,197,201,207,374,389,392,481,503,507,575,592,598,618,634,638,730,754],[16,17,18,22],"p",{},[19,20,21],"code",{},"&nbsp;"," is the HTML entity for a non-breaking space. It produces the character U+00A0 (decimal 160), which is not the same as a regular space, U+0020 (decimal 32). It differs in two ways: the browser never breaks a line at a U+00A0, and it does not collapse several in a row into one, the way it does with regular spaces.",[16,24,25,26,28,29,34,35,39],{},"The two look the same on screen, but code treats them as different characters, and that is where most ",[19,27,21],{}," bugs come from, especially in tests. The full list of entities is in the ",[30,31,33],"a",{"href":32},"\u002Fen\u002Freference\u002Fhtml-entities","HTML entities reference",", and codes 32 and 160 also appear in the ",[30,36,38],{"href":37},"\u002Fen\u002Freference\u002Fascii-table","ASCII table",".",[41,42,44,45],"h2",{"id":43},"when-to-use-nbsp","When to use ",[19,46,21],{},[16,48,49],{},"Use it when two parts of a text must stay on the same line:",[51,52,53,65,71,77,83],"ul",{},[54,55,56,57,60,61,64],"li",{},"a number and its unit: ",[19,58,59],{},"10&nbsp;km",", ",[19,62,63],{},"5&nbsp;kg",";",[54,66,67,68,64],{},"a currency and its amount: ",[19,69,70],{},"R$&nbsp;10.00",[54,72,73,74,64],{},"a title and a name: ",[19,75,76],{},"Dr.&nbsp;Smith",[54,78,79,80,64],{},"a month and a day: ",[19,81,82],{},"November&nbsp;22",[54,84,85],{},"a short word at the end of a paragraph, so it does not sit alone on the last line.",[87,88,93],"pre",{"className":89,"code":90,"language":91,"meta":92,"style":92},"language-html shiki shiki-themes dracula","\u003Cp>The trip is 10&nbsp;km long and costs R$&nbsp;10.00.\u003C\u002Fp>\n","html","",[19,94,95],{"__ignoreMap":92},[96,97,100,104,107,110,113,116,118,121,123],"span",{"class":98,"line":99},"line",1,[96,101,103],{"class":102},"sCdxs","\u003C",[96,105,16],{"class":106},"s0Tla",[96,108,109],{"class":102},">The trip is 10",[96,111,21],{"class":112},"sIQBb",[96,114,115],{"class":102},"km long and costs R$",[96,117,21],{"class":112},[96,119,120],{"class":102},"10.00.\u003C\u002F",[96,122,16],{"class":106},[96,124,125],{"class":102},">\n",[16,127,128],{},"If the screen width forces a line break, it happens before \"10\" or after \"km\", never between them.",[41,130,132],{"id":131},"when-not-to-use-it","When not to use it",[16,134,135,136,60,139,142,143,146,147,150],{},"For layout spacing, if you want space between elements, use ",[19,137,138],{},"margin",[19,140,141],{},"padding",", or ",[19,144,145],{},"gap",". A row of ",[19,148,149],{},"&nbsp;&nbsp;&nbsp;&nbsp;"," to indent text changes with the font, is not read well by screen readers, and is hard to maintain.",[16,152,153],{},"To stop a whole run of text from wrapping, CSS works better:",[87,155,159],{"className":156,"code":157,"language":158,"meta":92,"style":92},"language-css shiki shiki-themes dracula",".price {\n  white-space: nowrap;\n}\n","css",[19,160,161,170,186],{"__ignoreMap":92},[96,162,163,167],{"class":98,"line":99},[96,164,166],{"class":165},"sY_PY",".price",[96,168,169],{"class":102}," {\n",[96,171,173,177,180,183],{"class":98,"line":172},2,[96,174,176],{"class":175},"sLL85","  white-space",[96,178,179],{"class":106},":",[96,181,182],{"class":112}," nowrap",[96,184,185],{"class":102},";\n",[96,187,189],{"class":98,"line":188},3,[96,190,191],{"class":102},"}\n",[16,193,194,196],{},[19,195,21],{}," is for the space between two words, not for a block.",[41,198,200],{"id":199},"the-problem-that-shows-up-in-tests","The problem that shows up in tests",[16,202,203,206],{},[19,204,205],{},"Intl.NumberFormat"," in pt-BR puts a U+00A0 between the currency symbol and the number:",[87,208,212],{"className":209,"code":210,"language":211,"meta":92,"style":92},"language-js shiki shiki-themes dracula","const price = new Intl.NumberFormat(\"pt-BR\", {\n  style: \"currency\",\n  currency: \"BRL\"\n}).format(10);\n\nconsole.log(price); \u002F\u002F \"R$ 10,00\"\nconsole.log(price === \"R$ 10,00\"); \u002F\u002F false\nconsole.log(price === \"R$ 10,00\"); \u002F\u002F true\n","js",[19,213,214,252,270,285,302,309,325,351],{"__ignoreMap":92},[96,215,216,219,222,225,229,232,236,239,243,247,249],{"class":98,"line":99},[96,217,218],{"class":106},"const",[96,220,221],{"class":102}," price ",[96,223,224],{"class":106},"=",[96,226,228],{"class":227},"sviCg"," new",[96,230,231],{"class":102}," Intl.",[96,233,235],{"class":234},"sAOxA","NumberFormat",[96,237,238],{"class":102},"(",[96,240,242],{"class":241},"seVfx","\"",[96,244,246],{"class":245},"s-mGx","pt-BR",[96,248,242],{"class":241},[96,250,251],{"class":102},", {\n",[96,253,254,257,259,262,265,267],{"class":98,"line":172},[96,255,256],{"class":102},"  style",[96,258,179],{"class":106},[96,260,261],{"class":241}," \"",[96,263,264],{"class":245},"currency",[96,266,242],{"class":241},[96,268,269],{"class":102},",\n",[96,271,272,275,277,279,282],{"class":98,"line":188},[96,273,274],{"class":102},"  currency",[96,276,179],{"class":106},[96,278,261],{"class":241},[96,280,281],{"class":245},"BRL",[96,283,284],{"class":241},"\"\n",[96,286,288,291,294,296,299],{"class":98,"line":287},4,[96,289,290],{"class":102},"}).",[96,292,293],{"class":234},"format",[96,295,238],{"class":102},[96,297,298],{"class":112},"10",[96,300,301],{"class":102},");\n",[96,303,305],{"class":98,"line":304},5,[96,306,308],{"emptyLinePlaceholder":307},true,"\n",[96,310,312,315,318,321],{"class":98,"line":311},6,[96,313,314],{"class":102},"console.",[96,316,317],{"class":234},"log",[96,319,320],{"class":102},"(price); ",[96,322,324],{"class":323},"shSDL","\u002F\u002F \"R$ 10,00\"\n",[96,326,328,330,332,335,338,340,343,345,348],{"class":98,"line":327},7,[96,329,314],{"class":102},[96,331,317],{"class":234},[96,333,334],{"class":102},"(price ",[96,336,337],{"class":106},"===",[96,339,261],{"class":241},[96,341,342],{"class":245},"R$ 10,00",[96,344,242],{"class":241},[96,346,347],{"class":102},"); ",[96,349,350],{"class":323},"\u002F\u002F false\n",[96,352,354,356,358,360,362,364,367,369,371],{"class":98,"line":353},8,[96,355,314],{"class":102},[96,357,317],{"class":234},[96,359,334],{"class":102},[96,361,337],{"class":106},[96,363,261],{"class":241},[96,365,366],{"class":245},"R$ 10,00",[96,368,242],{"class":241},[96,370,347],{"class":102},[96,372,373],{"class":323},"\u002F\u002F true\n",[16,375,376,377,380,381,384,385,388],{},"The text you typed in the test has a regular space. What ",[19,378,379],{},"Intl"," returns has a U+00A0. On screen they look identical, and the failure message shows the expected and received values as \"equal\". In French the thousands separator is another similar character, U+202F (narrow non-breaking space), so ",[19,382,383],{},"1 234 567,5"," formatted with ",[19,386,387],{},"fr-FR"," carries those characters.",[16,390,391],{},"There are two ways to fix it. One is to build the expected value with the right character, as above. The other is to normalize before comparing:",[87,393,395],{"className":209,"code":394,"language":211,"meta":92,"style":92},"const normalize = (text) => text.replace(\u002F[  ]\u002Fg, \" \");\n\nexpect(normalize(price)).toBe(\"R$ 10,00\");\n",[19,396,397,451,455],{"__ignoreMap":92},[96,398,399,401,404,407,410,414,417,420,423,426,428,432,435,438,440,443,445,447,449],{"class":98,"line":99},[96,400,218],{"class":106},[96,402,403],{"class":234}," normalize",[96,405,406],{"class":106}," =",[96,408,409],{"class":102}," (",[96,411,413],{"class":412},"sGEwX","text",[96,415,416],{"class":102},") ",[96,418,419],{"class":106},"=>",[96,421,422],{"class":102}," text.",[96,424,425],{"class":234},"replace",[96,427,238],{"class":102},[96,429,431],{"class":430},"s-doY","\u002F",[96,433,434],{"class":175},"[",[96,436,437],{"class":175},"  ]",[96,439,431],{"class":430},[96,441,442],{"class":106},"g",[96,444,60],{"class":102},[96,446,242],{"class":241},[96,448,261],{"class":241},[96,450,301],{"class":102},[96,452,453],{"class":98,"line":172},[96,454,308],{"emptyLinePlaceholder":307},[96,456,457,460,462,465,468,471,473,475,477,479],{"class":98,"line":188},[96,458,459],{"class":234},"expect",[96,461,238],{"class":102},[96,463,464],{"class":234},"normalize",[96,466,467],{"class":102},"(price)).",[96,469,470],{"class":234},"toBe",[96,472,238],{"class":102},[96,474,242],{"class":241},[96,476,342],{"class":245},[96,478,242],{"class":241},[96,480,301],{"class":102},[16,482,483,484,487,488,491,492,495,496,499,500,502],{},"UI tests hit the same wall: ",[19,485,486],{},"getByText(\"R$ 10,00\")"," does not find the element if the page text has a U+00A0. Two details help when debugging. ",[19,489,490],{},"String.prototype.trim()"," and the ",[19,493,494],{},"\\s"," in JavaScript regular expressions both treat U+00A0 as whitespace, so ",[19,497,498],{},"\" \".trim()"," returns an empty string. The ",[19,501,337],{}," operator does not make that equivalence.",[41,504,506],{"id":505},"how-to-write-the-character-in-each-place","How to write the character in each place",[508,509,510,523],"table",{},[511,512,513],"thead",{},[514,515,516,520],"tr",{},[517,518,519],"th",{},"Where",[517,521,522],{},"How to write it",[524,525,526,542,556,566],"tbody",{},[514,527,528,532],{},[529,530,531],"td",{},"HTML",[529,533,534,60,536,142,539],{},[19,535,21],{},[19,537,538],{},"&#160;",[19,540,541],{},"&#xA0;",[514,543,544,547],{},[529,545,546],{},"JavaScript",[529,548,549,552,553],{},[19,550,551],{},"\" \""," or ",[19,554,555],{},"\"\\xa0\"",[514,557,558,561],{},[529,559,560],{},"CSS",[529,562,563],{},[19,564,565],{},"content: \"\\a0\"",[514,567,568,571],{},[529,569,570],{},"JSON",[529,572,573],{},[19,574,551],{},[16,576,577,578,580,581,587,588,39],{},"In HTML, all three forms give the same result. ",[19,579,21],{}," is the only one with a name, defined in the ",[30,582,586],{"href":583,"rel":584},"https:\u002F\u002Fhtml.spec.whatwg.org\u002Fmultipage\u002Fnamed-characters.html",[585],"nofollow","WHATWG"," list of named character references. For other characters that cause errors in translation files, see also ",[30,589,591],{"href":590},"\u002Fen\u002Fblog\u002Fhow-to-add-special-characters-on-i18n","how to add special characters on i18n",[41,593,595,597],{"id":594},"nbsp-showing-up-as-text",[19,596,21],{}," showing up as text",[16,599,600,601,603,604,607,608,611,612,615,616,39],{},"If a person sees the text ",[19,602,21],{}," on the page instead of a space, the HTML was escaped twice. The ",[19,605,606],{},"&"," became ",[19,609,610],{},"&amp;",", and the browser shows the result literally: ",[19,613,614],{},"&amp;nbsp;"," renders as the text ",[19,617,21],{},[16,619,620,621,624,625,627,628,630,631,633],{},"This happens when an email, a CMS, or an API stores HTML that is already escaped and another layer escapes it again. The same goes for ",[19,622,623],{},"&quot;"," and ",[19,626,610],{}," showing up raw. The fix is to find the layer that escapes the second time and remove one of the two. Replacing ",[19,629,614],{}," with ",[19,632,21],{}," by hand only hides the problem.",[41,635,637],{"id":636},"other-spaces","Other spaces",[508,639,640,653],{},[511,641,642],{},[514,643,644,647,650],{},[517,645,646],{},"Entity or code",[517,648,649],{},"Character",[517,651,652],{},"What it does",[524,654,655,667,680,693,706,717],{},[514,656,657,661,664],{},[529,658,659],{},[19,660,21],{},[529,662,663],{},"U+00A0",[529,665,666],{},"non-breaking space, one space wide",[514,668,669,674,677],{},[529,670,671],{},[19,672,673],{},"&ensp;",[529,675,676],{},"U+2002",[529,678,679],{},"space as wide as an \"n\"",[514,681,682,687,690],{},[529,683,684],{},[19,685,686],{},"&emsp;",[529,688,689],{},"U+2003",[529,691,692],{},"space as wide as an \"m\"",[514,694,695,700,703],{},[529,696,697],{},[19,698,699],{},"&thinsp;",[529,701,702],{},"U+2009",[529,704,705],{},"thin space",[514,707,708,711,714],{},[529,709,710],{},"(no name)",[529,712,713],{},"U+202F",[529,715,716],{},"narrow non-breaking space",[514,718,719,724,727],{},[529,720,721],{},[19,722,723],{},"&#8203;",[529,725,726],{},"U+200B",[529,728,729],{},"zero-width space",[16,731,732,733,60,735,60,738,741,742,744,745,747,748,753],{},"The other codes, such as ",[19,734,610],{},[19,736,737],{},"&lt;",[19,739,740],{},"&gt;",", and ",[19,743,623],{},", are in the ",[30,746,33],{"href":32},". The MDN ",[30,749,752],{"href":750,"rel":751},"https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FGlossary\u002FCharacter_reference",[585],"Character reference glossary entry"," explains the concept.",[755,756,757],"style",{},"html pre.shiki code .sCdxs, html code.shiki .sCdxs{--shiki-default:#F8F8F2}html pre.shiki code .s0Tla, html code.shiki .s0Tla{--shiki-default:#FF79C6}html pre.shiki code .sIQBb, html code.shiki .sIQBb{--shiki-default:#BD93F9}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sY_PY, html code.shiki .sY_PY{--shiki-default:#50FA7B;--shiki-default-font-style:italic}html pre.shiki code .sLL85, html code.shiki .sLL85{--shiki-default:#8BE9FD}html pre.shiki code .sviCg, html code.shiki .sviCg{--shiki-default:#FF79C6;--shiki-default-font-weight:bold}html pre.shiki code .sAOxA, html code.shiki .sAOxA{--shiki-default:#50FA7B}html pre.shiki code .seVfx, html code.shiki .seVfx{--shiki-default:#E9F284}html pre.shiki code .s-mGx, html code.shiki .s-mGx{--shiki-default:#F1FA8C}html pre.shiki code .shSDL, html code.shiki .shSDL{--shiki-default:#6272A4}html pre.shiki code .sGEwX, html code.shiki .sGEwX{--shiki-default:#FFB86C;--shiki-default-font-style:italic}html pre.shiki code .s-doY, html code.shiki .s-doY{--shiki-default:#FF5555}",{"title":92,"searchDepth":172,"depth":172,"links":759},[760,762,763,764,765,767],{"id":43,"depth":172,"text":761},"When to use &nbsp;",{"id":131,"depth":172,"text":132},{"id":199,"depth":172,"text":200},{"id":505,"depth":172,"text":506},{"id":594,"depth":172,"text":766},"&nbsp; showing up as text",{"id":636,"depth":172,"text":637},[91],"Learn what nbsp means in HTML, when to use the non-breaking space, and why U+00A0 breaks string comparisons in tests, such as Intl.NumberFormat output in pt-BR.","what-does-nbsp-mean-in-html","md",{},"\u002Fen\u002Fblog\u002Fwhat-does-nbsp-mean-in-html","o-que-significa-nbsp-no-html","2026-11-22",{"title":6,"description":769},{"loc":773,"lastmod":775},"en\u002Fblog\u002Fwhat-does-nbsp-mean-in-html",708,"ppenlVn3gGY-PNJq6xSqj3Q_Wf86rFO-iAWKbyZKCug",1795359122194]