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 HTML Objects Images

Myroslav Tkachenko
Myroslav Tkachenko
10,581 Points

Inline elements outside of block elements

Is it an appropriate or valid way to use inline elements like an 'img' outside of block elements, 'p' or 'div', like in this Nick's example? Thank you.

1 Answer

Michael Williams
Michael Williams
13,005 Points

Hi Myroslav Tkachenko,

It seems to be a preference among each developer. I have heard that when deciding to either wrap the img tag with a div tag or a p tag, think of the div tag for "divisions of content; or containers". The p tag can be thought of in the case that you are trying to say something to the visitor, the content is rather important. Regardless of the choice, they are both considered semantically correct.

The alternative in relations to Nick's "Images" video is to take the HTML a step further into the CSS:

img { display: block; }

or, if you want to have some images as inline and others as block, you could add a class to your HTML

<img class="block">

and then apply the style with your CSS

img.block { display: block; }

Regards, Michael

Myroslav Tkachenko
Myroslav Tkachenko
10,581 Points

Thanks for your reply! I tried several examples in W3C validator, it seems that putting an inline element such as 'img' outside of a block element was invalid in the strict variants of previous versions of the HTML standard. But in HTML5 it's perfectly valid now.