HTML Basics 5 min readLesson 2 of 3
HTML Elements & Tags
Understand opening tags, closing tags, self-closing tags, and element nesting.
### What is an HTML Element? An HTML element is defined by a start tag, some content, and an end tag:
html
<tagname>Content goes here...</tagname>
Examples of HTML Elements - `<h1>My First Heading</h1>` - `<p>My first paragraph.</p>` - `<button>Click Here</button>`
Nested HTML Elements HTML elements can be nested inside other elements:
html
<div class="container"> <h2>Subheading</h2> <p>Paragraph nested inside a container div.</p> </div>
Empty / Self-Closing Elements Some elements do not have content or a closing tag, such as `<br>` (line break) and `<img>` (image):
html
<p>Line 1<br>Line 2 after line break</p> <img src="logo.png" alt="Company Logo"> ```
Interactive Sandbox
HTML Nested Elements Example
Live W3-EditorEdit code below and see instant live output in the preview box
Source Code InputHTML / CSS / JS
Live Browser Result Live Result
Test Yourself With Exercises
Verify your understanding before moving to the next topic