Course Content
Introduction to HTML
In this introductory module, you'll learn what HTML is and its role in web development. You will set up your development environment and create your first HTML page. You'll also understand the basic structure of an HTML document and get familiar with fundamental HTML elements and attributes.
0/4
Working with Text in HTML
This module covers how to format text in HTML, including creating headings, paragraphs, and lists. You'll learn how to emphasize text with bold, italics, and underline, and how to create links for navigation. You'll also explore text alignment and introduce inline CSS for basic styling.
0/4
Working with Images and Multimedia
In this module, you’ll learn how to add images and multimedia to your HTML pages. You'll master the <img> tag, and understand how to work with attributes like src and alt. Additionally, you'll discover how to embed audio and video files directly into your webpage, enhancing its interactivity.
0/3
Tables and Forms in HTML
This module introduces the use of tables for displaying structured data and forms for collecting user input. You'll learn how to create, format, and style tables, and how to build forms with input fields, checkboxes, and buttons. Basic HTML5 form validation will also be covered.
0/2
HTML5 Elements and Semantic Markup
Explore the power of HTML5 in this module, where you’ll learn about new HTML5 elements like <article>, <section>, and <nav>. You’ll gain an understanding of semantic HTML, which helps improve search engine optimization (SEO) and accessibility. You’ll also be introduced to HTML5-specific features such as video and audio embedding.
0/3
Advanced HTML Concepts
This module dives deeper into advanced HTML topics, including embedding external content using [iframe], working with HTML5 APIs like geolocation, and implementing accessibility best practices with ARIA attributes. You’ll also get a primer on responsive web design with the use of meta tags and media queries.
0/4
HTML Best Practices
Learn the best practices for writing clean, maintainable, and accessible HTML. This module covers proper code formatting, the importance of semantic HTML, and how to structure your HTML for SEO. You’ll also get practical tips on debugging HTML and using online validators to ensure your code is error-free.
0/3
Project – Building a Simple Website
Apply everything you’ve learned by creating a complete website from scratch in this hands-on project. You’ll plan, design, and build a multi-page website, incorporating text, images, forms, and navigation. This project will help you solidify your skills and showcase your work.
0/4
Conclusion and Next Steps
In the final module, you'll review the key concepts and skills you’ve learned throughout the course. You’ll also get guidance on the next steps in your web development journey, including an introduction to CSS for styling and JavaScript for interactivity. You’ll complete a final assessment to demonstrate your new HTML skills.
0/2
Complete HTML Course (Free)
About Lesson

Working with Forms

This lesson introduces you to HTML forms, a crucial feature for collecting user input. You will learn how to create forms, use various input types, and customize form elements to enhance usability.


1. What is an HTML Form?

An HTML form is a structure that allows users to input data, which can then be submitted to a server for processing. Common examples include login forms, registration forms, and search bars.

Basic Syntax:

<form action="submit_page.html" method="POST">
    <!-- Form elements go here -->
</form>
  • action: Specifies the URL where form data will be sent.
  • method: Defines how data is sent (GET or POST).

2. Common Form Elements

  1. Text Input:

    • Used for single-line text input.
    <input type="text" name="username" placeholder="Enter your name">
    
  2. Password Input:

    • Hides user input for passwords.
    <input type="password" name="password" placeholder="Enter your password">
    
  3. Email Input:

    • Validates email format.
    <input type="email" name="email" placeholder="Enter your email">
    
  4. Number Input:

    • Allows numeric input with optional min/max values.
    <input type="number" name="age" min="1" max="100">
    
  5. Date Input:

    • Displays a date picker.
    <input type="date" name="dob">
    
  6. Radio Buttons:

    • Allows selecting one option from a group.
    <input type="radio" name="gender" value="male"> Male
    <input type="radio" name="gender" value="female"> Female
    
  7. Checkboxes:

    • Allows selecting multiple options.
    <input type="checkbox" name="hobby" value="reading"> Reading
    <input type="checkbox" name="hobby" value="traveling"> Traveling
    
  8. Dropdown/Select:

    • Provides a dropdown menu for selecting options.
    <select name="country">
        <option value="usa">United States</option>
        <option value="uk">United Kingdom</option>
    </select>
    
  9. Textarea:

    • Allows multi-line text input.
    <textarea name="message" rows="4" cols="30" placeholder="Enter your message"></textarea>
    
  10. Submit Button:

    • Submits the form.
    <input type="submit" value="Submit">
    

3. Example: Simple Form

<!DOCTYPE html>
<html>
<head>
    <title>Simple Form</title>
</head>
<body>
    <h1>Registration Form</h1>
    <form action="submit_form.html" method="POST">
        <label for="username">Name:</label>
        <input type="text" id="username" name="username" placeholder="Enter your name" required><br><br>

        <label for="email">Email:</label>
        <input type="email" id="email" name="email" placeholder="Enter your email" required><br><br>

        <label for="password">Password:</label>
        <input type="password" id="password" name="password" placeholder="Enter your password" required><br><br>

        <label for="gender">Gender:</label>
        <input type="radio" id="male" name="gender" value="male">
        <label for="male">Male</label>
        <input type="radio" id="female" name="gender" value="female">
        <label for="female">Female</label><br><br>

        <label for="hobby">Hobbies:</label>
        <input type="checkbox" id="reading" name="hobby" value="reading">
        <label for="reading">Reading</label>
        <input type="checkbox" id="traveling" name="hobby" value="traveling">
        <label for="traveling">Traveling</label><br><br>

        <input type="submit" value="Register">
    </form>
</body>
</html>

4. Styling Forms with CSS

CSS can make forms visually appealing and user-friendly.

Example:

<style>
    form {
        max-width: 400px;
        margin: auto;
        padding: 20px;
        border: 1px solid #ccc;
        border-radius: 5px;
        background: #f9f9f9;
    }
    label {
        display: block;
        margin: 10px 0 5px;
    }
    input, select, textarea {
        width: 100%;
        padding: 10px;
        margin: 5px 0 15px;
        border: 1px solid #ccc;
        border-radius: 4px;
    }
    input[type="submit"] {
        background: #4CAF50;
        color: white;
        border: none;
        cursor: pointer;
    }
    input[type="submit"]:hover {
        background: #45a049;
    }
</style>

5. Form Validation

Modern browsers provide basic validation for certain input types, but you can enhance validation with attributes and JavaScript.

Common Validation Attributes:

  1. required: Ensures a field is filled out.

    <input type="text" name="username" required>
    
  2. pattern: Specifies a regex pattern for validation.

    <input type="text" name="zipcode" pattern="[0-9]{5}" placeholder="Enter 5-digit ZIP code">
    
  3. min and max: Sets numeric range.

    <input type="number" name="age" min="18" max="99">
    

6. Best Practices for Forms

  1. Use Descriptive Labels:

    • Ensure each input has a label for accessibility.
  2. Group Related Fields:

    • Use <fieldset> and <legend> to group related fields.
    <fieldset>
        <legend>Personal Information</legend>
        <!-- Fields go here -->
    </fieldset>
    
  3. Provide Clear Feedback:

    • Use placeholder text or tooltips to guide users.
  4. Secure Data Submission:

    • Use HTTPS to secure form data.

7. Hands-On Activity: Creating a Feedback Form

  1. Task: Create a feedback form with the following fields:
    • Name
    • Email
    • Rating (1–5)
    • Comments
  2. Include: CSS styling, validation attributes, and a submit button.

Example Output: A styled feedback form that collects and validates user input before submission.


8. Summary

  • HTML forms are essential for collecting user data.
  • Use various input types like text, email, radio, and checkboxes for versatility.
  • Enhance forms with CSS for improved usability and appearance.
  • Implement validation to ensure accurate and complete data collection.