Complete HTML Form Example

<form onsubmit="showData(event)" method="POST" >

<!-- Personal Information -->
    <fieldset>
        <legend>Personal Information</legend>

        <label for="name">Name:</label>
        <input type="text" id="name" name="name" placeholder="Enter your name" required>

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

        <p>Gender:</p>

        <label for="male">
            <input type="radio" id="male" name="gender" value="male" required> Male
        </label>

        <label for="female">
            <input type="radio" id="female" name="gender" value="female"> Female
        </label>
    </fieldset>

    <!-- Preferences -->
    <fieldset>
        <legend>Preferences</legend>

        <p>Skills:</p>

        <label>
            <input type="checkbox" name="skill[]" value="html"> HTML
        </label>

        <label>
            <input type="checkbox" name="skill[]" value="css"> CSS
        </label>

        <label>
            <input type="checkbox" name="skill[]" value="javascript"> JavaScript
        </label>
    </fieldset>

    <!-- Message -->
    <fieldset>
        <legend>Message</legend>

        <label for="message">Your Message:</label>
        <br>
        <textarea id="message" name="message" placeholder="Enter your message" rows="4" cols="30" required></textarea>
    </fieldset>

    <button type="submit">Submit</button>

</form>

<div id="result"></div>

Explanation:

Overall Structure

This is a complete HTML form used to collect user data such as:

<form onsubmit="showData(event)" method="POST">

Personal Information Section

<fieldset> 
    <legend>Personal Information</legend>

Name Input

<input type="text" placeholder="Enter your name" name="name" id="name" required>

Email Input

<input type="email" id="email" name="email" placeholder="Enter Your Email" required>

Gender (Radio Button)

<input type="radio" name="gender" value="male"> Male
    <input type="radio" name="gender" value="female"> Female

Preference Section

<fieldset>
    <legend>Preferences</legend>

Skills

<input type="checkbox" name="skill[]" value="html">

Message Section

<textarea id="message" name="message"></textarea>

Submit Button

<button type="submit">Submit</button>

Try it Yourself Button

<button class="tryBtn">Try it Yourself</button>

Conclusion

This example demonstrates how to create a complete HTML form using various input types such as text fields, radio buttons, checkboxes, and textarea. Understanding these elements is essential for collecting user data effectively and building interactive web applications.