HTML Elements
π What Are HTML Elements?
HTML elements are the building blocks of HTML pages. An element consists of a start tag, content, and an end tag (for most cases).
>>βIn HTML, everything visible or structural on a page is an element.β π
π¦ Structure of an HTML Element
The basic syntax of an HTML element looks like this:
Basic Element Structure
<tagname>Content goes here</tagname>Some elements are empty or self-closing, meaning they donβt have an end tag:
Self-Closing Element
<img src="image.jpg" alt="Image" />Note
β οΈ Self-closing elements include <img>, <br>, <hr>, and <input>.
π Types of HTML Elements
1. Block-level Elements π¦
Block elements take up the full width of the page and start on a new line.
- <div>
- <p>
- <h1> to <h6>
- <ul>, <ol>, <li>
- <form>
2. Inline Elements π
Inline elements do not start on a new line. They only take up as much width as necessary.
- <span>
- <a>
- <strong>, <em>
- <img>
- <br>, <input>
3. Semantic Elements π§
Semantic elements clearly describe their meaning in a human- and machine-readable way.
- <header> β Top section of the page
- <nav> β Navigation links
- <main> β Main content
- <section>, <article> β Content sections
- <footer> β Footer of the page
π§ͺ Example: Combining Elements
Combining Different HTML Elements
<header>
<h1>My Website</h1>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
</header>
<main>
<section>
<h2>Welcome!</h2>
<p>This is a paragraph with a <a href="#">link</a>.</p>
</section>
</main>
<footer>
<p>© 2025 All rights reserved.</p>
</footer>π Table: Element Summary
| Element | Type | Description |
|---|---|---|
| <div> | Block | Generic container for layout |
| <span> | Inline | Generic container for inline text |
| <h1> | Block | Main heading element |
| <a> | Inline | Defines a hyperlink |
| <main> | Semantic | Main content container |
π Learn More
>>βMaster the elements, and you master the web.β π§©