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
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.
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 arel
attribute or anitemprop
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...
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 thetype
attribute.
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.
精彩评论