Say I was to write a stylesheet within the HTML document. I know that ever since HTML5 the type
attribute is not necessary as text/css
has become a default (and only possible) value:
<style type='text/css'></style>
Thus specifying a MIME type is not required but is there any case in which I should specify it?
Also is there a difference between specifying it for the <link>
or <style>
tag?
<link rel='stylesheet' type='text/css' href='typography.css'>
Technically, it would work either ways but can I omit it in the <link>
tag just the way I can in <style>
except in the case when the href
attribute is set?
In pre HTML5 versions you need to specify it. That is the case, otherwise if you're having an API that would require it, then is the case to specify them. Otherwise since HTML5 you're not asked to always specify them.
Specify them or not, its valid in HTML5.
No, a style tag is a tag defined for the Styles of the document. So, Browser would know that you're having styles here. Whereas a link is element defined to link an external source to your document. It can be style and can be a script (JavaScript code).
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
According to the above document,
The HTML Link Element (
<link>
) specifies relationships between the current document and external resource.
So, to specify you need to declare the MIME type for the resource that you'd link to the current document.