HTML elements


May 02, 2021 11:06 HTML


Table of contents


HTML elements


HTML documents are defined by HTML elements, which refer to all code from the start tag to the end tag.


HTML elements

Start Tags The contents of the element End Tags
<p> This is a paragraph </p>
<a href="default.htm"> This is a link </a>
<br> This is a line-by-line label

* The start label is often referred to as the start tag, and the end label is often referred to as the closed tag.


HTML element syntax

  • HTML elements start with the start tag
  • HTML element terminates by ending the label
  • The content of an element is the content between the start label and the end label
  • Some HTML elements have empty content
  • Empty element closes in start label (ends at end of start label)
  • Most HTML elements can have the property

Note: You'll learn more about properties in the HTML Properties chapter of this tutorial.


Nested HTML elements

HTML documents consist of nested HTML elements that can contain other HTML elements.


AN instance of an HTML document

<!DOCTYPE html>

<html>

<body>

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

</body>

</html>


Try it out . . .

The above example contains three HTML elements.


HTML instance resolution

Elements:

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


Try it out . . .

This element defines a paragraph in an HTML document.
This element has a start label, and an end label, slt;/p.gt;
The element content is: This is the first paragraph.

Open the field test to start learning the tab.

The elements:

<body>

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

</body>


Try it out . . .

The element defines the body of the HTML document.
This element has a start label, slt; body, and an end label, slt;/body.
The element content is another HTML element (p element).

The elements:

<html>

<body>

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

</body>

</html>


Try it out . . .

The element defines the entire HTML document.
This element has a start tag , and an end tag , and an end tag , .
The element content is another HTML element (body element).


Don't forget to end the label

If you forget to use the end tag, most browsers will also display HTML correctly:

<p>这是一个段落

<p>这是一个段落


Try it out . . .

The above examples can also be displayed in the browser because closing the tab is optional.

However, you cannot rely on this because forgetting to use the end label can produce unpredictable results or errors.


HTML empty element

An HTML empty element is an HTML element without content.

HTML empty elements should be closed in the Start label.

An empty element of HTML is slt;br?gt;(used to define line-ups), and the element is that there is no label off.

The closing method for HTML empty elements is to add slashes to the start label, such as slt;br /;, which is accepted by HTML, XHTML, and XML.

Note: In XHTML, XML, and future versions of HTML, all elements must be turned off, even empty elements.


HTML Tip: Use a small-case label

Because HTML tags are not sensitive to the case of English letters, they mean the same thing, although most websites prefer to use capital HTML tags.

W3CSchool uses a small-case label because the World Wide Web Federation (W3C) recommends using small verses in HTML 4 and enforces them in future (X) HTML versions.