HTML5 Doctor » u http://html5doctor.com helping you implement HTML5 today Tue, 17 Mar 2015 16:12:06 +0000 en-US hourly 1 http://wordpress.org/?v=3.9.1 The return of the u element https://stevefaulkner.github.io/html5doctored/u-element/ https://stevefaulkner.github.io/html5doctored/u-element/#comments Tue, 25 Oct 2011 14:00:37 +0000 http://html5doctor.com/?p=3862 The <u> element was deprecated in HTML 4 and non-conforming in HTML5, but a couple of use cases have seen it return from the dead. Are the use cases enough to persuade you that it’s a phoenix not a zombie?

]]>
Presentational elements like <i>, <b>, <small> and <hr> have been redefined in HTML5 with semantic meanings, or, in a couple of cases, made non-conforming. The <u> element had been in the non-conforming camp, but a couple of semantic use cases led it back into the fold. While most of us will never need it (and some will jeer), on the odd occasion, it might be just the element you need.

Before HTML5, <u> was solely for applying a presentational style of underlining to text. HTML 4 discouraged “font-style” or presentational elements, and even deprecated <u>, advising us to use CSS instead. Even before this, <u> was frowned upon as underlines are the browser default for links, and making normal text look like links gives users a bad case of clicky-clicky frustration. <u> was initially non-conforming in HTML5.

There are, however, a couple of non-link places where text is traditionally underlined to convey meaning, as the HTML5 specification’s definition mentions:

The u element represents a span of text with an unarticulated, though explicitly rendered, non-textual annotation, such as labeling the text as being a proper name in Chinese text (a Chinese proper name mark), or labeling the text as being misspelt.

Before we get to them, let’s quickly cover an unarticulated, though explicitly rendered, non-textual annotation. This means <u> is for when you are annotating something, but not explicitly saying what it is (WHATWG IRC, Ian Hickson) — the annotation’s meaning is implied by context.

Chinese proper name marks

And what exactly are those you ask? I had to ask Wikipedia myself:

In Chinese writing, a proper name mark (Simplified Chinese: 专名号, zhuānmínghào; Traditional Chinese: 專名號) is an underline used to mark proper names, such as the names of people, places, dynasties, organizations. … This method of recognizing proper names in text is similar to the English use of a capital letter.

Wikipedia gives the following example, which I’ve formatted using <u>:

<u class="pnm">屈原</u>放逐,乃賦<cite class="bnm">離騒</cite>。<u class="pnm">左丘</u>失明,厥有<cite class="bnm">國語</cite>。(司馬遷 《<cite>報任安書</cite>》)

屈原放逐,乃賦離騒。左丘失明,厥有國語。(司馬遷 《報任安書》)

Qu Yuan was exiled, and thus composed the Li Sao. Zuo Qiu lost his sight, hence there is the Guo Yu. (Sima Qian, “Letter to Ren'an”)

Using <u> for Chinese proper name marks where appropriate

If you’re using Firefox 6+ you’ll also see the appropriate wavy underline for a Chinese book name mark on the quote’s source, courtesy of CSS3’s text-decoration-style: wavy;. I’ve used <cite> for book name marks as it’s more appropriate than <u>. You can find out more about wavy in CSS Text Level 3.

Using <u> for spell-checking feedback

While you’re probably not marking up classical Chinese prose, a more familiar use case is for a spell-checker to indicate incorrect text. The default formatting in word processors is typically a red underline for spelling errors, and a green underline for grammatical errors:

.spelling-error {
  text-decoration: none;
  border-bottom: 1px dashed red;
}
.grammatical-error {
  text-decoration: none;
  border-bottom: 1px dashed green;
}
<p>hello doctor i am having a huge body <u class="spelling-error">oder</u> <u class="grammatical-error">it is smell really bad</u></p>

hello doctor i am having a huge body oder it is smell really bad

Using <u> for annotating spell checker feedback

While we’ve turned off the default text-decoration style, <u> will back us up if CSS is disabled, and potentially provide more information for assistive technology. After all, if it’s semantic it should be in HTML, not CSS.

Some word processors use wavy underlines. This CSS would have the same effect in a supporting browser:

.spelling-error {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: red;
}
.grammatical-error {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: green;
}

Or, using text-decoration as a shorthand property, and adding a default declaration for non-supporting browsers:

.spelling-error {
  text-decoration: underline; /* for backwards compatibility */
  text-decoration: underline wavy red;
}
.grammatical-error {
  text-decoration: underline; /* for backwards compatibility */
  text-decoration: underline wavy green;
}

Again, you can read more about the upgraded text-decoration properties in CSS Text Level 3.

Using <u> for indicating family names

Another use for <u> is to annotate a family name when this might be confusing — Chinese, Japanese, Korean and Vietnamese (among others) all traditionally write names in a different order than the western-centric “given-name family-name”. While applying a blanket western ordering is fairly common (especially when publishing in English), it’s good form to use culturally appropriate ordering. If the audience might misunderstand, the family name can be underlined, capitalised, or otherwise annotated to make the name order explicit. For example, the CIA’s World Fact Book capitalises the family name:

After World War II, the Communists under MAO Zedong established an autocratic socialist system …

This ties in nicely with the hCard microformat, as the “implied n optimisation” doesn’t work with these non-western ordered names, and we need a wrapper element to indicate each part of the name anyhow.

<style>
  .family-name {text-decoration: underline;}
</style>
<p>
  <span class="vcard" lang="ja-latn">
    <span class="fn n">
      <u class="family-name">Son</u> <span class="given-name">Goku</span>
    </span>
  </span>
   is the main protagonist in 
  <span class="vcard" lang="ja-latn">
    <span class="fn n">
      <span class="given-name">Akira</span> <u class="family-name">Toriyama</u>
    </span>
  </span>’s <i lang="ja-latn">manga</i> “Dragon Ball”.
</p>

Son Goku is the main protagonist in Akira Toriyama’s manga “Dragon Ball”.

Using <u> to indicate the family name in non-western names via underlining

Of course you can then change the style via CSS, for example

.family-name {
  text-decoration: none;
  text-transform: uppercase;
}

Son Goku is the main protagonist in Akira Toriyama’s manga “Dragon Ball”.

Using <u> to indicate the family name in non-western names via capitalisation

The benefit of using <u> for this is the family name will be indicated even when CSS is disabled, ensuring the annotation isn’t lost. Assistive technology may also be able to inform the user of this in the future.

But do we need <u>?

A lot of people bitten by the web standardista bug have somewhat of an allergic reaction to ex-presentational elements in HTML5, after influential articles like Tantek Çelik’s “<b>ed and <br>eakfast markup”. Given <u>’s ignoble past, I expect the reaction to its return will also lead to some poo-pooing. As we already mentioned, however, if it imparts meaning, it should be in HTML. These use cases involve semantic meaning, and even without assistive technology support, <u> conveys some meaning to sighted users via the browser-default style text-decoration: underline;.

Regardless of whether an element is deprecated (HTML 4, XHTML 1) or non-conforming (HTML5) or just plain uncool, browser makers still have to support it for backward compatibility with all those awesome web pages from the days when <blink> was hawt. Because of this, if there’s a semantic use case for an ex-presentational element, it’s definitely better to reform it rather than minting a new element with no backward compatibility. You might think <mark> sounds pretty similar, but the default browser styling would be completely wrong for proper name marks, and semantically less appropriate for spelling errors too.

As Ian Hickson explains:

The presentational markup that was <u>, <i>, <b>, <font>, <small>, etc, is gone. However, there are certain use cases that did not yet have elements yet were important enough to warrant us supporting them. By reusing existing elements, we are able to support them without having to wait for new elements to be implemented. By doing so in a way that closely matches how those elements were actually used in practice (at least to the same extent as other elements have been correctly used in practice) we can not only have older UAs support these new elements automatically, but we can do so in a way that does not introduce an undue volume of invalid pages.

Conclusion

Given the potential to confuse underlined text with links, using text-decoration: underline; on anything other than <a> is bad pretty much all the time. Generally <u> is not the element you’re looking for, even for Chinese book name marks (<cite> would be more appropriate). However, for at least these three use cases, it’s good to have a semantic option, something better than <span>.

So…in a hypothetical world where you did need to code for one of these situations, would you use <u> or something else like <span>? Let us know in the comments!

The return of the u element originally appeared on HTML5 Doctor on October 25, 2011.

]]>
https://stevefaulkner.github.io/html5doctored/u-element/feed/ 36