Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 607
pimvdb Avatar asked Sep 25 '22 19:09

pimvdb


People also ask

In which type of CSS do we use link tag?

The <link> tag defines the relationship between the current document and an external resource. The <link> tag is most often used to link to external style sheets or to add a favicon to your website. The <link> element is an empty element, it contains attributes only.

What does type text CSS do?

The type attribute identifies the content between the <style> and </style> tags. The default value is "text/css", which indicates that the content is CSS.

Does style tag need type?

The type attribute applied to the style tag has only one acceptable value: text/css . In theory, other types of styling could also be used between style tags–thus the need for a type attribute.


1 Answers

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.

like image 168
Tom Gullen Avatar answered Oct 18 '22 19:10

Tom Gullen