HTML Basics
HTML Elements
Understand HTML elements, their structure, and how they work together to build web pages.
What is an HTML Element?
An HTML element is defined by a start tag, some content, and an end tag. The element is everything from the start tag to the end tag:
<tagname>Content goes here...</tagname>
HTML elements can be nested — elements can contain other elements. All HTML documents consist of nested HTML elements.
HTML Element Structure
An HTML element consists of:
- Opening tag:
<p> - Content: The visible content
- Closing tag:
</p>
Some elements have no content and are called empty elements. Empty elements do not have a closing tag, like the <br> element.
Common HTML Elements
| Element | Description |
|---|---|
<h1> to <h6> | Defines headings |
<p> | Defines a paragraph |
<a> | Defines a link |
<img> | Embeds an image |
<div> | Defines a section/container |
<span> | Inline container |
Example
html
<!DOCTYPE html>
<html>
<body>
<h1>This is a Heading</h1>
<p>This is a <strong>paragraph</strong> with <em>emphasis</em>.</p>
<div class="container">
<p>This paragraph is inside a div.</p>
<ul>
<li>Item one</li>
<li>Item two</li>
<li>Item three</li>
</ul>
</div>
<br>
<hr>
</body>
</html>Try it yourself — HTML