codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🎨

HTML & CSS

10 / 59 topics
1Introduction to HTML2HTML Elements3HTML Attributes4HTML Document Structure5HTML Text Formatting6HTML Links7HTML Images8HTML Lists9HTML Tables10HTML Forms
Tutorials/HTML & CSS/HTML Forms
🎨HTML & CSS

HTML Forms

Updated 2026-05-15
10 min read

HTML Forms

Introduction

Forms are a fundamental part of web development, allowing users to interact with your website by submitting data. This tutorial will guide you through creating and structuring forms in HTML, covering both basic and advanced concepts.

Concept

HTML provides several elements to create interactive forms:

  • <form>: The container for all form elements.
  • <input>: For various types of user input like text, email, password, etc.
  • &lt;textarea&gt;: For multi-line text input.
  • &lt;select&gt;: For dropdown lists.
  • &lt;button&gt;: For submitting or resetting the form.

Examples

Basic Form Structure

Let's start with a simple form that includes a text input and a submit button.

HTML
1<form action="/submit" method="post">
2<label for="name">Name:</label>
3<input type="text" id="name" name="name"><br><br>
4<button type="submit">Submit</button>
5</form>

Input Types

HTML provides various input types to handle different kinds of data:

  • type="text": For single-line text.
  • type="email": Validates email format.
  • type="password": Hides the input for security.
HTML
1<form action="/submit" method="post">
2<label for="name">Name:</label>
3<input type="text" id="name" name="name"><br><br>
4
5<label for="email">Email:</label>
6<input type="email" id="email" name="email"><br><br>
7
8<label for="password">Password:</label>
9<input type="password" id="password" name="password"><br><br>
10
11<button type="submit">Submit</button>
12</form>

Textarea

For multi-line text input, use the &lt;textarea&gt; element.

HTML
1<form action="/submit" method="post">
2<label for="message">Message:</label><br>
3<textarea id="message" name="message" rows="4" cols="50"></textarea><br><br>
4
5<button type="submit">Submit</button>
6</form>

Select Dropdown

The &lt;select&gt; element creates a dropdown list.

HTML
1<form action="/submit" method="post">
2<label for="country">Country:</label><br>
3<select id="country" name="country">
4 <option value="usa">USA</option>
5 <option value="canada">Canada</option>
6 <option value="uk">UK</option>
7</select><br><br>
8
9<button type="submit">Submit</button>
10</form>

Form Attributes

You can add various attributes to the &lt;form&gt; element to control its behavior:

  • action: The URL where form data is sent.
  • method: The HTTP method used (e.g., "post", "get").
  • enctype: Specifies how form data should be encoded when submitted.
HTML
1<form action="/submit" method="post" enctype="multipart/form-data">
2<!-- Form elements go here -->
3</form>

Validation

HTML5 provides built-in validation for input fields:

  • required: Ensures the field must be filled out before submission.
  • minlength and maxlength: Specify minimum and maximum length of text.
HTML
1<form action="/submit" method="post">
2<label for="username">Username:</label>
3<input type="text" id="username" name="username" required minlength="5" maxlength="20"><br><br>
4
5<button type="submit">Submit</button>
6</form>

What's Next?

Now that you have a good understanding of HTML forms, the next step is to learn about CSS positioning. This will allow you to style and layout your forms effectively.

Stay tuned for more tutorials!


PreviousHTML TablesNext HTML Semantic Elements

Recommended Gear

HTML TablesHTML Semantic Elements