Avoiding unnecessary space in HTML code

As you try to help yourself to make your code more readable, you may start using space where it is not needed. Remember browsers ignore any extra space you may have in your code. That does not mean you should use extra space when it is not needed, however. There are two areas where the use of space should be avoided:

  1. space between the tag name and brackets
  2. space between the tag name and the text it affects
Space between the tag name and brackets

There should be no space between a tag name and its angle brackets. (This page explains when to use space inside the brackets when you are using attributes.) As an example, avoid:

Avoiding space between tag brackets
Avoiding space between tag brackets

There is no reason to use space between a tag name and the angle brackets. So the title tag above should be rewritten as:

<title>My page</title>

Space between the tag name and the text it affects

Space should also be avoided when you use a tag that affects some text (or some other web object):

The code shown above should instead be rewritten as:

<p>This is a <a href="paragraph.asp">paragraph</a> text.</p>