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

CSS CSS Basics (2014) Basic Selectors ID Selectors

Can I create an ID within a Div element that has an ID?

What would happen if I created an ID within a div element that has an ID?

For example

<div id = primary-content> <h1>Heading<h/1> <p id = paragraph-one>Paragraph</p> </div>

Will any issues arise from creating the paragraph ID within the div element that has an ID?

Thanks in advance!

2 Answers

Hey Kane,

Yes, you can create an ID within a Div element that has an ID.

ID's are unique, therefore, each element can have only one ID and each page can have only one element with that ID.

<div id = primary-content> 
<h1>Heading</h1> 
<p id = paragraph-one>Paragraph</p> 
</div>

The example you provided, there will be no issues. You can style the paragraph by selecting #paragraph-one. But classes would be the better option as they are not unique and you can use the same class on multiple elements.

Hi Kane, Yes, you can create another id in your div element but the name of the id should be different, that is each element must have unique id name.