This page is a work in progress.You can help improve it. →

Whitespace in HTML

In the above examples, you may have noticed that a lot of whitespace is included in the code listings — this is not necessary at all; the two following code snippets are equivalent:

<p>Dogs are silly.</p>
<p>Dogs are silly.</p>

No matter how much whitespace you use (which can include space characters but also line breaks), the HTML parser reduces each one down to a single space when rendering the code. So why use so much whitespace? The answer is readability — it is much easier to understand what is going on in your code if you have it nicely formatted and not just bunched up together in a big mess. In our HTML, we've got each nested element indented by two spaces more than the one it's sitting inside. It is up to you what style of formatting you use (how many spaces for each level of indentation, for example), but you should consider formatting it.


© 2017 - 2022; Built with ♥ in St. Petersburg, Florida.