<u>: The Unarticulated Annotation (Underline) element - HTML: HyperText Markup Language 编辑

The HTML Unarticulated Annotation element (<u>) represents a span of inline text which should be rendered in a way that indicates that it has a non-textual annotation. This is rendered by default as a simple solid underline, but may be altered using CSS.

This element used to be called the "Underline" element in older versions of HTML, and is still sometimes misused in this way. To underline text, you should instead apply a style that includes the CSS text-decoration property set to underline.

See the Usage notes section for further details on when it's appropriate to use <u> and when it isn't.

Content categoriesFlow content, phrasing content, palpable content.
Permitted contentPhrasing content.
Tag omissionNone, both the starting and ending tag are mandatory.
Permitted parentsAny element that accepts phrasing content.
Implicit ARIA roleNo corresponding role
Permitted ARIA rolesAny
DOM interfaceHTMLElement

Attributes

This element only includes the global attributes.

Usage notes

Along with other pure styling elements, the original HTML Underline (<u>) element was deprecated in HTML 4; however, <u> was restored in HTML 5 with a new, semantic, meaning: to mark text as having some form of non-textual annotation applied.

Be careful to avoid using the <u> element with its default styling (of underlined text) in such a way as to be confused with a hyperlink, which is also underlined by default.

Use cases

Valid use cases for the <u> element include annotating spelling errors, applying a proper name mark to denote proper names in Chinese text, and other forms of annotation.

You should not use <u> to underline text for presentation purposes, or to denote titles of books.

Other elements to consider using

In most cases, you should use an element other than <u>, such as:

  • <em> to denote stress emphasis
  • <b> to draw attention to text
  • <mark> to mark key words or phrases
  • <strong> to indicate that text has strong importance
  • <cite> to mark the titles of books or other publications
  • <i> to denote technical terms, transliterations, thoughts, or names of vessels in Western texts

To provide textual annotations (as opposed to the non-textual annotations created with <u>), use the <ruby> element.

To apply an underlined appearance without any semantic meaning, use the text-decoration property's value underline.

Examples

Indicating a spelling error

This example uses the <u> element and some CSS to display a paragraph which includes a misspelled error, with the error indicated in the red wavy underline style which is fairly commonly used for this purpose.

HTML

<p>This paragraph includes a <u class="spelling">wrnogly</u>
spelled word.</p>

In the HTML, we see the use of <u> with a class, spelling, which is used to indicate the misspelling of the word "wrongly".

CSS

u.spelling {
  text-decoration: red wavy underline;
}

This CSS indicates that when the <u> element is styled with the class spelling, it should have a red wavy underline underneath its text. This is a common styling for spelling errors. Another common style can be presented using red dashed underline.

Result

The result should be familiar to anyone who has used any of the more popular word processors available today.

Avoiding <u>

Most of the time, you actually don't want to use <u>. Here are some examples that show what you should do instead in several cases.

Non-semantic underlines

To underline text without implying any semantic meaning, use a <span> element with the text-decoration property set to "underline", as shown below.

HTML
<span class="underline">Today's Special</span>
<br>
Chicken Noodle Soup With Carrots
CSS
.underline {
  text-decoration: underline;
}
Result

Presenting a book title

Book titles should be presented using the <cite> element instead of <u> or even <i>.

HTML
<p>The class read <cite>Moby Dick</cite> in the first term.</p>
Result with default style

Note that the default styling for the <cite> element renders the text in italics. You can, if you wish, override that using CSS:

cite {
  font-style: normal;
  text-decoration: underline;
}
Result with custom style

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of '<u>' in that specification.
Living Standard
HTML5
The definition of '<u>' in that specification.
Recommendation
HTML 4.01 Specification
The definition of '<b>' in that specification.
Recommendation

Browser compatibility

BCD tables only load in the browser

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:102 次

字数:12113

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文