What is the Indentation standard for HTML (Tab / Two spaces / etc)? [closed]

Many websites, with pre-generated HTML5-compliant boilerplate files, use two spaces. Visual Studio projects, such as ASP.NET MVC 3, default to using a tab.

Will one become the standard way of indenting HTML?


As nobody mentioned it, the Google HTML/CSS Style Guide and the W3School HTML(5) Style Guide recommend 2 spaces.

This article also brings an analysis of the effect of tabs vs spaces in the resulting file size.


Do not use tabs; use two spaces. Tabs are problematic because they can be a different width in different editors (and terminals, for that matter). Since whitespace is removed when you tidy your HTML before deployment, there is no ultimate bandwidth benefit to using tabs; they simply introduce a wildcard into your development experience.

Two spaces are emerging as the standard because they are “just enough” indentation to make the HTML clearly indented to most people's eyes, but because HTML tends to nest very deeply — much more deeply than one would commonly nest when programming — and anything more than two spaces tends to start pushing HTML off the right edge of an 80-column screen pretty quickly.


There is no standard but...
Use Tabs, it's what they're for.
Advantages: fewer bytes, the user can set their preferred display width.

Warning: tabs used within lines to align columns will potentially be miss-aligned if the tab width of the creator differs from that of the viewer, which is why I use spaces for aligning columns.

Edit I'm getting older, and I just don't care so much anymore. Although I still consider tabs superior in their advantages listed above. You should also consider: the simplest (spaces), or widest adoption (in your community, possibly wider than just your workplace), what works for you.


I don't think there's a W3C specified standard. Since HTML strips out excess whitespace anyway, you should go with whatever you're most comfortable with.


A space is a space, no more, nor less!

A tab is a sign to jump to the next column, but "next column" depends on the interpretation of the currently used editor/program.

To answer the OP question: NO, I don't see any standard emerging, because there are at least as many arguments, as there are opinions about:

  1. whether to use tab or spaces
  2. what the correct amount of spaces are (2,4,8, ...)

If you want explicit spacing use Space (or Tab-To-Space conversion)! If you don't care about implicit interpretation of the editors, use raw tabs.

IMHO: TAB-conversion reduces typing, but TABs in a file makes you a candidate in the Implicit-Interpretation-Lottery. Therefore I personally use spaces, never tabs!

My suggestion: Use an editor which interprets tabs depending on the context:

  • HTML: 2 spaces
  • C: 8 spaces (Torvald's preference)
  • Python: 4 spaces

So I personally concur with Mr. Rhodes' reasoning. Most editors provide an option for tab to space conversion, and I strongly suggest to use it.


4th edit, after revisiting a 3rd time, because of a down-vote and trying to improve the quality of my (opinionated) answer.