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

HTML

XHTML Question

My new work placement uses XHTML, one question I do have...

Why do img tags need to be surrounded by p, h1, h2 tags ect?

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,254 Points

As far as I'm aware, they don;t have to be surrounded to be valid code, but it can be useful to do some, when selecting your elements with CSS. :)

It may be because img is a in-line element and not a block element. Although it is an in-line block element. It doesn't really matter in html; but xhtml has it's own bizarre oddities :P

As far as I remember, all in-line elements must be in block elements for valid xhtml.