Siva
Siva

Reputation: 123

HTML entitites - alternative to &nbsp?

I am a beginner with HTML (coming from a C background) and I came across the concept of HTML entities. I have some very basic questions regarding &nbsp.

  1. How does &nbsp entity introduce a non-breaking space within an element ?

  2. Is there any alternative to using the &nbsp entity in HTML ?

My internet searches have not given the answer I was looking for and some direction on these would be most appreciated.

Upvotes: 10

Views: 47172

Answers (2)

isherwood
isherwood

Reputation: 61063

  1. &nbsp is simply a reference to a [particular] space character [see comments]. It renders in the font specified for its location.

  2. Sure. The space character. Or you can split the element and apply padding or margin via CSS.

Upvotes: 4

Aaron Digulla
Aaron Digulla

Reputation: 328594

  is an alias for   or &xa0;. This character is defined as "non-breaking space" in the HTML standard. So someone said "browser must treat this is a space but not break a line" in a standard and all people who created Web browsers adhered to this standard.

If your editor supports it, you can also type this character. The browser doesn't care how it was created, only that it sees the byte 0xa0 in the input stream.

As an alternative, you can use various CSS styles and tricks to create lengths of text that won't break (for example with the style white-space: nowrap (see here) or by using padding / margins.

Related:

Upvotes: 11

Related Questions