Why does the universal selector * have a negative impact on browser rendering?

Asked

Viewed 180 times

1

I was just applying a CSS Reset to my website. I usually use the one suggested by Eric Meyer http://meyerweb.com/eric/tools/css/reset/ . But I was looking at Diego’s suggestion http://tableless.com.br/css-reset/ that is so :

* {
margin:0;
padding:0;
list-style:none;
vertical-align:baseline;
}

I found it cool, simpler (of course Eric Meyer’s is more complete.)

I was testing on my Visual Studio Express 2013 for Web, and Web Essentials fired a warning saying :

Performance : Never use the universal selector. It has a big Negative performance Impact on browsers Rendering.

Translating :

Performance : Never use the universal dial. This has a great negative performance impact on browser rendering.

Why the universal dial * causes this negative impact on the rendering of browsers?

2 answers

4


The concept that the universal dial is slow is a myth coined ten years ago when, in fact, there were performance problems, nothing surprisingly, because of Internet Explorer 6.

Nowadays, in modern browsers the performance impact of the universal dial is insignificant as long as you do not define rules that result in slower effects on it.

Unlike the reference article, personally, I would not define CSS3 effects on the universal selector. Not only because I vehemently doubt that ALL elements would REALLY need that particular effect, but also because I am in favour of reusable generic classes present in frameworks CSS such as Bootstrap.

Source: Article on Telerik’s Blog through an answer in the Soen

2

The main argument against the universal selector was not so much performance, but the impact it caused on property inheritance.

In practice, neither loss of performance nor inheritance problems were ever relevant enough to abolish the use, because it was much faster and more practical to use it and make a few specific definitions afterwards, including adopting sheets of styles specific to the late IE6, which was already obsolete when the use of CSS2 gained strength and table-based layouts began to go into disuse.

A model I always adopted, recently upgraded to Html5, was:

* {
  margin:0;
  padding:0;
 /* outros estilos com base no projeto */ 
}

div, article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
  display: block;
}

a, a:link, a:visited, a:hover, a:active { 
  text-decoration:none; 
  font:inherit; 
}

li {
  list-style-type:none;
}

Because, again, in practice, you always need to define the styles according to the project, each one specifically, and in the reset enter only the elements that can really mess or repeat a lot in the creation.

  • I don’t know, huh. When CSS3 showed up, it had a website, I don’t remember which one, did a type of browser benchmark to see what effects it supported and how fast they were processed. Hence it is logical: if an effect is too heavy for a dial, if applied to the universal the thing gets ugly.

  • 1

    @Brunoaugusto, the last test I saw was 2009, and I don’t believe it’s gotten any worse. At the time the impact was considered insignificant for all major browsers, mainly taking into account the cost aspect of development, suggesting more attention to the application of certain particularly heavy rules (not the selector) and your interactions with javascript. Along with CSS3, there has also been a lot of evolution in browser technology. In time, I just found this link from 2012: http://blogs.telerik.com/kendoui/posts/12-09-28/css_tip_star_selector_not_that_bad

  • Anything older than this? The original article I used in the translation mentions 10 years. How was the thing in 2004 or earlier?

  • 1

    Until 2004, precisely, when it began to avenge the idea of web standards, good practices, tableless, flash is evil thing, etc... Nobody cared about that. Layout was with tables, sliced images, and period. Good site had to have flash with at least 10MB (by the time the average download was 256kbits/second) and animations for everything that is side. The most CSS was used to change the link color or hide miles of keywords for Google to find.

  • Quite interesting :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.