Supported by :   My Law Forms Ltd. - Deed polls and Tenancy Agreements

XHTML Formatting – closing tags

Close those elements

When you’re creating valid xHTML you’ll need to make sure that you always close your elements properly. When your element has some data in it make sure you add an end tag directly after your data. Consider the following examples:
<p>This paragraph is perfect</p>
<p>This paragraph is hideous

The first paragraph is properly closed but the second paragraph has omitted the end tag.

There are a couple elements, however, that have to be closed in a special way. These elements do not have any data associated with them and are considered empty, namely the line break, horizontal rule, and image elements.

Don’t do this:

<img src=“cow.jpg” alt=“A picture of a cow”>

Do this instead

<img src=“cow.jpg” alt=“A picture of a cow” />

And you will need to include that space at the end as well-seriously; it is part of the specification.

Here is how the other two elements would look:

<br />
<hr />

This entry was posted on Sunday, January 7th, 2007 at 5:44 pm and is filed under XHTML tips. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.