Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

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?

like image 780
Danny Avatar asked Mar 25 '11 09:03

Danny


People also ask

What is the HTML code for indentation?

Many developers choose to use 4-space or 2-space indentation. In HTML, each nested tag should be indented exactly once inside of its parent tag. Place a line break after every block element.

How many spaces indent HTML?

Indent by two spaces per indentation level. Use all-lowercase for elements and attributes. Don't leave trailing spaces at the end of a line (except as needed for Markdown).

What is the HTML code for tab space?

Adding Tab Space in HTML Unlike with HTML space, there is no particular HTML tab character you could use. You could technically use the 	 entity as the tab is character 9 in the ASCII. Unfortunately, HTML parsers will simply collapse it into a single space due to the whitespace collapse principle.

Should a tab be 2 or 4 spaces?

If you represent the indents using space characters (ASCII SP), then 2 spaces is 2 characters fewer than 4 spaces. If you allow TAB characters to be used, then (on Windows) a TAB indents by up to 4 spaces, so TAB characters result in fewer characters.


2 Answers

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.

like image 59
Jefferson Lima Avatar answered Sep 23 '22 05:09

Jefferson Lima


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.

like image 25
Brandon Rhodes Avatar answered Sep 26 '22 05:09

Brandon Rhodes