Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS

Ingrid Bardales
Ingrid Bardales
10,616 Points

Divs w/o <p> vs. Divs w/ <p>

Are there advantages to setting up a Div without a <p> element versus a Div with a <p> element? I'm a newbie so if what i am about to say is completely off someone please steer me in the right direction. I would think not because you can always use the selectors such as :nth-of-type to style the text inside the div, also it's one less element that server would have to download. Sorry if this is a rudimentary question but it's been bugging me.

thanks for all the great help in advance!

3 Answers

Kevin Korte
Kevin Korte
28,110 Points

The answer has more to do with semantics. Whether there should or should not be a <p> tag inside a div depends.

Divs are meaningless, unsystematic holders of stuff. They are a division, or a chunk, of something. <p> or paragraph tags are quite semantic. They signify the end or begin of a paragraph.

So if your div contains copy that is in paragraphs, than yes, you should have paragraph tags inside of it. If you don't have paragraphs inside the div, than no.

As far as browser speed goes, you'd have to have an incredibly massive file, or series of files coming together for there to be any sort of measurable or noticeable speed increase with browsers rendering a few more tags here and there. Browsers are quite good at what they do today.

I prefer to use the html tags and then manipulate them instead of using too many selectors, but i think that depends on the coder, but i really don't know witch is better hah.

Sorry bad english, not my native language.

Ingrid Bardales
Ingrid Bardales
10,616 Points

Thanks guys for clearing this up for me!