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?
It's not required with the HTML5 spec, but for older versions of HTML is it required.
Html 4 W3.org spec
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.
It's not required, no.
The part of the HTML Living Standard you're interested in is The
link element, which states:
linkelement must have either a
relattribute or an
itempropattribute, but not both.
typeattribute 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
typeattribute is used as a hint to user agents...
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.
<a>'s definition for the
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.
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).
No it just stands for MIME type, it has been deprecated in HTML, We can drop using it without any browser compatibility.