Live Preview
Text input with label and placeholder inside a styled form:

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.
Set type to define the control behavior.
Text, password, checkbox, radio, submit, and more.
Use name, id, value, and placeholder.
Connect label to inputs for accessibility.
Mark required fields and match types to data.
Place inputs inside form for submission.
<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.
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.
Specify the type attribute to define the kind of form control:
<input type="text" placeholder="Enter your text here">input is a void element — no </input> closing tag in HTML.type attribute determines control behavior (defaults to text if omitted).name so the field value is included when the form is submitted.label for to input id for accessible field names.form with action and method for submission.| type | Purpose | Example |
|---|---|---|
text | Single-line text | Username, search box |
password | Masked text entry | Login password |
email | Email address with validation | Contact form email |
checkbox | On/off toggle | Agree to terms |
radio | One of a group | Gender selection |
submit | Submit the form | Send button |
hidden | Non-visible data | CSRF token |
<input> vs <textarea>Both collect text, but serve different needs:
| Feature | <input> | <textarea> |
|---|---|---|
| Element type | Void element | Container with closing tag |
| Text length | Single line | Multi-line paragraphs |
| Common types | text, email, password, number | Plain multi-line text only |
| Default content | Via value attribute | Between opening and closing tags |
Common <input> attributes plus global attributes such as class and disabled:
type RequiredDefines the control: text, password, checkbox, radio, submit, email, etc.
type="text"name RequiredIdentifies the field when form data is submitted.
name="username"id AccessibilityUnique identifier linked to label for and scripting.
id="username"value DataInitial or submitted value; label text for submit buttons.
value="Submit"placeholder HintShort hint shown when the field is empty — not a replacement for labels.
placeholder="Your name"required ValidationBrowser blocks submission until the field has a value.
required<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.
Attributes, text fields, passwords, checkboxes, radio buttons, and submit inputs with copy-ready code and live previews.
Text input with label and placeholder inside a styled form:
Combine name, id, placeholder, and required on a text field.
<input type="text" name="fullname" id="fullname" placeholder="Your full name" required>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.
Create a labeled text field for usernames or other single-line text.
<label for="username">Username:</label>
<input type="text" id="username" name="username">Mask characters during entry with type="password".
<label for="password">Password:</label>
<input type="password" id="password" name="password" autocomplete="current-password">Let users agree to terms or toggle an on/off option.
<input type="checkbox" id="agree" name="agree" value="yes">
<label for="agree">I agree to the terms and conditions</label>Offer mutually exclusive options with the same name and unique id values.
<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>Send form data with type="submit". Place it inside a form element.
<form action="/submit" method="post">
<input type="submit" value="Submit">
</form>Style form controls for a polished, accessible user experience:
width: 100% Full-width fields:focus Visible focus ringborder-radius Rounded inputs:disabled Muted inactive state/* 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
Form inputs must be usable for keyboard and screen reader users:
label for to input id.fieldset and legend for radio and checkbox groups when helpful.aria-describedby when using custom validation.Set type for behavior and name for form submission.
The browser renders the appropriate control and captures the user’s input.
On submit, checked/ filled inputs send their name and value to the server.
User input is captured and ready for processing on the server or in JavaScript.
The <input> element is fully supported in all browsers. Some newer input types may fall back to text in very old browsers.
From legacy Internet Explorer to the latest mobile browsers — the input element is foundational for web forms.
Bottom line: Build interactive forms with confidence. The <input> element is safe to use in every production environment today.
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.
label elements for every inputtype to the expected data (email, number, date)required for mandatory fieldsnamename on fields that should submit datatype="text" when a semantic type fits better<input>Bookmark these before you ship — they’ll keep your forms usable and accessible.
text, password, checkbox, radio, submit, and more.
FoundationNo closing tag in HTML syntax.
SyntaxConnect label for to input id.
AccessibilityForm data uses the name attribute.
FormsUse required and matching types.
ValidationWorks in every browser today.
Compatibilitytype attribute determines the control behavior.input is a void element with no closing tag in HTML. It does not wrap content like textarea.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.Try text fields, passwords, checkboxes, radio buttons, and submit inputs in the interactive editor.
6 people found this page helpful