Types of Elements
In this unit, you will learn about the different types of HTML elements that are used to structure and organize the content of a web pages
What you will learn
-
Types of HTML elements
-
Block-level elements
-
Inline elements
-
Void elements
-
Semantic elements
Void elements
Void elements are those that don't have any content, and instead only have attributes. These elements are typically used to include images, line breaks, or other types of non-text content in a web page. Some common void elements include:
-
<img>
-
<br>
-
<hr>
-
<meta>
-
<input>
Void elements are also called self-closing elements, as they don't have a closing tag. For example:
html
Editable
1
<input placeholder="Enter your name">
Void elements should not have any content between the opening and closing tags. For example, the following code is invalid HTML:
html
1
<input type="text"></input>
Semantic elements
Semantic elements are those that have meaning beyond just the formatting of the content. These elements are used to give structure to a web page, and can help search engines and screen readers understand the content of the page. Some common semantic elements include:
-
<header>
-
<nav>
-
<section>
-
<article>
-
<aside>
-
<footer>
By using these different types of HTML elements, you can create a well-structured and organized web page that is easy for both humans and machines to understand.
List of HTML Elements
<html>
<head>
<title>
<body>
<header>
<footer>
<a>
<nav>
<main>
<section>
<article>
<aside>
<div>
<p>
<ul>
<ol>
<li>
<img>
<form>
<input>
<label>
<button>
<select>
<option>
<textarea>
<table>
<tr>
<td>
<th>
<thead>
<tbody>
<tfoot>
It is important to note that this is not an exhaustive list of all HTML elements, but it includes many of the most commonly used ones. Each element has its own unique purpose and attributes that can be used to modify its behavior and appearance. In the following units, we will cover each element in more detail and provide examples of how they can be used in web development.
Elements that always require attributes
Here's an example table of HTML elements that always have certain required attributes:
a
href
img
src
form
action
input
type
input
name
label
for
select
name
option
value
It's important to note that while these attributes are required for these elements, there may be other optional attributes that can be included as well depending on the specific use case.
Here’s an example of an a
or also called a anchor hyperlink element:
html
Editable
1
<a href="https://www.example.com">Click here to go to Example.com</a>
In this example, the a
element is used to create a hyperlink. The href
attribute specifies the URL that the hyperlink should point to. When the user clicks on the link, their web browser will navigate to the URL specified in the href
attribute. The text Click here to go to Example.com
is the content of the hyperlink, and will be displayed as underlined blue text by default in most web browsers.