Is use of <u>underline</u> deprecated and non validated? [closed]
Is use of underline deprecated and non validated?
It's deprecated in HTML 4 http://www.w3.org/TR/REC-html40/present/graphics.html#edef-U so won't validate.
Use styles instead. Maybe a <span>
tag. Although, if you want the thing you're trying to add an underline to, to be emphasized without styles enabled. Use an <em>
tag and use CSS to give it an underline.
Yes, it's deprecated. Use styles instead. Note also that underlined text can be confusing, as it resembles the default styling of links, and might frustrate some users.
If you wanted, you could even repurpose another HTML element, like em
:
CSS:
em {
font-style: normal; /* Removes italics */
text-decoration: underline; /* Makes underline */
}
HTML:
<p>I like to <em>underline</em> words.</p>
<rant>
General comment on "semantics versus style": While there is certainly truth to this, it is a lesson that some people have way way overlearned.
In real life, many people use italics for emphasis. Sure, I could create a CSS style of "span.emphasized { font-style: italic;}", and then instead of putting "<i></i>" around the emphasized text, put "<span class='emphasized'></span>". And exactly what does that gain, besides a lot of extra typing?
Further, there are a million reasons why I might want to put a piece of text in, say, italics. Perhaps it is the title of a book; perhaps I want to emphasize it; perhaps I am using the convention of italicizing foreign words; etc. If I have 10 words in a document that are italicized for 9 different reasons, the pedantic answer is that I should create 9 different CSS style entries to describe all these reasons. Personally, I almost never do this, because it gains nothing. Yes, theoretically I might decide that book titles should be in a cursive font instead of italicized or some such. In practice, the probability that this will happen is pretty close to zero, and if it did, and I have two such book titles in my document, I can just change it twice. Theoretically someone might want to scan my text with a program that looks for book titles. But in practice, unless we have arranged this in advance and we have agreed on the CSS class names, there is no way they are going to do this.
I'm not saying CSS is useless. Quite the contrary. When I have a semantic object that is repeated many times in my text, and which has no "natural", widely-recognized style, it then becomes quite plausible to suppose that as I continue to work on the document I may want to change the style. In that case it is much easier to change a single CSS entry than to change a hundred instances. Or I may want to use a different style in different situations, like put warning messages in red when displaying on the screen but put them in bold when printing a black-and-white document.
For example, I routinely use CSS for quote citations because I often change my mind about italicizing, indenting, and font size. I never use CSS for text that I want italicized for emphasis because I know it is extremely unlikely that I will ever want to render this as anything other than italics.
My point is, I don't care that some pedant said "This is a rule that you must always obey. You ask why you must obey it? But I just told you! Because it's a rule!" I use tools and techniques that are useful in the present application. (And yes, yes, there are lots of rules of thumb that are valid 99% of the time and aren't worth thinking about until the rare exception turns up.)
</rant>
The <u>
tag has been deprecated in favor of stylesheets.
Most browsers will continue to recognize it for a long time to come, simply out of need to be backwards compatible with the content already out there. But if you want to by XHTML compliant, you should avoid using it.,
You can read some more about deprecated HTML tags here.
Yes, it was deprecated in HTML 4. However, you can just use the following css.
span.underline { text-decoration: underline; }
However, the underline class name is not semantic. You may want to replace it with a class name that describes the content you need underlined.
The tag is deprecated but not obsolete. The reason it's not obsolete is to allow browsers to support the element for backward compatibility.
The tag is not defined in the xhtml1-strict.dtd but it's available under xhtml1-frameset.dtd and xhtml1-transitional.dtd. It's declaration are as follows (not on Strict DTD):
<!ELEMENT u %Inline;> <!-- underline -->
<!ATTLIST u %attrs;>
This is to allow backward compatibility with browsers.
Do not use the tag as "This tag has been deprecated in favor of style sheets". It may soon become obsolete. Rather use stylesheet, e.g.
/** Underlining an anchor tag in CSS **/
a {
text-decoration: underline;
}
Deprecated: yes.
Validated: ? I guess that depends on what you are using to validate it.
http://www.codehelp.co.uk/html/deprecated.html
Yes, it is deprecated.
You tagged your question with both XHTML and HTML. the U tag is definitely deprecated in xhtml-strict. I think it may still be OK in HTML-4-Transitional. As other people have said, use styles instead. With good name they give more semantics to your docs.
If you're using the latest version of HTML or XHTML then yes it's deprecated. Regardless, in general you want to avoid underlining anything that isn't a link, as it can make things more confusing for the user.
精彩评论