HTML elements refer to everything from the start tag to the end tag code.
Like this
##Start tag
Element content
End tag
## <p>
This is a paragraph
</p>
<a href="" >
This is a link
</a>
## <br /> ;
## <body>
</body>
Note: The start tag is often called an opening tag, and the end tag is often called a 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
Tip: You will learn more about attributes in the next chapter of this tutorial.
Nested HTML Elements
Most HTML elements can be nested (can contain other HTML elements). HTML documents are composed of nested HTML elements.
##<html><body><p>There are three html elements here</p> </body> ; </html>
##The above example contains three HTML elements. They are <p> element, <body> element, <html> element
HTML example explanation
<p> element:
##<p>This is my first paragraph.</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>This is my The first paragraph.</p>
</body>
<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>This is my first paragraph.</p>
</body>
</ The html>
<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>This is a paragraph
<p>This is a paragraph
##Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>php.cn</title>
</head>
<body>
<p>This is a paragraph
<p>This is a paragraph
</body>
</html>
Program running result:
This is a paragraph
This is a paragraph
The above example will work fine in most browsers, but don’t rely on this approach. Forgetting to use a closing tag can produce unpredictable results or errors.
Note
: Future versions of HTML will not allow the closing tag to be omitted.
Empty HTML element
An HTML element without content is called an empty element. Empty elements are closed in the opening tag.
<br> 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.
##Tip
: HTML tags are not case-sensitive: <P> is equivalent to <p>, but lowercase is recommended
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning