An HTML form is a way to collect and submit data from users on a webpage. When you fill out things like search bars, login fields, contact forms, or sign-up pages, you are interacting with an HTML form.
Here’s what it does:
i.Collects user input: Forms allow users to type in text, select options, upload files, or choose items (like checkboxes or radio buttons).
ii.Sends data: Once submitted, the form sends the collected data to a server for processing. This could be to sign up for a website, post a comment, or make a purchase.
For example:
1. Login form: Collects your username and password, sends it to the server for verification.
2.Contact form: Lets you send a message to the website admin (name, email, message).
3.Search bar: Allows you to search for content on the site.
method: How data is sent — GET (visible in URL) or POST (hidden)
<input>: The element for user input.
⚙️ Form Attributes Summary:
action=> URL to send the form data to
method=> HTTP method: get or post
enctype=> Encoding type (e.g., multipart/form-data=> for file uploads)
target=> Where to open response (_self, _blank, etc.)
autocomplete=> Enable or disable browser auto-fill,
The required, minlength, and maxlength attributes enforce client-side validation.
Sample Form: Using All Types of <input> Elements=>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample Form with All Input Types</title>
</head>
<body>