Writing HTML Document
Writing HTML Document
• Void elements can't have any contents (since there's no end tag, no content
can be put between the start tag and the end tag).
The DOCTYPE
1. The first character of an end tag must be a LESS-THAN SIGN character (<).
2. The second character of an end tag must be a SOLIDUS character (/).
3. The next few characters of an end tag must be the element's tag name.
4. After the tag name, there may be one or more ASCII whitespace.
5. Finally, end tags must be closed by a GREATER-THAN SIGN character (>).
Attributes
• Attributes for an element are expressed inside the element's start tag.
• Attributes have a name and a value. Attribute names must consist of one or
more characters other than controls, SPACE, ("), ('),(>), (/), (=), and
noncharacters. In the HTML syntax, attribute names, even those for foreign
elements, may be written with any mix of ASCII lower and ASCII upper
alphas.
• Attributes can be specified in four different ways:
• Empty attribute syntax
Just the attribute name. The value is implicitly the empty string.
• Unquoted attribute value syntax
The attribute name, followed by zero or more ASCII whitespace, followed by a single EQUALS
SIGN character, followed by zero or more ASCII whitespace, followed by the attribute value, which, in
addition to the requirements given above for attribute values, must not contain any literal ASCII
whitespace, any QUOTATION MARK characters ("), APOSTROPHE characters ('), EQUALS SIGN
characters (=), LESS-THAN SIGN characters (<), GREATER-THAN SIGN characters (>), or GRAVE
ACCENT characters (`), and must not be the empty string
• Single-quoted attribute value syntax
The attribute name, followed by zero or more ASCII whitespace, followed by a single EQUALS SIGN
character, followed by zero or more ASCII whitespace, followed by a single APOSTROPHE character
('), followed by the attribute value, which, in addition to the requirements given above for attribute
values, must not contain any literal APOSTROPHE characters ('), and finally followed by a second
single APOSTROPHE character (').
• Double-quoted attribute value syntax
The attribute name, followed by zero or more ASCII whitespace, followed by a single EQUALS SIGN
character, followed by zero or more ASCII whitespace, followed by a single QUOTATION MARK
character ("), followed by the attribute value, which, in addition to the requirements given above for
attribute values, must not contain any literal QUOTATION MARK characters ("), and finally followed by
a second single QUOTATION MARK character (").
Comments
<div id="content">
<h1>Heading here</h1>
<p>Lorem ipsum dolor sit amet.</p>
<p>Lorem ipsum dolor <em>sit</em> amet.</p>
<hr>
</div>
<div id="nav">
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
• A diagram of the this HTML document tree would look like this.
</div>
</body>
Parent and Child
• A parent is an element that is directly above and connected to an element in the document tree. In the diagram
below, the <div> is a parent to the <ul>.
• A child is an element that is directly below and connected to an element in the document tree. In the diagram
above, the <ul> is a child to the <div>.
Sibling
• A sibling is an element that shares the same parent with another element.
• In the diagram below, the <li>'s are siblings as they all share the same parent - the <ul>.