Skip to main content
D
HTML
HTML Forms

HTML Forms

HTML forms collect user input securely.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

HTML uses the `
` element to gather data from the user. It wraps various input fields like text boxes and checkboxes. The browser sends this collected data to a server when the user clicks submit.

Syntax

Syntax
1<!-- form syntax -->
2<form action="/submit" method="POST">
3  <input type="text" name="user">
4</form>

Example

Example
1<!-- this creates a form -->
2<!DOCTYPE html>
3<html lang="en">
4  <head>
5    <meta charset="UTF-8">
6    <meta name="viewport" content="width=device-width, initial-scale=1.0">
7    <title>Forms</title>
8  </head>
9  <body>
10    <form action="/login" method="POST">
11      <label for="username">Name:</label>
12      <input type="text" id="username" name="username">
13      <button type="submit">Submit</button>
14    </form>
15  </body>
16</html>

Try it Yourself

Hands-on Practice
Modify the code below to see how it affects the output. This is the best way to learn!
Interactive Editor
1234567891011121314151617181920
Live Preview

Key Points

  • The `` tag wraps input elements.
  • Forms collect data for processing.
  • The `action` attribute sets the destination URL.
  • The `method` attribute defines the HTTP request.

Up Next

Continue your journey with the next topic.

Go to HTML Form Attributes