(X)HTML syntax

See also:

Tag Lingo

<p align="right">A right-justified sentence.</p>
 

Nesting tags

There are tags that require a closing tag (e.g. <i> ) and others that don't (e.g. <br> ). For those that require closing tags, any tag set should only ever enclose other complete tagsets. You can use the "crossed lines" test to see if tags are correctly nested:

correct
properly nested tags
wrong
improperly nested tags




HTML syntax

We're living in the age of HTML 4.01, though the W3C is now working on the HTML 5 specification.

Some of the rules that describe how to write HTML

Text in HTML files

Tags can...

Browsers usually ignore...

without throwing an error (quietly):

Most browsers ignore...

some common syntax errors:

Typical DOCTYPE

<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

XHTML syntax

We are also in the age of XHTML 1.1.

HTML is easy for humans to write, but hard for computers to handle. If the humans could be a bit more consistent it would be easier to write, for example, a browser to work on a mobile phone that has much less in the way of computing power than a desktop computer. XHTML is more rigid, and therefore easier for computers.

Some of the main differences with HTML.... In XHTML:

See this XHTML Vs HTML summary

Typical DOCTYPE +

<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Validation

Browsers are....

So the challenge is to get into the habit of using good syntax when you're starting out, because there doesn't seem to be any benefit. We'll try to address this by having you check your documents using a validation service, such as:

validator.w3.org