In this article, Mytour will introduce you to HTML elements. Additionally, readers can refer to other articles on Mytour to learn more about what HTML is.
Understanding HTML Elements
1. HTML Elements
1.1. Nested HTML Elements
1.2. End Tags in HTML
1.3. Void Elements in HTML
1.4. HTML Case Insensitivity
1. HTML Elements
In HTML, elements typically consist of a start tag and an end tag, with content inserted in between.
HTML elements are any content enclosed between a start tag and an end tag.
HTML elements without content are referred to as void elements. Void elements do not have an end tag, for example, the br element.
HTML elements can nest within each other, meaning one element can contain other elements.
All HTML documents contain nested HTML elements.
For example: the following example illustrates 4 nested HTML elements:
The result after using nested HTML elements appears as follows:
In the example above:
The html element defines the entire document.
- There's a start tag html and an end tag html.
- Inside the html element is the body element, or in other words, the body element is nested within the html element.
The body element specifies the document's body content.
- There's a start tag body and an end tag body.
- There are 2 HTML elements nested within the body element: h1 and p.
The h1 element defines a heading.
- There's a start tag h1 and an end tag h1.
- The content element is Mytour. In the example above, it is h1Mytour h1.
The p element defines a paragraph of text.
- It includes a start tag p and an end tag p.
- The content element is: Learning HTML on Mytour. In the example above, it is
1.2 End Tags in HTML
Some HTML elements can still render correctly even if we forget to use the end tag.
Example 1:
In the example above, even without the end tag, the result still displays correctly as shown below:
Note: However, not all HTML elements will render correctly, so Mytour advises you to use the end tag.
1.3 Empty Elements in HTML
HTML elements without content are called empty elements.
br is an empty element because it has no closing tag. The br tag in HTML is used to insert a line break.
For example:
The result returned after using the br tag appears as follows:
Empty elements can be placed within the opening tag like br /.
1.4 HTML Case Insensitivity
HTML tags are not case sensitive, so we can use P or p interchangeably.
This article has just introduced you to HTML elements. Furthermore, if you have any questions or queries needing clarification such as how to set file paths in HTML?, readers can leave their comments below the article for discussion.