HTML <form> Tag

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Forms & Controls

What You’ll Learn

By the end of this tutorial, you’ll build interactive forms that collect and submit user input with semantic HTML.

The HTML <form> tag is a cornerstone element in web development, empowering developers to create interactive and user-friendly web forms. This guide covers syntax, attributes, accessibility, and best practices for beginners and web developers alike.

01

Core Syntax

Wrap controls in <form> opening and closing tags.

02

action & method

Send data to a URL with GET or POST.

03

Text Inputs

Collect names, emails, and usernames.

04

Textarea

Capture multi-line messages and comments.

05

Submit Buttons

Trigger form submission to the server.

06

Labels & name

Accessible, submittable form controls.

What Is the <form> Tag?

The form element (<form>) encapsulates interactive controls for collecting user input. It provides the structure for input fields, textareas, selects, buttons, and other elements, and defines where and how data is sent when the user submits the form.

💡
Every control needs a name

Only form controls with a name attribute are included in submission data. Always pair inputs with label and name for accessibility and server handling.

Forms facilitate communication between users and web servers. You can also handle submission with JavaScript using the submit event, but the semantic form element remains the foundation.

📝 Syntax

Encapsulate form elements within opening and closing <form> tags:

syntax.html
<form action="/submit" method="post">
  <!-- Your form elements go here -->
</form>

Syntax Rules

  • Place all related controls inside one form element.
  • Set action to the URL that processes the data.
  • Use method="post" for sensitive or large submissions; get for searches.
  • Include a submit control (button type="submit" or input type="submit").

⚡ Quick Reference

PatternCode SnippetNotes
Basic form<form action="/submit" method="post">Standard submission
Text input<input type="text" name="username">Single-line text
Textarea<textarea name="message"></textarea>Multi-line text
Submit<button type="submit">Submit</button>Sends the form
Label pairing<label for="id">...</label>Required for a11y
Default methodgetUse post for sensitive data

⚖️ <form> vs <div>

Both can wrap inputs visually, but only form handles submission semantics:

Feature<form><div>
Semantic roleForm submission containerGeneric container
Submit behaviorEnter key and submit button work nativelyRequires manual JavaScript
action / methodBuilt-in attributesNot available
Best forLogin, contact, search, checkoutLayout-only groupings

⚖️ method="get" vs method="post"

Choose the HTTP method based on what the form does:

MethodData locationWhen to use
getAppended to URL as query stringSearch boxes, filters, bookmarkable queries
postSent in request bodyLogin, registration, contact forms, file uploads
Security noteNever send passwords with GET — use POST over HTTPS
DefaultgetExplicitly set method="post" when needed

🧰 Attributes

The <form> tag supports these key attributes plus global attributes such as class and id:

action Required*

URL where form data is sent on submit. Use a server endpoint or handler script.

action="/submit-form"
method HTTP

HTTP verb: get or post. Defaults to get.

method="post"
enctype Uploads

Encoding type. Use multipart/form-data when uploading files.

enctype="multipart/form-data"
name / id Global

Identify the form for scripting or associating external controls via form attribute.

id="signup-form"
autocomplete UX

Enable or disable browser autofill for the entire form.

autocomplete="on"
novalidate Boolean

Skip built-in browser validation (you may validate with JavaScript instead).

novalidate
attributes.html
<form action="/submit-form" method="post" id="contact-form">
  <!-- Your form elements go here -->
</form>

Avoid target="_blank" on forms unless necessary. If used, add rel="noopener" on any resulting navigation for security.

Examples Gallery

Contact forms, text inputs, textareas, and submit buttons with copy-ready code and live previews.

Live Preview

A simple contact form with name, email, and submit button:

Contact Form with action and method

A complete form that sends name and email to a server endpoint using POST.

contact-form.html
<form action="/submit-form" method="post">
  <label for="name">Name:</label>
  <input type="text" id="name" name="name">

  <label for="email">Email:</label>
  <input type="email" id="email" name="email">

  <button type="submit">Submit</button>
</form>
Try It Yourself

📚 Common Use Cases

Use <form> for login and registration, contact and feedback forms, search bars, newsletter signups, checkout flows, survey questions, and any page where users enter data that should be sent to a server or processed by JavaScript.

Text Input

Use the <input> element with type="text" to create a single-line text field inside a form.

text-input.html
<form>
  <label for="username">Username:</label>
  <input type="text" id="username" name="username">
</form>
Try It Yourself

Textarea

For multi-line text input, use the <textarea> element inside a form.

textarea.html
<form>
  <label for="message">Message:</label>
  <textarea id="message" name="message" rows="4" cols="50"></textarea>
</form>
Try It Yourself

Submit Button

Include a submit button so users can send the form. The button must have type="submit" and live inside the form.

submit-button.html
<form action="/submit-form" method="post">
  <label for="username">Username:</label>
  <input type="text" id="username" name="username">

  <button type="submit">Submit</button>
</form>
Try It Yourself

Styling <form> with CSS

Style the form container and its controls for a polished user experience:

max-width Readable form width
label Clear field labels
input:focus Focus ring on fields
button Primary submit style
form-styles.css
/* Form container */
form.contact-form {
  max-width: 420px;
  padding: 1.25rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
}

form label {
  display: block;
  margin: 0.65rem 0 0.25rem;
  font-size: 0.8125rem;
  font-weight: 500;
}

form input,
form textarea {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

form button[type="submit"] {
  margin-top: 0.75rem;
  padding: 0.5rem 1rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

Live styled form

♿ Accessibility

Accessible forms work for keyboard and screen reader users:

  • Label every field — use label for="id" matching the control’s id.
  • Use meaningful names — the name attribute identifies data on submit.
  • Group related fields — use fieldset and legend for sections.
  • Validate on server — never rely on client validation alone for security.

🧠 How <form> Works

1

Author builds the form

Add labeled inputs, textareas, and a submit button inside form.

Markup
2

User fills in fields

Browser collects values from named controls as the user types.

Interaction
3

Form is submitted

Submit sends data to action using method (GET or POST).

Submission
=

Data reaches the server

The backend processes input and responds with a new page or JSON.

Universal Browser Support

The <form> element is fully supported in all browsers, including legacy Internet Explorer.

Baseline · Since HTML 4

Forms that work everywhere

From legacy Internet Explorer to the latest mobile browsers — the form element is a foundational building block for interactive web pages.

100% Core tag support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
<form> tag 100% supported

Bottom line: Ship interactive forms with confidence. The <form> element is safe to use in every production environment today.

Conclusion

Mastering the HTML <form> tag is fundamental for creating dynamic and user-friendly web forms. By understanding its syntax, attributes, and best practices, you’ll build effective forms that enhance user interaction on your website.

Always use labels and name attributes, choose GET or POST appropriately, validate on the server, and pair forms with related tags like fieldset, button, and label.

💡 Best Practices

✅ Do

  • Use proper label elements for every field
  • Set name on all submittable controls
  • Use method="post" for sensitive data
  • Validate input on both client and server

❌ Don’t

  • Submit passwords with method="get"
  • Skip labels and rely on placeholder text alone
  • Wrap unrelated page content in a form
  • Trust client-side validation for security

Key Takeaways

Knowledge Unlocked

Six truths every developer should know about <form>

Bookmark these before you ship — they’ll keep your forms usable and secure.

6
Core concepts
🔗 02

action URL

Where submitted data is sent.

Attribute
📥 03

GET vs POST

Choose method for search vs sensitive data.

HTTP
🏷️ 04

name Required

Only named fields are submitted.

Submission
05

Labels Matter

Pair every input with a label.

Accessibility
🌐 06

Universal Support

Works in every browser, including legacy IE.

Compatibility

❓ Frequently Asked Questions

It collects user input and sends it to a server. It wraps inputs, textareas, selects, buttons, and other controls.
It specifies the URL where form data is sent when the user submits the form.
GET puts data in the URL (good for searches). POST sends data in the request body (preferred for login and sensitive submissions).
Yes. Only controls with a name attribute are included when the form is submitted.
Yes. The form element is fully supported in all modern browsers and Internet Explorer.

Build Interactive Forms

Create contact forms with labels, inputs, and submit buttons in the HTML editor.

Try contact form →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful