HTML/HTML Components

HTML Forms (with Attributes)

Updated on January 6, 2026
1 min read

What is an HTML Form?

An HTML form is used to collect user input.

Examples:

  • Login form
  • Registration form
  • Contact form

Basic Form Structure

<form>
  <!-- form elements -->
</form>

Form Tag Attributes

1. action

Tells where form data is sent

<form action="submit.php">

2. method

Tells how data is sent

<form method="post">
MethodUse
getData visible in URL
postData hidden

3. target

<form target="_blank">

Form Elements

1. <input> Tag

Used to take user input.

Common Input Types & Attributes

Text Input

<input type="text" name="username" placeholder="Enter name">

Password Input

<input type="password" name="password">

Email Input

<input type="email" name="email">

Number Input

<input type="number" min="1" max="100">

Radio Button

<input type="radio" name="gender"> Male
<input type="radio" name="gender"> Female

Checkbox

<input type="checkbox"> HTML
<input type="checkbox"> CSS

Important <input> Attributes

AttributeUse
typeInput type
nameField name
valueDefault value
placeholderHint text
requiredMandatory
readonlyCannot edit
disabledDisabled field

2. <label> Tag

<label>Name:</label>
<input type="text">

3. <textarea>

<textarea rows="4" cols="30"></textarea>

4. <select> & <option>

<select>
  <option>HTML</option>
  <option>CSS</option>
</select>

5. <button>

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

Complete Example Form

<form action="save.php" method="post">
  <label>Name:</label>
  <input type="text" required>

  <label>Email:</label>
  <input type="email">

  <button>Submit</button>
</form>

Important Notes

  1. Always use name attribute
  2.  Use label for accessibility
  3.  Use post for sensitive data
HTML Forms (with Attributes) | HTML | Learn Syntax