Is it O.K. to use the same name for a classname and an ID name? Is it a code smell?
<div class="wrapper" id="wrapper"></div>
Yes, it's valid to do it. It's not common to need to do it, though: it's a bit of a code smell. It may indicate you need to revisit your naming conventions.
To expand on the issue of naming conventions and semantics:
When you use an ID of wrapper
, you're saying "This is the wrapper - the only one of its kind". When you use a class of wrapper
you're saying "This is one of the wrappers, and there may be others like it". Saying both of those things at the same time is a bit weird, right?
I'd suggest that you use a specific ID: #primaryWrapper
, #outerWrapper
, etc. That means you're expressing 'primaryWrapper is one of the wrappers', which makes heaps more sense.
Yes, it's totally valid and you can do it
Hopefully you know that#ID
must be unique-per-page, while.CLASS
can be assignet to more than one element.
If you incline to write clean and readable HTML
markup, try always to keep your attributes at an understandable minimum.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With