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 trialRobin McKenzie
212 PointsQuestion: Is tab spacing important when structuring your HTML?
Some of the tab sizes at the top of the HTML are 4 spaces, whereas in the rest of the file they are 2 spaces.
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsWhitespace in HTML doesn't actually matter and won't affect the outcome of the HTML. It would be a matter of preference to the designer and/or to the style guide being used by a group/company.
I find that many designers will use a combination of both 2 spaces and 4 spaces when writing HTML.
One common practice is to use 4 when indenting 'primary' tags (example: a <ul> being inside a <div>) and then use only 2 when indenting closely related tags (example: the <li> inside the <ul>. I don't know of any particular reason except it just seems to make sense when nesting certain tags.
So it may look like this, and that's okay:
<div>
<ul>
<li>
<li>
</ul>
</div>
As long as you are consistent and it looks need and orderly and is easy to read, there really is not a specific "rule" per say, as to how many to use because the editor doesn't recognize whitespace.
One thing to remember, however, is that many languages pay very close attention to whitespace and thus the indenting (especially Python). So, yes, then it is VERY important. HTML and CSS... not so much.
:)