HTML <input> Tag

Beginner
⏱️ 7 min read
📚 Updated: Jun 2026
🎯 6 Examples
Forms & Input

What You’ll Learn

By the end of this tutorial, you’ll create interactive form controls with the <input> element — text fields, passwords, checkboxes, radio buttons, and submit buttons.

The <input> tag is a versatile HTML element for user interaction in forms. This guide covers syntax, input types, attributes, accessibility, and best practices for beginners and web developers alike.

01

Core Syntax

Set type to define the control behavior.

02

Input Types

Text, password, checkbox, radio, submit, and more.

03

Key Attributes

Use name, id, value, and placeholder.

04

Labels

Connect label to inputs for accessibility.

05

Validation

Mark required fields and match types to data.

06

Form Context

Place inputs inside form for submission.

What Is the <input> Tag?

The input element (<input>) creates form controls that let users enter data or make selections on a web page. It is a void element — it has no closing tag and does not wrap child content.

💡
The type attribute defines behavior

type="text" shows a text field. type="checkbox" toggles an option. type="submit" sends the form. Always set the appropriate type for the data you collect.

Inputs usually live inside a <form> element so their values can be submitted to a server. Pair every input with a <label> (or accessible name) so users and assistive technologies understand each field.

📝 Syntax

Specify the type attribute to define the kind of form control:

syntax.html
<input type="text" placeholder="Enter your text here">

Syntax Rules

  • input is a void element — no </input> closing tag in HTML.
  • The type attribute determines control behavior (defaults to text if omitted).
  • Use name so the field value is included when the form is submitted.
  • Connect label for to input id for accessible field names.
  • Wrap related inputs in a form with action and method for submission.

⚡ Quick Reference

typePurposeExample
textSingle-line textUsername, search box
passwordMasked text entryLogin password
emailEmail address with validationContact form email
checkboxOn/off toggleAgree to terms
radioOne of a groupGender selection
submitSubmit the formSend button
hiddenNon-visible dataCSRF token

⚖️ <input> vs <textarea>

Both collect text, but serve different needs:

Feature<input><textarea>
Element typeVoid elementContainer with closing tag
Text lengthSingle lineMulti-line paragraphs
Common typestext, email, password, numberPlain multi-line text only
Default contentVia value attributeBetween opening and closing tags

⚖️ input type="submit" vs <button>

Both can submit forms, but buttons are more flexible:

Featureinput submitbutton
Labelvalue attributeHTML content inside element
StylingLimited by browser defaultsIcons and nested markup allowed
Non-submit actionsNotype="button" or reset
RecommendationSimple legacy formsPreferred for modern UIs

🧰 Attributes

Common <input> attributes plus global attributes such as class and disabled:

type Required

Defines the control: text, password, checkbox, radio, submit, email, etc.

type="text"
name Required

Identifies the field when form data is submitted.

name="username"
id Accessibility

Unique identifier linked to label for and scripting.

id="username"
value Data

Initial or submitted value; label text for submit buttons.

value="Submit"
placeholder Hint

Short hint shown when the field is empty — not a replacement for labels.

placeholder="Your name"
required Validation

Browser blocks submission until the field has a value.

required
attributes.html
<input
  type="text"
  name="fullname"
  id="fullname"
  placeholder="Your full name"
  required
>

Use autocomplete on login fields, min/max on number inputs, and pattern for custom validation when needed.

Examples Gallery

Attributes, text fields, passwords, checkboxes, radio buttons, and submit inputs with copy-ready code and live previews.

Live Preview

Text input with label and placeholder inside a styled form:

Input Attributes

Combine name, id, placeholder, and required on a text field.

attributes.html
<input type="text" name="fullname" id="fullname" placeholder="Your full name" required>
Try It Yourself

📚 Common Use Cases

Use <input> for login forms, search boxes, surveys, settings toggles, and payment fields. Match each type to the data you need and always provide accessible labels.

Basic Text Input

Create a labeled text field for usernames or other single-line text.

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

Password Input

Mask characters during entry with type="password".

password-input.html
<label for="password">Password:</label>
<input type="password" id="password" name="password" autocomplete="current-password">
Try It Yourself

Checkbox

Let users agree to terms or toggle an on/off option.

checkbox.html
<input type="checkbox" id="agree" name="agree" value="yes">
<label for="agree">I agree to the terms and conditions</label>
Try It Yourself

Radio Buttons

Offer mutually exclusive options with the same name and unique id values.

radio-buttons.html
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label>
Try It Yourself

Submit Button

Send form data with type="submit". Place it inside a form element.

submit-button.html
<form action="/submit" method="post">
  <input type="submit" value="Submit">
</form>
Try It Yourself

Styling <input> with CSS

Style form controls for a polished, accessible user experience:

width: 100% Full-width fields
:focus Visible focus ring
border-radius Rounded inputs
:disabled Muted inactive state
input-styles.css
/* Text inputs */
input[type="text"],
input[type="email"],
input[type="password"] {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.875rem;
}

input:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-color: #2563eb;
}

input:disabled {
  background: #f1f5f9;
  color: #94a3b8;
  cursor: not-allowed;
}

Styled input preview

♿ Accessibility

Form inputs must be usable for keyboard and screen reader users:

  • Always use labels — connect label for to input id.
  • Don’t rely on placeholder alone — placeholders disappear when typing and are not a substitute for labels.
  • Group related radios — use fieldset and legend for radio and checkbox groups when helpful.
  • Visible focus — ensure keyboard users can see which field is active.
  • Error messages — link validation errors to fields with aria-describedby when using custom validation.

🧠 How <input> Works

1

Author defines type and name

Set type for behavior and name for form submission.

Markup
2

User enters or selects data

The browser renders the appropriate control and captures the user’s input.

Interaction
3

Form submits name/value pairs

On submit, checked/ filled inputs send their name and value to the server.

Submission
=

Interactive form data

User input is captured and ready for processing on the server or in JavaScript.

Universal Browser Support

The <input> element is fully supported in all browsers. Some newer input types may fall back to text in very old browsers.

Baseline · Since HTML 2

Form controls that work everywhere

From legacy Internet Explorer to the latest mobile browsers — the input element is foundational for web forms.

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
<input> tag 100% supported

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

Conclusion

Mastering the <input> tag is essential for building interactive, user-friendly forms in HTML. By understanding input types, attributes, and accessibility patterns, you can capture data effectively and create better user experiences.

Always pair inputs with labels, choose the right type, validate with required where appropriate, and place controls inside a form for submission.

💡 Best Practices

✅ Do

  • Provide meaningful label elements for every input
  • Match type to the expected data (email, number, date)
  • Use required for mandatory fields
  • Give radio groups the same name

❌ Don’t

  • Rely on placeholder as the only field label
  • Forget name on fields that should submit data
  • Use type="text" when a semantic type fits better
  • Leave inputs without visible focus styles

Key Takeaways

Knowledge Unlocked

Six truths every developer should know about <input>

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

6
Core concepts
02

Void Element

No closing tag in HTML syntax.

Syntax
03

Labels Required

Connect label for to input id.

Accessibility
🔗 04

name for Submission

Form data uses the name attribute.

Forms
05

Validate Early

Use required and matching types.

Validation
06

Universal Support

Works in every browser today.

Compatibility

❓ Frequently Asked Questions

It creates form controls for user data entry and selection. The type attribute determines the control behavior.
input is a void element with no closing tag in HTML. It does not wrap content like textarea.
Radios with the same name form a group where only one option can be selected. Each radio still needs a unique id for its label.
input handles single-line controls and buttons. textarea is for multi-line text with opening and closing tags.
button type="submit" is preferred for modern forms because it supports richer content and styling. input type="submit" still works for simple cases.

Practice HTML Form Controls

Try text fields, passwords, checkboxes, radio buttons, and submit inputs in the interactive editor.

Try text input example →

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