Inputs
The Input element specifies a field for the user to enter information on a page.
On this page:
Best Practices
- Please read Label Guidance first.
- Refrain from using placeholder attributes in inputs because they cause usability problems.
- Use the Text Input when you can’t predict a user’s response or when another type of Input would make answering the prompt difficult.
- If users must choose from a predetermined set of choices, use Radio Buttons or Checkboxes.
- Use Textarea if the user needs to enter more than a single line of text.
- Clearly label all text input fields.
- Use the appropriate type of input for the data being gathered.
- Ensure the
for
andid
attributes have matching values.
We currently show 8 of the 22 types of inputs.
Usage
Input Type: Text
- Accepts text, numbers, and other characters
This accepts any kind of alphanumeric characters.
<div class="form-group">
<label for="inputTextBox199" class="label form-label">Input Text Label</label>
<input type="text" class="form-control" id="inputTextBox199">
<small>This accepts any kind of alphanumeric characters.</small>
</div>
Input Type: Date Picker
- Accepts dates using the browser’s date picker.
- Displays a User Interface (UI) optimized for the entry of dates.
This tells the browser to present its own optimized date-entry user interface.
<div class="form-group">
<label for="inputDate299" class="label form-label">Input Date Label</label>
<input type="date" class="form-control" id="inputDate299">
<small>This tells the browser to present its own optimized date-entry user interface.</small>
</div>
Input Type: Known Date Entry
- Accepts dates using three text inputs for Month, Day, Year.
- Displays a User Interface (UI) optimized for the entry of dates.
- Be sure to include labels, especially if the fields are rearranged.
Enter Date as Month, Day, Year
<p class="label" id="date-multiple-guidance">Enter Date as Month, Day, Year</p>
<div class="form-row">
<div class="col-4 col-md-3 col-lg-1">
<div class="form-group">
<label for="date-multiple-month" class="label form-label">Month</label>
<input type="text" class="form-control" id="date-multiple-month" name="date-multiple-month" aria-describedby="date-multiple-guidance" maxlength="2" pattern="[0-9]*" value="">
</div>
</div>
<div class="col-4 col-md-3 col-lg-1">
<div class="form-group">
<label for="date-multiple-day" class="label form-label">Day</label>
<input type="text" class="form-control" id="date-multiple-day" name="date-multiple-day" aria-describedby="date-multiple-guidance" maxlength="2" pattern="[0-9]*" value="">
</div>
</div>
<div class="col-4 col-md-3 col-lg-1">
<div class="form-group">
<label for="date-multiple-year" class="label form-label">Year</label>
<input type="text" class="form-control" id="date-multiple-year" name="date-multiple-year" aria-describedby="date-multiple-guidance" minlength="4" maxlength="4" pattern="[0-9]*" value="">
</div>
</div>
</div>
Input Type: Tel
- Accepts telephone numbers
- Displays a UI optimized for a phone number
On mobile browsers this presents a phone number-optimized UI.
<div class="form-group">
<label for="inputTelBox399" class="label form-label">Input Tel Label</label>
<input type="tel" class="form-control" id="inputTelBox399">
<small>On mobile browsers this presents a phone number-optimized UI.</small>
</div>
Input Type: Email
- Accepts email addresses
- Displays a UI optimized for the email address entry
On mobile browsers this presents an email-optimized UI.
<div class="form-group">
<label for="inputEmail499" class="label form-label">Input Email Label</label>
<input type="email" class="form-control" id="inputEmail499">
<small>On mobile browsers this presents an email-optimized UI.</small>
</div>
Input Type: Search
- Accepts search terms
- Displays a UI optimized for search term entry
This presents a search-optimized UI.
<div class="form-group">
<label for="inputTextBox599" class="label form-label">Input Search Label</label>
<input type="search" class="form-control" id="inputTextBox599">
<small>This presents a search-optimized UI.</small>
</div>
Input Type: URL
- Accepts web addresses
- Displays a UI optimized for the entry of web addresses
On mobile browsers this presents a URL-optimized UI.
<div class="form-group">
<label for="inputTextBox699" class="label form-label">Input URL Label</label>
<input type="url" class="form-control" id="inputTextBox699">
<small>On mobile browsers this presents a URL-optimized UI.</small>
</div>
Input Type: Number
- Accepts numbers
- Displays a UI optimized for the entry of numbers
This presents a numeric-optimized UI.
<div class="form-group">
<label for="inputTextBox799" class="label form-label">Input Number Label</label>
<input type="number" class="form-control" id="inputTextBox799">
<small>This presents a numeric-optimized UI.</small>
</div>
Input Type: File
- Accepts file uploads.
- Displays a UI optimized for uploading files.
This presents a file-selection UI.
<div class="form-group">
<label for="formFile" class="label form-label">Upload File</label>
<input class="form-control" type="file" id="formFile">
<small>This presents a file-selection UI.</small>
</div>
Readonly
- Shows user information that is readonly.
- User can copy the information but not change it.
Note: This is not the same as a disabled field. A disabled field prevents user input. This displays system provided values.
<div class="form-group">
<label for="read-only" class="label form-label">Label</label>
<input id="read-only" class="form-control" type="text" value="Readonly input here..." aria-label="readonly input example" readonly>
</div>
Input-Aligned Plain Text
- Same as Readonly, but removes input styling.
- Will horizontally align with other, user-editable fields.
<div class="form-group">
<label for="staticEmail" class="label form-label">Label</label>
<input type="text" readonly class="form-control-plaintext" id="staticEmail" value="email@example.com">
</div>
Input Detail View
- Use for detail views.
- Decreased vertical space between label and data to improve a detail page of data.
- Use on detail pages, not edit pages.
Label
Value
<div class="form-group">
<p class="label form-label">Label</p>
<p>Value</p>
</div>