HTML elements are the building blocks of a web page, each serving a specific purpose in structuring and presenting content. In HTML, elements are typically composed of opening and closing tags, with content sandwiched between them.
Here are explanations of some common HTML elements along with examples:
- Paragraph (
<p>
):- The
<p>
element is used to define paragraphs of text. - Example
- The
<p>This is a paragraph of text.</p>
- Heading (
<h1>
,<h2>
, …,<h6>
):- Headings are used to define the hierarchical structure of the document, with
<h1>
being the highest level and<h6>
the lowest. - Example:
- Headings are used to define the hierarchical structure of the document, with
<h1>Main Heading</h1>
<h2>Subheading</h2>
- Link (
<a>
):- The
<a>
element is used to create hyperlinks, allowing users to navigate to other web pages. - Example:
- The
<a href="https://www.example.com">Visit Example.com</a>
- Image (
<img>
):- The
<img>
element is used to embed images in a web page. - Example
- The
<img src="image.jpg" alt="Description of the image">
- List (
<ul>
,<ol>
,<li>
):- Lists can be unordered (
<ul>
) or ordered (<ol>
), with list items defined by the<li>
element. - Example:
- Lists can be unordered (
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<ol>
<li>First</li>
<li>Second</li>
</ol>
- Table (
<table>
,<tr>
,<th>
,<td>
):- Tables are created using the
<table>
element, with rows defined by<tr>
, header cells by<th>
, and data cells by<td>
. - Example:
- Tables are created using the
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
- Form (
<form>
,<input>
,<button>
):- Forms are used to collect user input and can include elements like
<input>
for text boxes and<button>
for submission. - Example:
- Forms are used to collect user input and can include elements like
<form action="/submit" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username">
<button type="submit">Submit</button>
</form>
- Header and Footer (
<header>
,<footer>
):- Semantic elements like
<header>
and<footer>
help define the structure and meaning of different sections of a page. - Example:
- Semantic elements like
<header>
<h1>Main Header</h1>
</header>
<footer>
<p>© 2024 Example Company</p>
</footer>
- Strong and Emphasis (
<strong>
,<em>
):<strong>
is used to indicate strong importance, and<em>
is used to emphasize text.- Example:
<p><strong>This is strong text.</strong></p>
<p><em>This is emphasized text.</em></p>
- Division (
<div>
):- The
<div>
element is a generic container that is often used for grouping and styling purposes. - Example:
- The
<div>
<p>This is inside a div.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</div>
Empty HTML elements also known as void elements, are elements that do not have any content between opening and closing tags. Instead, they may include attributes, and they usually don’t require a closing tag. In HTML, these elements are self-closing.
These examples cover some of the fundamental HTML elements. Combining and nesting these elements allows developers to create structured and meaningful web pages.