Why do we need to use 2-space indentations?

Question

If the spacing in our HTML documents doesn’t affect the positioning of content on the page, why do we need to use 2-space indentations?

Answer

Experienced developers use indentation and vertical spacing to keep their code neat and legible. Highly readable code improves maintainability, aides collaborative efforts and makes for a better developer experience overall.

Within our HTML, consistent indentation should be used to illustrate nesting. For more info, check out this chapter.

29 Likes

You don’t have to use 2 spaces HTML does not care about spacing outside of literals (e.g. quoted text). I particularly dislike spaces because it is not as adaptive as tab spacing. In fact, you can write the entirety of an html document on a single line (though if you do, look for your boss to fire you as soon as you turn it in as complete.) What you must do, is follow the style guide for the people for whom you are working (unless you want to be fired ). If your company says use two spaces, use two spaces. If they say use four spaces, use four spaces. If they tell you to use tab spacing, do it.

1 Like

Two spaces = One tab.