English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
An HTML document is defined by HTML elements.
HTML elements refer to all the code from the start tag (start tag) to the end tag (end tag).
Start tag * | Element content | End tag * |
<p> | This is a web page paragraph | </p> |
<a href="index.html"> | This is a hyperlink | </a> |
<br> | Newline tag |
*Start tags are often called opening tags, and end tags are often called closing tags.
HTML elements start with a start tag
HTML elements are terminated with an end tag
The content of an element is the content between the start and end tags
Certain HTML elements have empty content
Empty elements are closed in the start tag (ending with the end of the start tag)
Most HTML elements can have attributes
Note: You will learn more about attributes in the next chapter of this tutorial.
Most HTML elements can be nested (can contain other HTML elements).
An HTML document is composed of nested HTML elements.
<!DOCTYPE html> <html> <body> <p>This is the first paragraph.</p> </body> </html>
The above examples include three HTML elements.
<p> element:
<p>This is the first paragraph.</p>
This <p> element defines a paragraph in the HTML document. This element has a beginning tag <p> and an ending tag </p>. Element content is: This is the first paragraph.
<body> element:
<body> <p>This is the first paragraph.</p> </body>
<body> element defines the main content of the HTML document. This element has a beginning tag <body> and an ending tag </body>. Element content is another HTML element (the p element).
<html> element:
<html> <body> <p>This is the first paragraph.</p> </body> </html>
<html> element defines the entire HTML document. This element has a beginning tag <html> and an ending tag </html>. Element content is another HTML element (the body element).
Even if you forget to use the end tag, most browsers will display HTML correctly:
<p>This is a paragraph
<p>This is a paragraph
The above examples can also be displayed normally in the browser because closing tags are optional.
But do not rely on this practice. Forgetting to use end tags can produce unpredictable results or errors.
HTML elements without content are called empty elements. Empty elements are closed in the beginning tag.
<br> is an empty element without a closing tag (the <br> tag defines a line break).
In XHTML, XML, and future versions of HTML, all elements must be closed.
Add a slash to the beginning tag, such as <br /> is the correct way to close empty elements, which is accepted by HTML, XHTML, and XML.
Although <br> is valid in all browsers, but using <br /> For better compatibility, it is recommended to use <br /> Newline tag.
HTML tags are case-insensitive: <P> is equivalent to <p>. Many websites use uppercase HTML tags.
The basic tutorial uses lowercase tags because the World Wide Web Consortium (W3C) In HTML 4 It is recommended to use lowercase, and in future (X)HTML versions, lowercase is mandatory.
It is recommended that everyone use lowercase tags consistently during the process of making web pages.