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
Matt Varner
5,373 PointsDo ID selectors have the same use prohibition in Codepen that it's supposed to have in a "real HTML" environment?
I'm watching the video for Class and ID Selectors with Guil Hernandez, and he says "So an element can only have one ID and a page can only have one element with the same ID name." The expected behavior (unless I'm misunderstanding) is that if you've used the ID...
<div id="main-content">
...at some point in the markup and you've put something in your CSS to style that ID element...
#main-content { yadda (yadda); yadda; }
...then if you were to use that ID again elsewhere in the markup, some kind of fail behavior would be observable...like only the last element with that specific ID gets the styling.
This particular lesson series has no attendant Treehouse Workspace environment, so I was following the link to the Codepen "Code Playground" where the project code can be saved, forked or whatever...and then toyed with. So, I toyed with it to observe the behavior.
In addition to the included ID "main-content" in an existing HTML DIV element, I changed a class in the existing footer to read as the same ID and then changed the color value for that ID element to red, saved it and...<sad trombone="on">.
Both the DIV element and the footer element change values according to what's in the "CSS" portion of the code. And I suspect but need confirmation that this is due to Codepen being a web app and not (I'm just guessing here) a bona fide, actual HTML environment.
The behavior that I observe seems exactly as if it were a class element with an attribute that can be shared wherever in the markup...and I want to make sure that this is a special case error...and to trust that the info about ID and class selectors really is that they are different in 'real-world' scenarios...for lack of a better phrase.
I'll keep the code in my Forked version the same for this question, in perpetuity, at http://codepen.io/RavingNoah/pen/mAwyl
2 Answers
Marko Koron
20,658 PointsThe thing is that CSS doesn't cares about multiple IDs, but this doesn't mean that you should do it, Such code is not valid by the W3C standards. Also have in mind about the headaches if you were using multiple IDs and the Javascript getElementById() method.
If you don't "trust" Codepen as a web app you can always code your HTML pages in a plane text editor an check it in a browser of your choice ;).
Philip G
14,601 PointsMatt Varner
5,373 PointsUsing the experimental HTML5 validation checker. Thanks for the screenshot. :)

Matt Varner
5,373 PointsMatt Varner
5,373 PointsOkay, I went ahead and made a couple of pages in a folder and opened it up in Chrome and it indeed looks exactly the same in the webpage as it does in CodePen. :) Thanks for the suggestion.
So, CSS doesn't care...there won't be obviously simple fail behavior, but it's against the W3C standard and will produce problems for you at greater levels of complexity later on if you choose to not heed the rule. :) Got it.