Is type="text/css" necessary in a <link> tag?

HtmlCssStylesheet

Html Problem Overview


I was wondering whether or not it is necessary to use <link rel="stylesheet" type="text/css" href=...> over <link rel="stylesheet" href=...>. The rel="stylesheet" marks the information that it is a stylesheet - so text/css doesn't actually add anything as far as I'm concerned.

The only stylesheet format used by HTML is CSS anyway, so what does text/css 'say' to the browser? Some websites seem to add the type="text/css" attribute (http://www.jquery.com/), whilst other ones don't (http://www.youtube.com/).

So, what is the use of type="text/css" in a <link rel="stylesheet"> element, and is it necessary to include it?

Html Solutions


Solution 1 - Html

It's not required with the HTML5 spec, but for older versions of HTML is it required.

Html 4 W3.org spec

http://www.w3.org/TR/html40/struct/links.html#edef-LINK http://www.w3.org/TR/html40/present/styles.html

Type stands for The MIME type of the style sheet. The only supported value I have ever seen is Text/CSS, which is probably why HTML5 has dropped it. I imagine they had it for earlier versions to allow future expansion possibilities which never happened.

Using HTML5 and not specifying the type, I have run so far into no problems with compatibility even when testing older versions of IE.

Solution 2 - Html

It's not required, no.

The part of the HTML Living Standard you're interested in is The link element, which states:

> A link element must have either a rel attribute or an itemprop attribute, but not both. > > The type attribute gives the MIME type of the linked resource. It is purely advisory. The value must be a valid MIME type string. > > For external resource links, the type attribute is used as a hint to user agents...

Solution 3 - Html

HTML4.01 does not require the type attribute on a <link> tag. According to the specification, the type attribute is a hint to the browser. If the browser does not support the hinted content type, then it can skip fetching it.

> type = content-type [CI] > >> This attribute gives an advisory hint as to the content type of the content available at the link target address. It allows user agents to opt to use a fallback mechanism rather than fetch the content if they are advised that they will get content in a content type they do not support. >> >> Authors who use this attribute take responsibility to manage the risk that it may become inconsistent with the content available at the link target address.

  • NOTE: <link> defers to <a>'s definition for the type attribute.

Solution 4 - Html

My understanding is that it's to allow the specification of stylesheets in formats other than text/css.

While that has become the dominant (and standard) delivery format for stylesheets for (X)HTML documents, the specification is actually wide enough to allow a variety of different MIME types to be passed, it's just that standard browsers don't implement them.

Solution 5 - Html

Not relevant to most people, but some systems (at least Microsoft SharePoint 2013) will use this type attribute when working out how to process HTML (e.g. when creating a .master page file).

Solution 6 - Html

No it just stands for MIME type, it has been deprecated in HTML, We can drop using it without any browser compatibility.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpimvdbView Question on Stackoverflow
Solution 1 - HtmlTom GullenView Answer on Stackoverflow
Solution 2 - HtmlalexmullerView Answer on Stackoverflow
Solution 3 - HtmlUyghur Lives MatterView Answer on Stackoverflow
Solution 4 - HtmlGShenaniganView Answer on Stackoverflow
Solution 5 - HtmlDavid GilbertsonView Answer on Stackoverflow
Solution 6 - Htmlprasen sinhaView Answer on Stackoverflow