3 ms·
Never use IDs? Why? i'm open to this if you have a good argument but i use IDs for unique elements only.
by weallneedheroes 16y ago
Never use IDs? Why? i'm open to this if you have a good argument but i use IDs for unique elements only.
- evanrmurphy 16y agoThe problem is that as a site grows, it's common for things that were once unique to become multiple. Also, if you just resolve to always use classes instead of ids, then you can eliminate the cognitive overhead that comes with every new selector of, "Should this be a class or an id?".
- perlgeek 16y agoHow many of your pages have two footers? I do agree on the cognitive load though.
- TorbjornLunde 16y agoThe main reason is that including IDs makes “selector points” much more complex. A selected with one ID will outweigh a selector with two classes for instance. This can quickly lead to complexity because you need to use a ID many places in order to override a selector that used ID. A class only used once serves the same purpose as ID (CSS-wise), expect that you avoid a lot of problems. I might use IDs for anchor purposes (site.com/foo#section), but I never reference it in my CSS.