CS 100 (Learn) — CS 100 (Web) — Module 07
Let's revisit the example from the previous section.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello</title>
</head>
<body>
<p>Hello, World!</p>
<p>Here is a bullet list:
<ul>
<li>First bullet item</li>
<li>Second bullet item has some <em>emphasis</em> in it</li>
</ul>
</p>
</body>
</html>
Hello, World!
Here is a bullet list:
It just so happens that we can make this example a little less cluttered.
In the latest version of HTML (HTML5) there are a few paired tags for which the closing tag is optional.
For example, the closing paragraph tag </p>
is optional. This is because it is always clear that a paragraph ends when a new paragraph begins. You cannot have paragraphs nested inside of each other.
Another optional closing tag is the </head>
tag. The header section must be over when the <body>
section begins.
Similarly, the closing </body>
and </html>
tags are always at the end of the doucment and can also be omitted.
One final example of a closing tag that can be omitted is the closing </li>
(list item) tag. Every </li>
closing tag is immediately followed by either a new list item (<li>
) or the end of the list (in this example, </ul>
).
If we remove all of the optional closing tags, our example becomes a little cleaner:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello</title>
<body>
<p>Hello, World!
<p>Here is a bullet list:
<ul>
<li>First bullet item
<li>Second bullet item has some <em>emphasis</em> in it
</ul>
Hello, World!
Here is a bullet list: