Is type = "text / css" required for the <link> element?
I am trying to use Google Web Fonts, and on the official website, he recommends using the <link> , including type , as shown below:
<link href='http://fonts.googleapis.com/css?family=Ubuntu:400,700' rel='stylesheet' type='text/css'>` In the official website of the HTML5 template, they skip the type attribute
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,700"> According to this rather old answer , in HTML5 the type attribute is not required for the <style> and is required for the <link> .
However, a version without the type attribute is validated against the W3C validator .
So, is the type attribute mandatory or not?
I found the answer on the official W3C HTML5 project :
The type attribute indicates the MIME type of the associated resource. This is purely advisory . The value must be a valid MIME type.
For external resource references, the type attribute is used as a hint to user agents so that they can avoid getting resources that they do not support. If the attribute is present, then the user agent must accept that the resource is of the given type (even if it is not a valid MIME type, for example, an empty string). If the attribute is omitted, but the link type of the external resource has a default type, then the user agent must assume that the resource is of this type. (...)
User agents should not consider the attribute type authoritative - on the selection of the resource, user agents should not use the type attribute to determine its actual type. Only the actual type (...).
The type of link in the style sheet defines the rules for processing metadata resources of the content type. (...)
If the document contains links to stylish strings denoted as follows:
<link rel="stylesheet" href="A" type="text/plain"> <link rel="stylesheet" href="B" type="text/css"> <link rel="stylesheet" href="C">... then a compatible UA that only supported CSS stylesheets, extract the B and C files and skip the A file (because / plain text is not a MIME type for CSS stylesheets).
For files B and C, it will check the actual types returned by the server. For those sent as text / css, it will apply styles, but for those marked as text / plain or any other type, it will not.
If one of the two files was returned without Content-Type metadata, or with a syntactically incorrect type of type Content-Type: "null", then the default type is for references to stylesheets. the default is text / css, the stylesheet will be nonetheless attached.
For the <style> attribute, the same document states:
The type attribute gives the style language. If an attribute is present, its value must be a valid MIME type that denotes a language style. The charset parameter is not specified. The default value is for the type attribute, which is used if the attribute is missing "text / css". [RFC2318]