Latest web development tutorials

HTML elements

HTML documents are defined by HTML elements.


HTML elements

Start tag * Element content End tag *
<P> This is a paragraph </ P>
<a href="default.htm"> This is a link </a>
<br>

* Start tag is often called the start tag (opening tag),the end tag is often called theclosing tag (closing tag).


HTML Element Syntax

  • HTML elements start withthe start tag
  • HTML elements withan end tag termination
  • Content element is the content ofthe start tag and the end tag
  • Some HTML elements haveempty content (empty content)
  • Empty elementsare closed in the start tag (to end the start tag and end)
  • Most HTML elements can haveattributes

NOTE: You will learn more about the properties in the next chapter of this tutorial.


Nested HTML elements

HTML documents consist of nested HTML elements.


HTML document instance

<! DOCTYPE html>
<Html>

<Body>
<P> This is the first paragraph. </ P>
</ Body>

</ Html>

The above examples contains three HTML elements.


Examples of HTML parsing

<p> element:

<p>这是第一个段落。</p>

The <p> element defines a paragraph in the HTML document.
The element has a start tag <p> and an end tag </ p>.
Element content is: This is my first paragraph.

<body> element:

<body>
<p>这是第一个段落。</p>
</body>

The <body> element defines the body of the HTML document.
The element has a start tag <body> and an end tag </ body>.
Element content is another HTML element (p element).

<html> element:

<html>

<body>
<p>这是第一个段落。</p>
</body>

</html>

The <html> element defines the whole HTML document.
The element has a start tag <html>, and an end tag </ html>.
Element content is another HTML element (body element).


Do not forget the end tag

Even if you forget to use a closing tag, most browsers will correctly display HTML:

<p>这是一个段落
<p>这是一个段落

The above examples can be displayed properly in the browser, because the closing tag is optional.

But do not rely on this practice. Forgetting the end tag can produce unexpected results or errors.


HTML empty element

HTML elements without content are called empty elements. Empty elements are closed in the start tag.

<br> is no closing tag empty element (<br> tag defines a line break).

In XHTML, XML, and future versions of HTML, all elements must be closed.

Adding a slash at the beginning of the label, such as <br />, is the proper way to close empty elements, HTML, XHTML and XML accept this approach.

Even <br> in all browsers are effective, but using <br /> actually more long-term protection.


HTML Tip: Use Lowercase Tags

HTML tags are not case sensitive: <P> is equivalent to <p>. Many sites use uppercase HTML tags.

W3CSchool using lowercase tags because the World Wide Web Consortium (W3C) HTML 4recommended in lowercase, but in the future (X) HTML version of the mandatoryuse lowercase.