5 ms·
Reason to USE ID's: 1-ID's are the fastest CSS selector. 2-ID's are the fastest Xpath Selector. 3-ID's are the fastest JQuery selector. 4-ID's make your fro
by ericb 15y ago
Reason to USE ID's:
1-ID's are the fastest CSS selector.
2-ID's are the fastest Xpath Selector.
3-ID's are the fastest JQuery selector.
4-ID's make your front-end test-able.
Without ID's, functional, integration, regression, and even load testing are many orders of magnitude more difficult. If you are worldly enough to be offering best practice advice, I assume you or your organization tests at some point in your process?
- csswizardry 15y agoPoints 2, 3 and 4 are irrelevant here. Do not use IDs in CSS. Use them in markup and JS and tests, sure, just not in CSS. Point 1: The speed difference between a class and an ID is so, so slight that it's almost non-existent. The specificity difference between a class and an ID is massive.
- brawley 15y agoblather all you want, but the consensus here is IDs, when properly used, enable speed and specificity. you don't get to tell us what's best practice.
- talmand 15y agoAh yes, the almighty consensus has spoken. Dare not disagree or we shall smite you.
- lazerwalker 15y agoIf a given ID element is uniquely styled (a very common use case), it seems backwards to me to explicitly give it a class so that you can select it by class instead of by the ID that already exists.