Do not use #id selectors, because they are not reusable. Good enough reason.

However, there is a nice debate here.

. css IDs are like singletons (can have only one instance), hence not re-usable.
. IDs refers specific element. Abstracting is difficult.

Points against the statement:

. using IDs are fast. (poor point. the speed gain is low and negligible)

Read the comments for more fun. | Don’t use ID selectors in CSS | Screwlewse | Don’t use ID selectors in CSS | Screwlewse | Don’t use ID selectors in CSS Posted on: July 28, 2010 / Categories: UncategorizedLately I have been testing out performance among css styles and I found that some of my very smartfriends, started asking,”why aren’t you testing using IDs for the unique sections of the page?”.This wasn’t a hard answe...

tarek.jubaer's picture

It should not be a hard rule to use/not use any selectors. It totally depends on the pattern developer is comfortable with. But must be optimized and easy to maintain.

ron's picture

agree. not a hard rule..

While writing css, we will be beneficial if we practice the basic patterns we follow in code like
. not repeat code
. where necessary override css using inheritance

using id selector prevents re-using of code, so we shall avoid this when we have other options .. e.g.: adding two classes

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.