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?

Agnel Kurian
  • 57,975
  • 43
  • 146
  • 217
  • 2
    SO isn't the place for rants. I suggest you go find yourself a nice HTML forum to harass instead. – Welbog Jul 03 '09 at 11:24
  • Edited to remove the subjective and argumentative parts. – Welbog Jul 03 '09 at 11:26
  • 2
    It is still a valid question. Perhaps it should be along the lines of where does Visual Studio take its 'outdated' warnings from. – redsquare Jul 03 '09 at 11:27
  • It would be good to including the concrete wording of the warning/error message from Visual Studio in the question (I can't do it, I don't have VS installed). – Joachim Sauer Jul 03 '09 at 11:30
  • @Welbog, I wasn't harassing anyone. – Agnel Kurian Jul 03 '09 at 11:44
  • I've looked at the history. If I understand correctly, the purpose of this question isn't to ask "why does VS give me a warning about using the underline tag?" like it currently suggests, but rather "Why do people insist on phasing out these tags? What's wrong with using them?" – Coding With Style Jul 03 '09 at 20:41
  • You can create custom HTML (and CSS) validation with your own rules in VS. See link here http://stackoverflow.com/questions/1084194/ – Richard Jul 06 '09 at 09:28

10 Answers10

22

The underline tag has been deprecated as of HTML4. The W3C reference can be found here. The reason is that visual styling does not belong in tags, but should be moved to style-sheets.

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

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

To remove underline, use text-decoration:none to disable underlining.

Chait
  • 1,052
  • 2
  • 18
  • 30
Joeri Sebrechts
  • 11,012
  • 3
  • 35
  • 50
  • 4
    See, this is exactly the sort of suggestion I object to. How on earth is some underlined text remotely better than some underlined text? The plain old tag does the exact same, only it's supported by more browsers, shorter, more maintainable, and more readable. – Coding With Style Jul 03 '09 at 20:36
  • 3
    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 Jul 03 '09 at 22:28
  • 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 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 Jul 04 '09 at 00:01
  • 1
    @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 ``) like this: underlined, and your style-sheet would defined that those tags combined should be underlined. – anonymous coward Jul 04 '09 at 04:54
  • 1
    @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 Jul 04 '09 at 05:06
  • 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 Jul 04 '09 at 14:26
  • @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 Oct 13 '09 at 11:07
10

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.

Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329
8

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
  • 78,161
  • 20
  • 151
  • 159
4

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
  • 7,856
  • 3
  • 41
  • 40
1

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
  • 2,599
  • 17
  • 11
0

<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
  • 1,932
  • 13
  • 22
0

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
  • 1,114
  • 7
  • 12
0

there can be meaning that will be lost to some minor extent with CSS reference over the 'u' tag.

One minor but annoying result is the ACCESS key to input controls.

<u>F</u>irst Name <input ... AccessKey="f"..

OR

<span class="ul">F</span>irst Name

The first method, using a tag truly indicates a meaning where a random, user-assigned class name does not. TAGS are fixed - class-name is arbitrary.

As far as standards, it's a distinction without a difference. The decision is arbitrary, subjective and capricious, handed down from the supposed experts and purists.

davidWazy
  • 61
  • 6
0

As it says here:

It is possible to achieve a much richer variety of font effects using style sheets.

They have to split stuff into "HTML", "CSS" and "JS". I mean, imagine this: you're making a very basic web app and styling is made in partially HTML and partially CSS. In small codes that's a simplicity; but in spaghetti codes, like Google Translate's, it just makes things more complicated. So it's not made to make your job simpler, it's made to make multi-millionaire companies and people who make huge projects' jobs simpler.

But yeah, it would be better if they didn't deprecate it. We could have two options then and it will make stuff easier, btw.

-5

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
  • 1,692
  • 1
  • 14
  • 10
  • 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 Jul 03 '09 at 13:19
  • 1
    Someone is missing the point... these styles belong in the stylesheet, not in the "style" attribute. Replacing with the style attribute doesn't help things a bit. However, replacing with styles that are defined in a CSS file where they belong DOES improve things. – TM. Jul 04 '09 at 04:12
  • Like it or not, HTML is moving toward holding meaning. CSS is for formatting and style. You can have a "ul" class. I'm underlined.. It's not quite as ugly as the alternatives. – Nosredna Jul 04 '09 at 04:43
  • You're missing the point, alright. "Replacing 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 Jul 04 '09 at 04:43
  • 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 . It still suffers from all the same problems, imo. – Coding With Style Jul 04 '09 at 04:52
  • I didn't say it was better. Just pointing out that if he really wants a way to say
      without tripping the deprecation warning, he can do it in a bit less ugly way. I wouldn't do it.
    – Nosredna Jul 04 '09 at 05:03
  • 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, is the underline tag,
      is the unordered list (bullet points unless styled differently) tag. ;-)
    – Coding With Style Jul 04 '09 at 05:11
  • Damn. The ul was a typo. My brain wasn't watching my fingers. – Nosredna Jul 04 '09 at 05:20
  • In fact, I don't even know why people would down vote an opinion. I only down vote factually wrong answers. – Nosredna Jul 04 '09 at 05:22
  • "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 Jul 04 '09 at 07:22
  • Haha. Yeah. I was on automatic. :-) – Nosredna Jul 04 '09 at 18:15
  • 1
    -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 Cole Jul 31 '09 at 04:15