HTML elements



HTML documents are defined by HTML elements.

##Start tag*Element contentEnd tag*<p>This is a paragraph</p><a href ="default.htm">This is a link</a>##<br>

*The start tag is often called the opening tag (opening tag), and the end tag is often called the closing tag (closing tag).


HTML element syntax

HTML elements start with a start tag

HTML elements are terminated with a closing tag

The content of the element is the content between the opening tag and the closing tag

Some HTML elements have empty content

Empty elements are closed in the opening tag (end with the end of the opening tag)

Most HTML elements can have attributes

Note: You will learn more about attributes in the next chapter of this tutorial.


Nested HTML elements

##<pMost html="" Elements can be nested (can contain other ="" elements).

HTML documents are composed of nested HTML elements.


##HTML document example

<!DOCTYPE html>
<html>
<body>
    <p>这是第一个段落。</p>
</body>
</html>
The above example contains three HTML element.


HTML Example Analysis

##< p> element:

<p>这是第一个段落。</p>
This <p> element defines a paragraph in an HTML document.


This element has a start tag <p> and an end tag </p>.
The content of the element is: This is my first paragraph.

<body> Element:

<body>
<p>这是第一个段落。</p>
</body>
The <body> element defines the body of the HTML document.


This element has a start tag <body> and an end tag </body>. The
element content is another HTML element (p element).


<html> Element:

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

The <html> element defines the entire HTML document.

This element has a start tag <html> and an end tag </html>.
The content of the element is another HTML element (body element).


Don’t forget the closing tag

Even if you forget to use the closing tag, most browsers will do it correctly Display HTML:

<p>这是一个段落
<p>这是一个段落
The above example can also be displayed normally in the browser because the closing tag is optional.

But don’t rely on this approach. Forgetting to use a closing tag can produce unpredictable results or errors.


HTML Empty Element

An HTML element with no content is called Empty element. Empty elements are closed in the opening tag.

<br> It is an empty element without a closing tag (<br> tag definition wraps).

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

Adding a slash in the opening tag, such as <br />, is the correct way to close an empty element, and is accepted by HTML, XHTML, and XML.

Even though <br> is valid in all browsers, using <br /> is actually a longer-term guarantee.

HTML Tip: Use lowercase tags H

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

W3CSschool uses lowercase tags because the World Wide Web Consortium (W3C) recommends lowercase in HTML 4 and will make it mandatory in future versions of (X)HTML.

Line break