Common Errors in XHTML

Correct examples are shown in larger type; incorrect examples are shown in normal size type.

Opening Tags

Both opening tags and closing tags need a < (less than) and a > (greater than) symbol.

<p> text </p> correct
<p text /> wrong
<p text /p> wrong

Closing Tags

For elements that have content, the / comes first in the closing tag.

<p> text </p> correct
<p> text <p/> slash in wrong place

For empty elements–elements that do not have content, the / comes just before the >, and you write the beginning and ending tag all wrapped up into one. The empty elements you have learned so far are <hr/> and <br/>.

<br/> correct
</br> slash in wrong place
<br> text </br> can’t have content in this element

Attributes

Attributes go inside the opening tag, and never in the closing tag.

<p align="right"> text </p> correct
<p> align="right" text </p> attribute outside tag
<p align="right"> text </p align="right"> attribute in closing tag

Styles

Styles are specified inside the style attribute. The style property and property value are separated by a colon, not an equal sign.

<p style="color:red"> text </p> correct
<p color="red"> text </p> no style attribute
<p style="color=red"> text </p> equal sign instead of colon

If you have more than one property to set, both properties go inside one style attribute, separated by semicolons.

<p style="color:red; font-size:12pt"> text </p> correct
<p style="color:red" style="font-size:12pt"> text </p> two style attributes
<p style="color:red font-size:12pt"> text </p> no semicolon