Should <head> and <body> tags be on a different level of indentation to <html>?
HTML does not care about indentation, it only requires proper nesting. It is parsed the same (except for whitespace text nodes of course), it does really not matter for correctness.
While proper indentation does matter for readability, many people choose not to indent <html>
, <head>
and <body>
tags as their structure is trivial, and only shifts the whole document rightwards unnecessarily. The contents of those tags should always be indented for clean markup, so that the nesting structure is clear to the reader.
To answer your question explicitly:
Should
<head>
and<body>
tags be on a different level of indentation to<html>
?
There is no need for that, as everybody knows they are nested in <html>
. You can do it if you want. Both
<html>
<head>
<title>…</title>
…
<head>
<body>
<div>
<div>…</div>
…
</div>
…
</body>
<html>
and
<html>
<head>
<title>…</title>
…
<head>
<body>
<div>
<div>…</div>
…
</div>
…
</body>
<html>
are fine, while the following is not:
<html>
<head>
<title>…</title>
…
<head>
<body>
<div>
<div>…</div> <!-- which nesting level ??? -->
…
</div>
…
</body>
<html>
It does not matter in functionality, but for the purpose of clean, readable and manageable code you should always indent child tags.