Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the <nobr> deprecated?

Tags:

html

I understand that this tag could easily be replaced with <span class="nowrap"> and a little bit of CSS, but in real life markup I often find that <nobr> tag is more appropriate. It's not about style, it's about content. <nobr>V. V. Putin</nobr> for example (in russian typography last name and first name shouldn't be line breaked, I think similar rules apply to other languages).

I guess that deprecation means there's something better but I don't see how styling is better than separate tag. Of course there are places where CSS should be used. Do I miss something?

like image 843
vbezhenar Avatar asked Feb 15 '15 22:02

vbezhenar


People also ask

What can I use instead of NOBR?

You can use the CSS white-space property instead of the <nobr> element and achieve the same result.

What is the use of NOBR tag?

The <nobr> HTML element prevents the text it contains from automatically wrapping across multiple lines, potentially resulting in the user having to scroll horizontally to see the entire width of the text.


3 Answers

It isn't deprecated because it was never standard in the first place.

HTML is (in theory) a semantic markup language. It describes the structure and semantics of a document along with relationships to other resources.

HTML is not supposed to describe presentation. A bunch of presentational features were added during the browser wars. Some of these became standardised. Most of them were subsequently deprecated when CSS came along.

CSS is a language for describing presentation. When you have a chunk of text that shouldn't have a line break in it, that is usually a matter of presentation so CSS is the right place to do it.

The exceptions are usually handled by non-breaking spaces (&nbsp;).

like image 133
Quentin Avatar answered Oct 24 '22 09:10

Quentin


You may use the obsolete/non-standard <nobr> HTML tag — if you define it in CSS.

It's virtually guaranteed that this element name will never be repurposed for any task other than its original behavior, and this name is descriptive of the action you'll define in CSS, making it intuitive for people reviewing your HTML.

⚠Warning: Custom/obsolete elements will make your code fail to validate as strict HTML.

Your CSS will need to look like this:

nobr  {  white-space: nowrap;  hyphens: none;  }

This defines the white-space as nowrap, which suppresses line breaks within white space and the hyphens as none, which prevents breaking within words (including ignoring characters within words that "suggest line break points").

You may or may not want (or need) the hyphens: none; part, but I have added it for completeness since it appears some implementations of <nobr> (used to?) also suppress hyphenation while white-space: nowrap; does not do that.

like image 28
Adam Katz Avatar answered Oct 24 '22 10:10

Adam Katz


Foolishness. That's the only reason.

<nobr> is universally supported, because it is needed, to convey the fact that the enclosed content is semantically a single unit, so it should not be split across multiple lines.

like image 9
Dave Burton Avatar answered Oct 24 '22 10:10

Dave Burton