- HTML Tutorial
- HTML Introduction
- HTML Editors
- HTML Basic
- HTML Comments
- HTML Elements
- HTML Attributes
- HTML Id & Classes
- HTML Skeletal Tags
- HTML Heading Tags
- HTML Paragraph Tag
- HTML Line Break Tag
- HTML Pre Tag
- HTML Anchor Tag
- HTML Image Tag
- HTML Horizontal Line Tag
- HTML Inline & Block
- HTML Inline
- HTML Block
- HTML LInks
- HTML Images
- HTML Formatting
- HTML Head
- HTML Head
- HTML Title
- HTML Meta Elements
- HTML Favicon
- HTML Style
- HTML List
- HTML Lists
- HTML Unordered List
- HTML Ordered List
- HTML Description List
- HTML Table
- HTML Tables
- HTML Table Headers
- HTML Table Styling
- HTML Table Colgroup
- HTML Form
- HTML Forms
- HTML Form Elements
- HTML Form Attributes
- HTML Input Types
- HTML Input Attributes
- HTML Form Actions
- HTML Semantic
- HTML Semantics
- HTML Graphics & Media
- HTML Canvas
- HTML SVG
- HTML Video & Audio
- HTML Plug-ins
- iFrames in HTML
- HTML Miscellaneous Tags
- HTML Code Tag
- HTML Entities
- HTML Quotation
- HTML Global Attributes
- HTML Obsolete Tags
- HTML Emojis
- HTML Symbols
- HTML Events
- HTML Colors
HTML Elements
In HTML, elements are the fundamental building blocks that define the structure, logic, and content of a web page. Think of a web page as a house: HTML elements are the bricks, windows, and doors that make up the frame. Most elements consist of an opening tag and a closing tag, wrapping around the content you want to display. These tags are always enclosed in angle brackets (< >).
Opening and Closing Tags:
- An opening tag marks where an element begins. It is written as <tagname>.
- A closing tag signals the end of that element. It looks just like the opening tag but includes a forward slash: </tagname>.
- The content whether it is text, an image, or another element sits between these two markers.
Nested Elements:
- HTML is hierarchical. This means you can place elements inside other elements, creating a "parent-child" relationship.
- When nesting, you must close tags in the reverse order they were opened. This is often called "Last In, First Out."
- Example: In the snippet below, the
<div>is the parent, while the<h1>and<p>are its children.
<div>
<h1>Main Page Title</h1>
<p>This is a paragraph nested inside a container.</p>
</div>
Empty Elements:
- Not every element needs to wrap around content. Some elements stand alone because they simply insert something into the page. These are called Empty Elements or Void Elements.
- Because they have no content, they do not require a closing tag.
- Example: The
<img>tag for images,<br>for line breaks, and<hr>for horizontal rules. - Example usage: <img src="logo.png" alt="Company Logo">
<img /> with a trailing slash, this is a leftover habit from XHTML. In modern HTML5, the slash is optional and usually omitted.
Attributes:
- Attributes provide extra information about an element or change how it behaves. They never appear in the closing tag; they are always placed inside the opening tag.
- Attributes usually come in name/value pairs like: name="value".
- Example: To create a link, we use the
<a>tag with anhrefattribute to tell the browser where to go: <a href="https://google.com">Visit Google</a>
Common HTML Elements:
- Text Elements: These define the hierarchy of your text. <h1> is the most important heading, while <p> handles standard paragraphs. <strong> makes text bold (indicating importance), and <em> adds italics (emphasis).
- Container Elements: These are used to group other elements together for styling or layout purposes. Examples include <div> (a generic box), <section>, and <main>.
- List Elements: Use <ul> for bulleted (unordered) lists and <ol> for numbered (ordered) lists. Individual items go inside <li> tags.
- Link and Image Elements: The <a> tag handles navigation, while <img>, <video>, and <audio> embed media.
- Form Elements: These allow user interaction. Common tags include <form>, <input> for typing text, and <button> for submitting data.
Semantic Elements:
- Semantic elements are tags that describe their meaning to both the browser and the developer. Instead of using a generic
<div>for everything, semantic tags tell us exactly what that section of the page does. - Benefits: They significantly improve SEO (search engine rankings) and Accessibility (helping screen readers for visually impaired users).
- Examples:
- <header>: The top section of a page or article.
- <nav>: Contains navigation links.
- <article>: A self-contained piece of content, like a blog post.
- <footer>: The bottom section containing copyright or contact info.
<div> for every single container. If it's a navigation menu, use <nav>!
Understanding HTML elements is the first step toward becoming a proficient web developer. By choosing the right elements for the right job, you ensure your website is clean, accessible, and easy for search engines to understand. Each element is a tool in your kit learning when and how to use them will make your code more professional and robust.