Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
dxt
16,505 PointsLoading html elements with a bunch of classes
I do understand the necessity of DRY standards for CSS and for any programming practice for that matter. I just tend to imagine much larger websites having an html element loaded with a bunch of different classes.
Not that I mind when it comes to DRY standards, but is there any downside for an html element to have many classes?
dxt
16,505 PointsThanks Kathryn! I meant this post to refer to a specific course in practicing DRY concept to CSS. Of course, the instruction is based solely for that purpose, and I should have kept that in mind when asking this, heh. It seemed weird to me at first, but I figure something would have to be inherently wrong in styling or html if too many classes were being applied. Fortunately, I learned in a later course of using more specialized selectors. Thanks again for the response!
2 Answers
Steven Parker
243,656 Points
Multiple classes, within reason, are not a problem.
But if the number of classes becomes unwieldy, it's probably a sign that the styling and/or HTML layout strategy needs rethinking.
With proper usage of semantic elements, it should not require very many classes to achieve effective styling.
dxt
16,505 PointsThank you. I appreciate the response.
Kathryn Notson
25,941 PointsDavid Kossow:
You're welcome.
Kathryn Notson
25,941 PointsKathryn Notson
25,941 PointsDavid Kossow:
The idea behind DRY - "Don't Repeat Yourself" is to use as little code as possible. How many classes do you need to use for one HTML element? Adding classes to an HTML element for the sake of adding classes without using them in your code would not be practicing DRY.