Opening and Closing Tags of Elements

This section describes the syntax of entering opening tags and closing tags to create HTML elements. It's better to have all elements closed explicitly with closing tags.

HTML documents are made up by a collection of nested HTML elements. Each element has a required opening tag and an optional closing tag. Here are some basic guidelines on how to enter HTML tags to create HTML elements.

1. Each HTML element must start with an opening tag in the format of:

<tag_name attributes>

2. An HTML element that supports content must have the content immediately following the opening tag like this:

<tag_name attributes>content

3. An HTML element that supports content must have a closing tag or let the browser to determine where is the end. It is strongly recommended that you always provide closing tags yourself like this:

<tag_name attributes>content</tag_name>

4. An HTML elements that does not support content must have no closing tag or combine the opening tag and closing tag into a short-hand format. It is strongly recommended that you always use the short-hand format like this:

<tag_name attributes/>

5. HTML element tag names are case insensitive. For example, "body" and "BODY" are identical. It is strongly recommended that you always use lower case letters in tag names.

Here is a good example of HTML document that have some elements without closing tags and some with closing tags:

<!DOCTYPE html>
<!-- HTML_Opening_and_Closing_Tags.html
 - Copyright (c) 2009 HerongYang.com. All Rights Reserved.
-->
<html>
<head>
<meta charset="iso-8859-1">
<title>Opening and Closing Tags</title>
</head>
<body>
<!-- HTML elements with no closing tags -->
<p>Tags are used to delimit the start and end of elements
in the markup.
<hr>

<!-- HTML elements with closing tags -->
<p>Tags are used to delimit the start and end of elements
 in the markup.</p>
<hr/>
</body>
</html>

Table of Contents

 About This Book

 Introduction of HTML

 Introduction of HTML5 Features

 HTML Document Structure and Content

HTML Document and Elements Syntax

 HTML Document Syntax

 Document Character Set and Encoding

 Entering Comments in HTML Document

Opening and Closing Tags of Elements

 Using Nested Elements

 Specifying Element Attributes

 Specifying Element Contents

 Element Content Syntax Types

 Using Whitespace Characters

 Using Character Entity References

 Using Numeric Character References

 Displayed and Printed HTML Documents

 Responsive Design of Web Pages

 MathML Integration in HTML Documents

 References

 Full Version in PDF/EPUB