5

I have read several results of a Google search, such as this nice question: Is type="text/css" necessary in a <link> tag?. However, I am currently going through some css3 (it's not that new) code and I see text/css everywhere.

Has something changed, or this is just an old habit that we (the young people) should not inherit?

Community
  • 1
  • 1
gsamaras
  • 71,951
  • 46
  • 188
  • 305
  • 3
    A downvote for what? Please explain, since I could not find any **recent** answer to my question. – gsamaras Dec 07 '15 at 21:46
  • I have no data on why specific people are doing this, but I would guess that it's a combination of a lot of IDEs and examples still having this, and ignorance of the fact that it's no longer necessary. – Two-Bit Alchemist Dec 07 '15 at 21:47
  • Exactly. Just look how long `language="JavaScript"` took to disappear! – Adrian Lynch Dec 07 '15 at 21:48
  • @Two-BitAlchemist then in that case, IMHO, it would be nice to have an 2015 resource that say, no, there is no need to use it! Adrian, I am too young probably. And I am still confused after Danny's answer.... – gsamaras Dec 07 '15 at 21:50
  • 1
    Voting to close. While I like the idea of the discussion here, the fact that answers and comments are beginning with things like _"I have no data on why specific people are doing this, but I would guess..."_, _"then in that case, IMHO..."_ and _"Once I got a client with a strange frontend error..."_ seem to signal that this question is speculative and likely to attract opinion based answers as oppose to factual based answers. – War10ck Dec 07 '15 at 21:58
  • @War10ck I see your point, I will accept an answer now so that the question stops taking views. – gsamaras Dec 07 '15 at 22:00
  • @gsamaras No worries. I apologize as I'm not trying to be a downer. I, in fact, I like the question a lot. I just wish there were a better platform for discussing questions like this that don't fit the _"Q&A"_ style. – War10ck Dec 07 '15 at 22:02
  • No need to @War10ck, I really understand the logic behind the close votes, but *not* the downvotes. – gsamaras Dec 07 '15 at 22:03

5 Answers5

6

Nothing changed, it is used for backward compability and will probably appear more rarely with time, as more installed browser will support HTML5.

Wiertek
  • 368
  • 1
  • 8
3

text/css is NOT required in HTML5, however the WC3 spec does mention it so it is advised to be used on any CSS import statement. They will work without as the spec defines the proper behavior in the absence of the "text/css" - but I would not depend on all older (or future) browsers handling the missing property the same way. As such, it is just good practice to include it.

Korgrue
  • 3,430
  • 1
  • 13
  • 20
  • Are you sure? The other answer seems to disagree on the W3C case. – gsamaras Dec 07 '15 at 21:51
  • I am positive. In HTML5 it is purely advisory (as in not required), but older browsers may not render HTML5 to spec - and they may change the spec in the future - so I personally recommend including it on imports. In HTML5 capable browsers, leaving it out should not make any difference (assuming the developers of the client followed the advisory spec). So, no - its not required, but it is a good idea to include it to help ensure backward and forward compatibility. – Korgrue Dec 07 '15 at 21:57
  • I see Danny, thank you very much, you deserve an upvote. – gsamaras Dec 07 '15 at 21:57
  • Name just one browser of any vintage that supports CSS but requires `type="text/css"` on a link element before it will fetch and/or apply the CSS of the specified resource. – Alohci Dec 07 '15 at 22:53
  • Older versions of IE http://blogs.msdn.com/b/ie/archive/2010/10/26/mime-handling-changes-in-internet-explorer.aspx "In the October Cumulative update, a change was made to CSS handling in IE6, IE7, and IE8 to block all cross-origin stylesheets unless they have been delivered with the proper HTTP response header: " – Korgrue Dec 07 '15 at 23:03
  • @DannyGibas that only talks about Content-Type sent by server, nothing about `type` attribute on the tag (and in the attack vector mentioned there the site containing `` is the malicious one so checking that wouldn't help). – Beni Cherniavsky-Paskin Dec 09 '15 at 16:16
2

If you refer to this question, it seems that the HTML5 spec says that this attribute is advisory (it says, that a look here).

The type attribute gives the MIME type of the linked resource. It is purely advisory. The value must be a valid MIME type.

For external resource links, the type attribute is used as a hint to user agents so that they can avoid fetching resources they do not support. If the attribute is present, then the user agent must assume that the resource is of the given type (even if that is not a valid MIME type, e.g. the empty string). If the attribute is omitted, but the external resource link type has a default type defined, then the user agent must assume that the resource is of that type. [...] If the attribute is omitted, and the external resource link type does not have a default type defined, but the user agent would obtain the resource if the type was known and supported, then the user agent should obtain the resource under the assumption that it will be supported.

So you can specify it, but it is not mandatory.

Community
  • 1
  • 1
Cyrille
  • 1,078
  • 1
  • 10
  • 24
  • Yeah I have seen the question(s), but they are old, +1 for linking to the ref, but I would advice you to please quote the relevant part of that in your answer. – gsamaras Dec 07 '15 at 21:53
  • 1
    Thanks for the advice, I just did it. – Cyrille Dec 07 '15 at 22:13
2

Once I got a client with a strange Frontend error. At the end he got a proxy (I really don't know how that thing worked) which didn't allow resources without text/css.

Was in 2014 in a big company.

Maybe it was unique, didn't encountered the same issue ever again!

gsamaras
  • 71,951
  • 46
  • 188
  • 305
Anditthas
  • 531
  • 1
  • 3
  • 11
  • That sounds like a real world example, very interesting, +1. – gsamaras Dec 07 '15 at 21:52
  • That sounds different. That's a likely from a content filter. It's requiring the CSS resource is served with a `text/css` mime type, not that a `type="text/css"`attribute is required on the link element. – Alohci Dec 07 '15 at 22:59
  • Maybe, but the type="text/css" fixed the problem – Anditthas Dec 08 '15 at 06:02
2

"Has something changed, or this is just an old habit that we (the young people) should not inherit?" - Yes don't use it.
From html 4 type is not required in a <link>, it was something was put in there for a possible future functionality that never comes. Like a new way to style elements that's why you should explicit text/css.
But as I said you shouldn't use it because it's useless.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
eskeli
  • 21
  • 1
  • 4