Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML indenting and readability [closed]

Tags:

People also ask

Does HTML care about indents?

Spacing and indentation should be consistent throughout your code. 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.

Is HTML indent sensitive?

No. HTML code does not need to be indented, and all browsers and search engines ignore indentation and extra spacing. However, for any human reader, it's a good idea to indent your text because it makes the code easier to scan and read.

Why do we indent HTML tags?

Indentation is extremely helpful for a few reasons: Helps us understand what elements are inside other elements. Helps us see validation errors more clearly. Helps maintain our code because it'll be more obvious if we haven't look at it in a while.


In all our projects we have a strict policy of indenting all HTML, XML, etc. to match nesting depth; but recently a question has arisen: Should <head> and <body> in HTML be indented to match nesting depth?

Essentially, it is a question of

<html>
<head>
  <title>...</title>
</head>
<body>
  ...
</body>
</html>

vs.

<html>
  <head>
    <title>...</title>
  </head>
  <body>
    ...
  </body>
</html>

I've seen both around the 'net, but which one should be considered to be the most proper?