You will see many sites with the following type of code:
Script elements:
<script type="text/javascript">
//javascript here
</script>
Link elements:
<link rel="stylesheet" href="url.css" type="text/css" media="all" />
Style elements:
<style type="text/css">
/* CSS */
</style>
My question is this:
Are the type
attributes needed in the popular browsers today?
(Popular meaning IE 8+, Firefox, Webkit, Opera and Chrome)
What happens if you do not include them?
Note: The answer needs to cover both HTML5 and XHTML doctypes if there is a difference in behavior between the two.
In short, they are not required since HTML5, but are required by W3C standards in HTML4/XHTML.
In HTML5 type
of script
tag:
type - This attribute identifies the scripting language of code embedded within a script element or referenced via the element’s src attribute. This is specified as a MIME type; examples of supported MIME types include text/javascript, text/ecmascript, application/javascript, and application/ecmascript. If this attribute is absent, the script is treated as JavaScript.
in HTML4 and XHTML it's required by W3C standards.
For style
and link
type
:
In HTML5, the type attribute is no longer required. Default value is "text/css".
No, they aren't.
For a long time, browser sets the default type=text/javascript
at script elements, ect. when you omitted the type
attribute. HTML5 makes this official, but every browser supported it long time ago.
In fact, which doctype you use isn't affecting the browsers behaviour, only the W3C specs. The nice and short HTML5 doctype is the standard doctype for years in normal browsers. HTML5 just makes those nice things official.
So you can use it and no browser will scream or fail, only the validator.
In Newer browsers (supporting HTML5) type attrib is optional and if not given it sctipt will understand default as text/javascript and style will understand as text/css
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With