tags:

views:

426

answers:

10

Is use of underline deprecated and non validated?

+8  A: 

Yes, it's deprecated. Use styles instead. Note also that underlined text can be confusing, as it resembles links, and might frustrate some users.

.underline { text-decoration:underline }

<p>I like to <span class="underline">underline</span> words.</p>
Jonathan Sampson
but It takes more character than <u>
metal-gear-solid
@Jitrenda: This makes no sense :) First ask yourself why you need the underline? Just to *emphasize* text? If so, then you can also just grab `<em>` and use CSS to underline it by default.
BalusC
I would do what BalusC suggests, emphasize the text with em and then choose how it is emphasized with a stylesheet. Rather than have a style class called underline.
Robin Day
Replacing `<u>` with a class called "underline" is a step backwards. But I agree about confusing underlined text with links - IMO you shouldn't underline text at all on web pages apart from links or headings (in which case, you'd attach the CSS to a heading tag).
DisgruntledGoat
@DisgruntledGoat I'm not encouraging the example, only showing how CSS handles itself as the alternative to the dreadful **u**.
Jonathan Sampson
A: 

Deprecated: yes.
Validated: ? I guess that depends on what you are using to validate it.

http://www.codehelp.co.uk/html/deprecated.html

Chris Lively
A: 

Yes, it is deprecated.

DaDaDom
+4  A: 

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.

LBushkin
A: 

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.

Peter Rowell
A: 

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.

Joe Martinez
+17  A: 

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.

Jonny Haynes
This should be upvoted more.
BalusC
yey nothing like more code to write. Why would any logical person replace <u></u> with <span style="text-decoration:underline;></span>7 chars vs 47. Plain stupid. Im sticking with <u> even though I can't say I really ever use it.
corymathews
Because logical people use classes or css overrides over inline styles, and understand the significance of keeping the structure of the document separate from the formatting of the document.
Joel Mueller
A: 

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.

aslum
A: 

<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 exmample, 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>

Jay
The comment "natural, widely-recognized style" in regards to the "world" wide web doesn't really work. What happens when you make chinese text italic? The internet gives us global coverage, this is something you always need to consider unless you know exactly what your entire target audience is.
Robin Day
@Robin: Maybe I'm missing something, but I'm not aware of any way to just flip a switch and turn English text into Chinese. If someone translates a document I've written into Chinese, I presume they'll translate the italics into some corresponding Chinese method of indicating emphasis. If you're thinking of a Babelfish translation, (a) given the crudeness of machine translations, inadequate handling of italics is the least of your worries; and in any case (b) it would surely be easier to deal with standard <i> tags then a custom-designed CSS class.
Jay
+1  A: 

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;
}
The Elite Gentleman