<h2> and </h2> are tags. The entire heading construct is the element.
Self-Contained Syntax and Void Elements
Some HTML elements are known as void elements. They cannot have child nodes and must not have closing tags in HTML syntax.
<img src="team.jpg" alt="Our development team">
<br>
<hr>
<input type="email" name="email">
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css">Common void elements include:
<area><base><br><col><embed><hr><img><input><link><meta><source><track><wbr>
Do not write a closing tag for a void element. For example, use <img src="photo.jpg" alt="A photo">, not <img></img>.
In HTML, a trailing slash is unnecessary for void elements. In addition, a slash does not make a non-void element self-closing. For example, <div /> does not work like a self-closing XML element in HTML.
4. Opening Tags and Closing Tags
Most HTML elements use an opening tag and a closing tag. The closing tag contains a forward slash before the element name.
<strong>Important information</strong>
<em>Emphasized text</em>
<section>
<h2>About Us</h2>
<p>We build practical software solutions.</p>
</section>In the last example, the section element begins with <section> and ends with </section>. The heading and paragraph are inside it.
Are Closing Tags Always Required?
Some non-void HTML elements have optional end tags under specific conditions defined by HTML. For example, a paragraph end tag may be omitted when the HTML rules allow it. However, beginners should generally write explicit closing tags for elements that require them and use clear, consistent markup.
For example, this is clear and recommended:
<p>First paragraph.</p>
<p>Second paragraph.</p>Do not assume every element can omit its closing tag. Rules depend on the element and its position in the document.
5. HTML Attributes: Adding Information to Elements
Attributes provide additional information or configuration for an HTML element. They are generally written in the opening tag, after the element name.
Example:
<a href="https://codementrix.in" target="_blank" rel="noopener">
Visit Codementrix
</a>This example uses three attributes: