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

What is the difference between the div tag and the span tag?

Just curious what's the difference if I'm not mistaken span is used to style it later on. But im not too sure what's the difference and both their uses. When would i used either or?

2 Answers

Hi Haki,

The way you structure your code is purely based upon your discretion. Your company may have guidelines that ask you to do things a certain way but this is something that will come naturally in time.

By default, div tags are block level elements and span tags are inline block elements so it all depends on the design and what you are trying to achieve.

Hope this helps, Shaun

Thank you for responding, So the difference is one is block level and the other is inline correct?

From a CSS point of view yes. From a HTML point of view, I wouldn't use a span tag as a container/wrapper element. For that, I would use a div. I would most often use a span tag if I wanted to style a small piece of text inside a p tag like so....

<div class="container">
     <p class="paragraph">This is a paragraph I created <span class="paragraph__span">earlier</span></p>
</div>

I see now, thank you for the help!