Starting with CSS

Faruk Ateş provides a set of CSS rules to use as a starting point in Starting with CSS: revisited.

Why reset the margins and padding of specific element types instead of using the universal selector (*) to set everything to zero? Two reasons:

  1. Some browsers have default values for the margin and padding of form elements. Setting them to zero is not always a good idea.
  2. Since the universal selector matches every element in the document tree, it can slow things down.

Those are valid enough reasons, and I’ve started using a set of starting rules similar to those in Faruk’s example.

Posted on September 6, 2005 in CSS, Quicklinks

Comments

  1. Faruk and I had some interesting discussions about this while, and after, he put his article together.

    I’m all for it, but I’m also still interested in the actual slowing down effect the universal selector would have in a web browser. Are there any benchmark tests?

    Why I’m asking is since high-profile CSS gurus (people like Eric Meyer) use the universal selector, and they, if any, should be aware of all possible side effects.

  2. Noooo! The star selector has been the foundation of my CSS for some time! :)

    I also like to see some testing performed on the ‘slowing down effect’. I’d like to know whether or not the difference is negligible before I begin recoding. :)

  3. Stuart,

    Developers of browsers have said they can see a slow down, but so far, I don’t think anyone has made test cases of websites where there is a noticeable difference. However, there is still the form control element issue that you get from using * {}, as well as the fact that it’s just not Best Practice to do that in the first place :-)

Comments are disabled for this post (read why), but if you have spotted an error or have additional info that you think should be in this post, feel free to contact me.