views:

963

answers:

8

Why do I get the following message in Visual Studio when I use the <u> element?

"Element 'u' is considered outdated. A newer construct is recommended"

Has it aged?

+7  A: 

It's because the W3C decided to deprecated it.

It's because all layout and design should be done using CSS. In HTML ideally only structure should exist.

<u> only adds a specific font decoration to the text, but no structural information.

DR
I doubt vs cares about this, the fact it shows the warning is down to w3c rules
redsquare
Of course, but I think it'd be better to add a little explanation, instead of just saying "because it is" :)
DR
well better to answer the question and give a reason :)
redsquare
+8  A: 

Because according to w3c is has been depreciated. Read here Also any style/formatting should be the responsibility of css but I am sure VS follows the w3c guidelines.

redsquare
+4  A: 

The tag is deprecated along with other text formatting / style elements.

The 'in' thing to do is to use correct markup and apply styling with stylesheets.

Neil Aitken
+12  A: 

The underline tag has been deprecated as of HTML4.

http://www.w3.org/TR/html401/present/graphics.html#edef-U

The reason is that visual styling does not belong in tags, but should be moved to stylesheets.

You can use the text-decoration: underline style instead:

<span style="text-decoration: underline">some underlined text</span>

(Or use text-decoration:none to disable underlining.)

Joeri Sebrechts
See, this is exactly the sort of suggestion I object to. How on earth is <span style="text-decoration: underline">some underlined text</span> remotely better than <u>some underlined text</u>? The plain old tag does the exact same, only it's supported by more browsers, shorter, more maintainable, and more readable.
Coding With Style
There's nothing objectionable about the answer; it's just fact that the underline tag was deprecated in HTML 4. The question is "why does Visual Studio show this warning," not "why did the standardization committee make this decision."
Jacob
That's just what the question looks like. If you look through the question's history, you'll see the point of this question was originally mostly "What on earth is wrong with using <u></u> tags?" not "Why does Visual Studio give me an error for using this?" which is what it wound up looking like after 3 different people edited the author's question to remove the author's own opinion from it. Also, you didn't answer my original question where I listed out my objections to this suggestion.
Coding With Style
@Coding : It's worth mentioning that using inline styles is also considered, by some, to be bad style, therefore you wouldn't necessarily use the long version as above, but use something (slightly longer than `<u>`) like this: <em><strong>underlined</strong></em>, and your style-sheet would defined that those tags combined should be underlined.
anonymous coward
@Anonymous, you're right on that, but I still don't see where the benefit to this is. Simple formatting rules shouldn't require extroardinary logic when implemented imo. If it's a question of "how do I position this div, what font do I use on this text, which size, which background, which text color, etc." using a stylesheet is probably a good idea. But for "Do I bold X" or "Do I underline Y", etc. I think stylesheets can be overkill. I think it's pretty safe to assume in most cases that those, at least, will remain constants, so the stylesheet doesn't contribute anything.
Coding With Style
I believe the reasoning against the u tag went that a u tag has no semantic value. It may have the semantic value of emphasis, but for emphasis there are the em and strong tags. The reasoning is that if you want to use underlining for emphasis, you will redefine the styling of the em or strong tags.
Joeri Sebrechts
@Coding: The point isn't about which one is more easy, handy or efficient to do. The point is that it's a different way of thinking - semantic content separated from style. There are multitudes of reasons for this, but this isn't the place to discuss them. (Besides, I would expect of all people *coders* would be the ones to understand the issue!)
Ilari Kajaste
A: 

Formatting with HTML rather than CSS is considered deprecated these days. Anyhow, if you ever have issues with standards compliance rejecting your in-line formatting, follow the following easy search and replace rules:

<b></b> Replace with <span style=font-weight:bold></span>
<u></u> Replace with <span style=text-decoration:underline></span>
<i></i> Replace with <span style=text-font-style:italic></span>
<font face=font,otherfont size=number></font> Replace with <span style=font-family:font,otherfont;font-size:replace-with-keyword></span>
<s></s> aka <strike></strike> Replace with <span style=text-decoration:line-through></span>

Keywords for font-size: xx-small, x-small, small, medium, large, x-large, xx-large
Roughly the same.

If you will just follow through with these easy replacements, you will experience...!

  • All the joys of standards compliance! (Bragging rights.)
  • None of the benefits. (This CSS isn't going to get modified from a single <style>.)
  • All the pain of excessive standardization (Wait, which formatting rule does this </span> tag undo again? Shit.)
  • More bandwidth consumption! (The price of progress, as soon as someone clues me in on how this helped anything.)
  • Decreased browser support! (Y'know those folks who still use old browsers or minimalist browsers like LYNX, Links, w3m, OffByOne, etc.? Eh... who cares?)

Oh yeah...

Addendum: More seriously, because these days many standards purists just have a hard-on for pure CSS. Most of the support behind CSS obviating regular markup generates simply from it being modern so you should get with the times. Other support comes from the notion that CSS is inherently more maintainable and completely overlooks unmaintainable messes like what I suggested above.

It's not that I have anything against CSS. The point here is that a lot of people preach the standard excessively and will condone it even when it's used in wildly inappropriate ways. The notion of replacing regular HTML tags with inline formatted CSS as I mentioned is genuinely viewed as progress by far too many advocates of CSS. They seem to view upholding the standard, the pattern, the design rule, as being some kind of inherent good rather than rationally looking at it. Inline formatting has its place, and I think using regular HTML tags for it is fitting and much more readable.

Those adherents are like the folks who tell you gotos are evil and you should never, ever use them. The ones who will look at a regular stack-esque wind and unwind and instead use an indented if statement clusterfuck going ten layers of indentation and repeated code deep. And, they will genuinely view their version as more readable and maintainable even though by any sane standard it clearly isn't. For more on that tangent: http://kerneltrap.org/node/553/2131

Coding With Style
If you're going to downvote, explain why. If you'd at least voice your objections, I'd listen and respond peaceably. Making a quick down vote and running off is just dumb and rude.
Coding With Style
Someone is missing the point... these styles belong in the stylesheet, not in the "style" attribute. Replacing <u> with the style attribute doesn't help things a bit. However, replacing <u> with styles that are defined in a CSS file where they belong DOES improve things.
TM
Like it or not, HTML is moving toward holding meaning. CSS is for formatting and style. You can have a "ul" class. <span class="ul">I'm underlined.</span>. It's not quite as ugly as the alternatives.
Nosredna
You're missing the point, alright. "Replacing <u> with the style attribute doesn't help things a bit." <- That's my point. I thought I made this clear with my addendum. What I am stating is that there are times when you will want to use in-line formatting and these quick and dirty alternatives to regular HTML markup are a step backwards rather than a step forwards. You might gain standards compliance, but aside from that dubious accomplishment, everything just works worse now. The problem that I am pointing out is that religious pursuit of the standard will easily leave us worse off.
Coding With Style
Nosredna, even with a new CSS class to do it for you instead, how is that better? Will there ever be a time you will look at your underlined text and want to replace it with different formatting? I think underlining, bolding, italicizing tends to serve a very specific purpose you won't readily replace, and having a single class for underlining is in no way better than just using <u></u>. It still suffers from all the same problems, imo.
Coding With Style
I didn't say it was better. Just pointing out that if he really wants a way to say <ul> without tripping the deprecation warning, he can do it in a bit less ugly way. I wouldn't do it.
Nosredna
Oh I see. So, is there anything you have against my objections here? (I'm assuming you downvoted me, or was that someone else?) Oh, and by the way, <u> is the underline tag, <ul> is the unordered list (bullet points unless styled differently) tag. ;-)
Coding With Style
It was not me that downvoted. :-)
Nosredna
Damn. The ul was a typo. My brain wasn't watching my fingers.
Nosredna
In fact, I don't even know why people would down vote an opinion. I only down vote factually wrong answers.
Nosredna
"I only down vote factually wrong answers." <- Same here. Now about the ul, I think that was more of an inattentive slip than a typo... You did it three times. I just think it's funny.
Coding With Style
Haha. Yeah. I was on automatic. :-)
Nosredna
-1 for being obnoxious. Either change to conform to new standards and settle down, or continue doing things the way you want to and settle down. Either way, settle down.
Mike C.
+1  A: 

As others have said, <u> (and similar elements) have been deprecated in the latest versions of web standards because of a general belief that style and markup should be separated.

And, as others have said, you can make your HTML valid by using a span with inline styling. Really though, that's not any better. Is it valid? Yes. But it buys you nothing else over simply using <u> tags in the first place.

The best semantic solution depends on the context. Why are you trying to insert an underline in text? There are three use cases I can think of: headings, links, and text emphasis. In each case you should be applying css from a stylesheet to the relevant semantic element: <h1-6> for headings, <a> for links, and <em> for emphasized text. If you need variations of each, apply css classes and ids as necessary.

Sam DeFabbia-Kane
To me the most obvious use is to show inserted text, and that's covered by the <ins> tag.
Nosredna
A: 

<u> is part of a family of elements that were deprecated. <b> and <i> were replaced with <strong> and <em>, respectively, while requires using css for effect.

The reasoning is that HTML shouldn't decide that something is underlined or bolded, that type of information is supposed to be a part of the style, and thus is a perfect candidate for a stylesheet.

nilamo
A: 

Not just HTML4, <u> is considered obsolete in HTML5 too.

Interestingly, <b> and <i> are kept as conforming. You may try to argue in their mailing list, or just keep using the tag as you like before. Browsers won't pull out its support and you are fine.

I remember the reason behind the decision of pulling <u> out is about its lack of uniform semantic meaning or something like that. At least when you see bold text you know you should read it louder.

billyswong