HTML element
An HTML document consists of a series of HTML elements, which form the basis of a web page's structure.
What is an HTML element?
An HTML element is the complete structure from the **start tagtoto the end tag**.
| The opening tag | Element content | End tag |
|---|---|---|
| This is a paragraph | ||
| This is a link | ||
|
|
Line break (empty element) | None |
Explanation:
- A start tag is also called an opening tag
- An end tag is also called a closing tag
HTML Element Syntax Rules
- An element begins withThe opening tagand ends withEnd tagat the end
- Element content lies between the start tag and the end tag
- Some elements areempty elements, with no content
- Empty elements usually self-close in the start tag (such as
) - Most elements can containattributes
**Tip:** Attributes will be described in detail in later chapters.
Nesting of HTML Elements
HTML elements can be nested within one another, forming a tree structure:
- One element can contain other elements
- An HTML document is essentially a nested structure (DOM tree)
HTML Document Example
This is the first paragraph.
This example contains three core elements:html、body、p。
Example walkthrough
element (paragraph)
This is the first paragraph.
Defines a paragraph containing text content.
element (body)
This is the first paragraph.
Defines the main content of the page and can contain multiple child elements.
element (root element)
This is the first paragraph.
The root node of the entire HTML document; all content must be contained within it.
About End Tags
In some cases, the browser automatically completes missing end tags:
This is a paragraph
This is another paragraph
Although it can be displayed normally,relying on this behavior is not recommended, as it may lead to:
- Structural disorder
- Abnormal styling
- Compatibility Issues
HTML Empty Elements
Empty elements are elements with no content, for example:
(line break)(image)(input field)
Recommended notation:
This notation is compatible with HTML, XHTML, and XML, and is more standard.
Best practice: use lowercase tags
HTML tagCase-insensitive, but it is recommended to:
- uniformly uselowercase tags
- Comply with W3C standards
- Improve code readability and consistency