include "_i/1.h" ?>
(X)HTML syntax
include "_i/2.h" ?>
(X)HTML syntax
See also:
Tag Lingo
<p align="right">A right-justified sentence.</p>
- p is the tag name.
- align is an attribute of the tag.
- right is the value of the align attribute.
- Attributes go only in the opening (<p>) tag--nothing attribute-related
is needed in the closing (</p>) tag.
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
|
|
wrong
|
|
|
|
|
|
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
- Any number of spaces in a row are rendered as one space.
- A line break (not a <br> , but rather what happens when you hit the "Enter"
key) is treated as a space too.
Tags can...
- be upper- or lower-case: <br> or <BR>
- have attributes enclosed in quotes or not: <h2 align=right>Some
headline</h2>
- Do not *have* to be closed: <p>One
paragraph.<p>Another
paragraph.
Browsers usually ignore...
without throwing an error (quietly):
- any number of spaces in the tag, except right after "<": So <p> is
rendered the same as <p > , (but not < p> !)
- non-existent attributes: <p favorites="yes">
- unrecognized tags: <uglygrammar>I ain't sayin
nuthin</uglygrammar>
- closing tags that aren't necessary: <br></br>
Most browsers ignore...
some common syntax errors:
- They'll display text in your <head> section:
<html>
<head>
<h1>(not) the proper place for a headline</h1>
</head>
Typical DOCTYPE
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
- This is the least restrictive (easiest to validate)
- But avoid the xhtml-style self-closing line breaks (<br />).
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:
- Tag names, attributes must be lower-case: <p
align='right'>
- Attribute values must be enclosed in quotes either double " " or
single ' ',
- Some elements are required such as a <title>,
- All tags must be closed. E.g. <br />
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....
- very forgiving about many syntax errors with pure HTML with no CSS
- not quite so forgiving with documents that use HTML and CSS
- impossible if you're trying to do pixel-perfect layout with poorly formed
HTML and CSS that you'd like to work in both IE and FireFox.
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
include "_i/3.h" ?>