HTML elements
The HTML element refers 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 paragraph |
</p> |
<a href= "default.htm" > |
This is a link |
</a> |
<br/> |
|
|
Note: The start tag is often called an open tag (opening tag), and the end tag is often referred to as a closed tag (closing tag).
HTML element syntax
- HTML element to start tag starting
- HTML element terminated with end tag
- The content of an element is the content between the start tag and the end tag
- Some HTML elements have blank content (empty contents)
- Empty elements are closed in the start tag (ending with the end of the start tag)
- Most HTML elements can have properties
Tip: You'll learn more about properties in the next chapter of this tutorial.
Nested HTML elements
Most HTML elements can be nested (other HTML elements can be included).
HTML documents are composed of nested HTML elements.
HTML document Instance
The above example contains three HTML elements.
HTML instance Interpretation <p> elements:<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>.
Element contents are: This is my first paragraph.
<body> elements:<body><p>this is my first paragraph.</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).
The
This element has a start tag
The element content is another HTML element (the BODY element).
Don't forget to end the tagEven 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 example is not a problem in most browsers, but do not rely on this approach. Forgetting to use the end tag can produce unpredictable results or errors.
Note: Future HTML versions do not allow the end tag to be omitted.
An empty HTML elementHTML elements that have no content are called empty elements. The empty element is closed in the Start tab.
<br> is the empty element without closing the label (the <br> tag defines a newline).
In XHTML, XML, and future versions of HTML, all elements must be closed.
Adding slashes to the start tag, such as <br/>, is the correct way to close an empty element, which is accepted by HTML, XHTML, and XML.
Even if <br> is valid in all browsers, the use of <br/> is actually a longer term guarantee.
HTML Hint: Use lowercase tagsHTML tags are not case sensitive:<p> is equivalent to <p>. Many websites use uppercase HTML tags.
W3school uses lowercase tags because the World Wide Web Consortium recommends lowercase in HTML 4, and lowercase in future (X) HTML versions.
HTML Basics 2