Welcome to the final lesson in our "Web Fundamentals" module. In our previous lesson, we masterfully assembled the static structure of a webpage—a complete layout with a header, main content area, and a "sticky" footer—using the power of CSS Flexbox. You now have a solid foundation for creating the visual skeleton of a website.
Today, we will bring that static structure to life by adding the primary mechanism for user interaction on the web: HTML forms. This lesson will equip you with the knowledge to create forms that can collect various types of user input, from simple text to multiple-choice selections. Mastering forms is the last piece of the puzzle in our web fundamentals journey and a critical prerequisite for building the interactive applications you aim to create with Leptos.
The Anatomy of a Form
At its core, an HTML form is a collection of interactive controls that allows a user to submit information to a web server. Every form you've ever filled out online—from a simple search bar to a complex registration page—is built with these fundamental elements.
The entire structure is wrapped in a <form> element. This element acts as a container and has two crucial attributes:
action: This specifies the URL where the form data should be sent for processing when the user submits it.method: This defines the HTTP method to be used for sending the data. The two most common methods areGET(appends data to the URL, visible to the user) andPOST(sends data in the request body, not visible in the URL).
Inside the <form>, we place various input controls. The most versatile is the <input> element. However, for an input to be useful, it needs two things: a label to tell the user what to enter, and a name so the server knows how to identify the submitted data.
Let's watch a short segment that explains these foundational concepts.
Learn HTML Forms In 25 Minutes
This video by Web Dev Simplified provides a clear walkthrough of the essential form attributes.
Please watch the section from the form attributes explanation. Pay close attention to: The purpose of the action and method attributes on the <form> tag. The critical role of the name attribute on an <input> for data submission. The two ways to associate a <label> with an <input>: using the for and id attributes, or by nesting.
The video mentions two ways to link a label to an input. The recommended and most robust method is using the for attribute on the <label> and a matching id attribute on the <input>. This explicit connection is excellent for accessibility (screen readers can announce the label when the user focuses on the input) and usability (clicking the label focuses the cursor in the input field).
Let's read a quick clarification on why this explicit labeling is preferred.
Forms and buttons in HTML - Learn web development
This MDN article is a great reference for all things forms. We'll focus on the section explaining labels.
Please read the part of the article under the heading <label> elements. Focus on the distinction between "explicit" and "implicit" labels and the reasons why the explicit approach is generally better.
Common Input Types
The <input> element is a chameleon. Its behavior changes dramatically based on its type attribute. We've already seen the basic type="text", but there are many others designed for specific kinds of data. Using the correct type not only provides a better user experience but also enables browsers to perform built-in validation.

This login form, for instance, would use <input type="text"> for the username and <input type="password"> for the password. The password type automatically masks the characters as the user types.
Let's explore some of the most common and useful input types.
Learn HTML Forms In 25 Minutes
We'll return to the Web Dev Simplified video to see a demonstration of several specialized input types.
Watch the segment from the input types overview. Observe how each type provides a different user interface and validation: email: Enforces a basic email format. number: Provides up/down arrows and can have min, max, and step attributes. date: Shows a calendar-based date picker.
Multi-line Text: The <textarea>
For longer-form text input, like a comments section, a single-line <input> isn't sufficient. For this, we use the <textarea> element. Unlike <input>, it has both an opening and a closing tag. You can set its default size with the rows and cols attributes.
Learn HTML forms in 10+ minutes! 📝
This video from Bro Code gives a quick and clear demonstration of the <textarea> element.
Watch the short segment on the text area. Notice how it's a separate element from <input> and how its dimensions can be controlled.
Inputs for Making Choices
Often, you don't want freeform text but need to guide the user to select from a predefined set of options. HTML provides three main ways to do this.
- Radio Buttons (
<input type="radio">): Used when a user must select exactly one option from a group. All radio buttons in a group must share the samenameattribute. - Checkboxes (
<input type="checkbox">): Used when a user can select zero, one, or multiple options from a group. Each checkbox typically has a uniquename. - Dropdown Menus (
<select>and<option>): A space-saving way to present a list of options. The<select>element is the container, and each choice is an<option>element nested inside.
The following resource contains a great example form that uses all three of these.
Forms and buttons in HTML - Learn web development
The MDN guide provides a rich example of a registration form for a meetup, which is perfect for seeing these choice-based controls in action.
First, look at the complete HTML code under the heading Other control types. Then, read the explanations for the following sections to understand how each control works: Radio buttons: Pay special attention to how the shared name="hotel" attribute groups the radio buttons together. Checkboxes: Note how these differ from radio buttons, allowing multiple selections. Drop-down menus: Understand the relationship between the parent <select> element and its child <option> elements.
Submitting the Form
Finally, a form needs a way to be submitted. This is done with a button. You can use <input type="submit">, but the more flexible and modern approach is to use the <button> element. By default, a <button> inside a <form> will act as a submit button.
You can also create a button with type="reset", which will clear all form fields back to their initial values.
Putting It All Together: A Registration Form
Theory is essential, but practice is where the learning solidifies. Let's walk through the creation of a complete registration form for a fictional conference. This will combine everything we've learned: text inputs, email inputs, select menus, textareas, and submit buttons, along with helpful attributes like required and placeholder.
Building Forms - Learn to Code HTML & CSS
The "In Practice" section of this tutorial by Shay Howe is an excellent hands-on exercise. It guides you through building a well-structured and practical form from scratch.
Follow the step-by-step guide in the section titled In Practice. You can create a new register.html file and style.css file to build this yourself. The key part for our learning outcome is Step 6, where the form itself is constructed. Pay close attention to: How <label> is used for every single form control. The use of <input type="text"> and <input type="email">. The use of the required attribute to make fields mandatory. The placeholder attribute providing hints to the user. The construction of the <select> menu for "Number of Passes". The final <input type="submit"> to create the purchase button.
Conclusion
Congratulations on completing the "Web Fundamentals" module! You started with the basic client-server model and now have the skills to build a structured, styled, and interactive webpage using HTML and CSS.
Key Takeaways from this Lesson:
- HTML forms are created using the
<form>element, which acts as a container for user input controls. - The
<input>element is highly versatile, with itstypeattribute determining its function (e.g.,text,password,email,number,checkbox,radio). <label>elements are crucial for accessibility and usability, and should be explicitly linked to their controls using theforandidattributes.- For multi-line text and dropdown lists, we use the dedicated
<textarea>and<select>/<option>elements, respectively. - A
<button>or<input type="submit">is used to send the collected form data to the server location specified in the form'sactionattribute.
Next Up:
You have now built a solid launchpad of web fundamentals. You understand the structure (HTML), the style (CSS), and the interaction (Forms). It's time to launch into the core of this course. In our next lesson, we will begin Module 2: Getting Started with Leptos. You'll discover what Leptos is, how it revolutionizes building web UIs with Rust, and write your very first Leptos component. Prepare to see how the HTML elements you've just learned are created programmatically and dynamically.