I have always wondered but can't really find an answer anywhere if there are any set standards regarding indenting the body or head tag.
Is this version correct?
<html>
<head>
</head>
<body>
</body>
</html>
Or this one?
<html>
<head>
</head>
<body>
</body>
</html>
Whilst I appreciate that it probably doesn't make the slightest bit of difference as far as the functionality of the final website goes, we are all human beings, and all blessed with the gift / burden that is curiosity.
Are there any set standards or does it not matter?
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>