If you’ve spent any time at all coding a basic HTML page with CSS, you’ll have seen the text line that includes an external stylesheet.
It usually looks something like this:
<link type="text/css" media="all" href="http://mywebsite.com/css/styles.css" rel="stylesheet" />
How you ever noticed the bit that says type=”text/css” and wondered what it does? The rel=”stylesheet” portion already indicates that this is a link to a stylesheet – so text/css doesn’t seem to add much, right?
You might have thought to yourself maybe it’s something to do with MIME types, maybe it’s more of a informative comment sort of thing, or maybe it’s not even used at all anymore.
Well it turns out, all three of those are sort of the case.
Type Attribute Purely Advisory
According to the official HTML5 spec, the type attribute is “purely advisory”. In HTML 4, the type attribute is required for both Script and Style.
Actually, though, default value for the type attribute, used when the attribute is absent, is “text/css” anyway. So you don’t need it, because it was always the default value. It’s just that now it is explicitly optional.
Internet media types (formerly known as MIME type, for Multipurpose Internet Mail Extension), basically serve the same function on the Internet that file extensions do in your operating system, like Microsoft Windows or OSX. These media types have two parts: a type and a subtype, separated by a slash (/).
The Internet Assigned Numbers Authority (IANA) lists 72 subtypes of text media type.
So, bottom line, how can you tell when you need type=”text/css” or not?
For new web pages conforming to HTML5 requirements, it is not needed. For strict HTML 4, leave it in. My take is that it doesn’t hurt to leave it in either way, and who knows, at some point in the future it could once again be required.