HTML for Beginners 04 — Forms & Semantic Elements
Welcome back to the fourth and final installment of our HTML for Beginners series! In this tutorial, we’ll be covering HTML Forms and Semantic elements, which were introduced in HTML5 to improve the structure and accessibility of web pages.
Forms
Forms are an essential component of web development, allowing users to input data and submit it to a server for processing. They can be used for various purposes, such as registering users, collecting feedback, or enabling users to make purchases.
To create a form in HTML, we use the?<form>?tag. Let’s say we have a registration page, where we need to ask our users for their name, email, and password:
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br>
<input type="submit" value="Submit">
</form>
In the code above, we have three input fields:?name,?email, and?password. Each input field has a corresponding label, which makes it easier for users to understand what information they need to provide.
Note that the?for?attribute of each label matches the?id?attribute of its corresponding input field. This association ensures that clicking on the label focuses the input field.
The?type?attribute of the input field determines what kind of input the field accepts. For example,?type="text"?specifies a text input field, while?type="email"?specifies an email input field.
The?submit?button at the end of the form allows users to submit the form once they have entered all the required information.
Semantic Elements
Semantic elements are HTML tags that give meaning to the content on your web page, making it easier for search engines and screen readers to understand. HTML5 introduced a variety of semantic elements, including header, nav, article, section, aside, and footer. Each of these tags represents a specific section of a web page and can be used to structure your content.
To give you a better idea of what we mean, here’s a brief rundown of some HTML5 semantic elements:
Here's an example of how to use these semantic elements to structure a web page:
<header>
<h1>My Website</h1>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h2>About Us</h2>
<p>We are a company that specializes in creating beautiful and functional websites.</p>
</section>
<section>
<h2>Our Services</h2>
<ul>
<li>Web Design</li>
<li>Web Development</li>
<li>Search Engine Optimization</li>
</ul>
</section>
<aside>
<h2>Recent Posts</h2>
<ul>
<li><a href="#">5 Tips for Better Web Design</a></li>
<li><a href="#">The Benefits of Responsive Web Design</a></li>
<li><a href="#">How to Optimize Your Website for Search Engines</a></li>
</ul>
</aside>
</main>
<footer>
<p>© 2023 My Website. All rights reserved.</p>
</footer>
Next Steps
If you’re looking to advance your HTML skills even further, here are some suggestions for the next steps:
Thanks for completing this tutorial series, and wish you the best of luck in your web development journey!
?? Follow me for more web development tips and tutorials