Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a performance cost for not declaring the "type" attribute in the <style> tag?

Tags:

The type attribute in the <style> element identifies the type of media being used.

If the type attribute is not declared, it defaults to text/css.

Is there a performance cost (however small) for not declaring type="text/css" in the <style> element?

like image 573
Jonathan Laliberte Avatar asked Sep 21 '17 20:09

Jonathan Laliberte


People also ask

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.

What is the value of type attribute in the style tag?

The type attribute specifies the Internet media type (formerly known as MIME type) of the <style> tag. 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.

What is the use of type attribute in HTML?

The HTML type Attribute is used to specify the type of button for <button> elements. It is also used in the <input> element to specify the type of input to display. For embed elements like link, object, script, source, and style used to specify the Internet Media Type.


2 Answers

From MDN Style docs on the type attribute:

This attribute is optional and defaults to text/css if it's missing.

Since it defaults to the correct one, there is no impact.

like image 88
m.spyratos Avatar answered Sep 30 '22 16:09

m.spyratos


You might as well ask if there is a performance cost for making an HTTP request in the first place. It is impossible to completely eliminate the notion of performance itself. At some point you're either at 100% performance efficiency for your page, standards compliant or not. The complimentary aspect to performance is standards in this case. Another example would be entrepreneurialism and execution. All the great ideas in the world are utterly useless unless you can execute to make said business fit into an economic model that works in the real world.

Now it is possible to make great leaps in performance. Back in the 80s and 90s, you could either buy a cheap Honda (non-standards here) or you could improve performance (Porsche, Ferrari or McLaren). Then Tesla came along and completely blew away even the best in acceleration. Disclaimer: I really don't care about cars but it's an easy analogy for most to comprehend.

As someone who has left very few rocks untouched, I can attest to you personally that eventually, it is not you though your environment in which performance increases should be sought. So while I commend you for trying to think outside the box I would make other considerations as to where to improve performance.

  • Be wary of too much utilization of the * selector.
  • Avoid CSS animation of box-shadow except on ::after and ::before pseudo-elements.
  • Be aware of which selector/rules aren't used.
  • Be aware to use a single compiled stylesheet for an entire domain you should have very well-honed CSS skills.
  • Avoid CSS class puking (class attributes on frigin everything).
  • Avoid CSS position absolute and fixed on moderate or minor layout aspects; reserve for only major layout elements.
  • Minify your CSS when and wherever possible.
  • Reduce the number of HTTP requests.
  • Use third-party tools like Yahoo's YSlow and Google PageSpeed Insights for further insight.
like image 26
John Avatar answered Sep 30 '22 17:09

John