Skip to content Skip to sidebar Skip to footer

Are Type Attributes On Script, Style, And Link Elements Still Needed?

You will see many sites with the following type of code: Script elements: Link elements:

in HTML4 and XHTML it's required by W3C standards.

For style and linktype:

In HTML5, the type attribute is no longer required. Default value is "text/css".

Solution 2:

Short answer

No, they aren't.

Long answer

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.

Solution 3:

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

Solution 4:

They are currently not required. Because all browsers assume the default that you would expect.

But they may become important in the future.

For example, when Google Dart becomes fully integrated in the browsers, and we then finally have an alternative to JavaScript. Similarly, once someone proposes a nice replacement for CSS, we will need this. And it may well be that Dart becomes "JavaScript 2.0". And the bastard language that JavaScript is surely needs a more sane replacement. I guess we are all only using it, because there is no alternative that works cross-browser (and in fact, not even one that works in a single browser, I guess ...).

So if you plan your site to live for a year: don't bother. If you plan to have the site running for 10 years, try to be verbose about your content types, formats and versions.

Post a Comment for "Are Type Attributes On Script, Style, And Link Elements Still Needed?"