Syntax and Semantics
Syntax is the arrangement of elements and attributes to create well-formed documents.
Semantics is concerned with meaning. In HTML, this is the purpose of elements and attributes, and the logical (sense and reference) relationship between elements and the attributes of those elements.
Authors usually, whether they know it or not, begin with the semantics because they know the content or type of content to be presented. Therefore, authors need to be concerned that their HTML syntax reflects those semantics. The user agents can determine the author's intended meaning as long as the syntax is correct.
HTML5 user agents must be backward compatible with HTML4. This means that any good HTML4 syntax and semantic practices are perfectly legal to use. Even some illegal practices are effectively supported by standard error correction. However, authors are advised to use a consistent style which relies as little as possible on current error correction guidelines.
In particular, authors are encouraged to always quote attributes and to never omit start or end tags. There are valid reasons to violate both guidelines, but doing so correctly requires more detailed knowledge of exception cases than is appropriate for this document.
Syntax used within this document
An HTML document begins with the Doctype declaration.
There are elements that are empty elements. Empty elements have only one tag. This tag may include attributes.
The remaining elements have start tags, which may contain attributes, and end tags. Between the start and end tags is content and other allowable elements.
- Consecutive element tags on the same line will not have any spaces between them.
- Attributes within an element tag will be separated by one space, with one space between the tag name and the first attribute, and no space between the last attribute and the closing of the tag.
- Attribute values will be enclosed in double quotes.
- Empty tags will end in ` />`. (A space, followed by the solidus indicating an empty element, then the greater-than sign to close the tag.) While the space is not strictly required, there are tools out there that will wrongly treat the "/" as part of an attribute value.
- Indenting will be 2 spaces per indent level.
Authors are free to adopt any valid variation of the HTML5 syntax but are encouraged to be consistent throughout documents regardless of their choice.
Line break, continue displaying content on the next line.
Image, replace with the image referenced by the `src` attribute or present the text of the `alt` attribute.
<img src="orange_cat.png" alt="Joe's orange cat is sitting on his kitchen counter." />
Paragraph, with sentences as content.
<p>The cruel weather postponed the ball game. Fans everywhere were disappointed.</p>
An ordered list, with entries in the list specifying a link associated with content.
<ol> <li><a href="html5_defintion.html>HTML5</a>/li> <li><a href="html4_defintion.html>HTML4</a></li> <li><a href="xhtml5_defintion.html>XHTML5</a></li> <li><a href="xhtml1x_defintion.html>XHTML1.x</a></li> </ol>