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?
As someone above said, indentation makes for clear readable code but not just, <head> and <body> are both children of <html> and thus should be indented to show this fact.
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.
Don't use tabs to indent text; use spaces only. Different text editors interpret tabs differently, and some Markdown features expect spaces and not tabs. Indent by two spaces per indentation level. Use all-lowercase for elements and attributes.
Formatting the Main Body There should be no extra spaces between the title and the beginning of your paper. The beginning of every paragraph should be indented by half an inch (just hit the "tab" key on your keyboard). There should be no extra spaces between paragraphs.
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 managable code you should always indent childs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With