+ 3

Why do people use &nbsp

It's possible just to use a space instead of &nbsp, so why do people use it?

22nd Dec 2017, 10:13 PM
Piday 3.14159 265358
Piday 3.14159 265358 - avatar
7 Respuestas
+ 10
If I am not mistaken, nbsp stands for non breakable space, so you need to use them in places where you want to put space, but do not want to let line brakes in case of different formating. So if you do move&nbspthis and your line will be to short to held "this", whole move&nbspthis will be moved to the next line.
22nd Dec 2017, 10:23 PM
Dima Makieiev
Dima Makieiev - avatar
+ 9
To assure it won't break the line, no matter what. That is why it is called a "|n|on-|b|reaking |sp|ace"
22nd Dec 2017, 10:22 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
That said... it is recommended to avoid using this HTML Entity where CSS can be used instead.
22nd Dec 2017, 10:57 PM
David Carroll
David Carroll - avatar
+ 5
@Piday: Browsers will ignore multiple subsequent spaces showing only a single space where 10 spaces might have been placed. Specifying 10 [ ] - non-breaking space HTML Entities - will preserve those 10 spaces when rendering the in the browser.
22nd Dec 2017, 10:52 PM
David Carroll
David Carroll - avatar
+ 3
Also people have been misusing it to put spaces where they couldn't otherwise. In HTML you are constantly indenting code with spaces, like <div> <p> <span></span> </p> </div> So HTML has to ignore all those spaces, otherwise they would end up on the page. &nbsp; will show no matter what.
22nd Dec 2017, 10:47 PM
Schindlabua
Schindlabua - avatar
+ 3
in html &nbsp; is to add a space that doesn't collapse with multiple spaces/tabs/enters in html. note the trailing semicolon! so to add two spaces it's &nbsp;&nbsp; and so on
23rd Dec 2017, 12:36 AM
Lisa F
Lisa F - avatar
+ 1
Makes sense
22nd Dec 2017, 10:24 PM
Piday 3.14159 265358
Piday 3.14159 265358 - avatar