Input prefix/suffix
Use input prefixes and suffixes to show symbols or abbreviations that help users enter the right type of information in a form's text input.
Input Prefix
Component Preview
Component Code
<form class="usa-form"> <label class="usa-label" for="example-input-prefix">Credit card number</label> <div class="usa-input-group"> <div class="usa-input-prefix" aria-hidden="true"> <svg aria-hidden="true" role="img" focusable="false" class="usa-icon"> <use href="/civic-guide/uswds/img/sprite.svg#credit_card"></use> </svg> </div> <input id="example-input-prefix" class="usa-input" pattern="[0-9]*" inputmode="numeric" /> </div> </form>
Input Prefix (Error State)
Component Preview
Component Code
<form class="usa-form"> <label class="usa-label" for="example-input-prefix-error">Credit card number (Error)</label> <div class="usa-input-group usa-input-group--error"> <div class="usa-input-prefix" aria-hidden="true"> <svg aria-hidden="true" role="img" focusable="false" class="usa-icon"> <use href="/civic-guide/uswds/img/sprite.svg#credit_card"></use> </svg> </div> <input id="example-input-prefix-error" class="usa-input" pattern="[0-9]*" inputmode="numeric" /> </div> </form>
Input Suffix
Component Preview
Component Code
<form class="usa-form"> <label class="usa-label" for="example-input-suffix">Weight, in pounds</label> <div class="usa-input-group usa-input-group--sm"> <input id="example-input-suffix" class="usa-input" pattern="[0-9]*" inputmode="numeric" /> <div class="usa-input-suffix" aria-hidden="true">lbs.</div> </div> </form>
Guidance
When to use the input prefix/suffix component
- Highlight the type of information.
- Prefixes and suffixes are useful when there's a commonly understood symbol or abbreviation for the type of information the user needs to enter. Some common examples include units of measurement (like lbs or ft), symbols (like $ or %), or even icons (like showing an eye for password visibility).
- Input cannot include units.
- Use prefixes and suffixes if the input refers to a unit or currency amount (like a length or dollar amount), but the user's input must include digits only, not units or a currency symbol.
- Reduce mental load.
- Adding a prefix or suffix can help the user more quickly understand what kind of information is requested.
When to consider something else
- Open-ended form fields.
- If there aren't specific parameters around the information the user needs to enter, a prefix or suffix may be incorrect.
- Explanation requires additional words.
- Don't use prefixes or suffixes if a symbol or abbreviation is insufficient to convey the meaning. There shouldn't be any confusion between what type of information a prefix or suffix represents.
Usability guidance
- Follow best practices when using an icon.
- If you include an icon as a prefix or suffix, follow the design system's icon guidance.
- Use common abbreviations.
- Only use commonly understood abbreviations when indicating a text prefix or suffix. Don't use the full word.
Accessibility guidance
- Hide from screen readers.
- Prefixes and suffixes are hidden from screen readers using
aria-hidden. - Use descriptive labels.
- Labels should clearly indicate what type of data to enter since prefixes and suffixes are hidden from screen readers. For example, if you're requesting someone's height in inches, your form label should say "Height, in inches."
Using the input prefix/suffix component
- Placement matters.
- Place the
.usa-input-prefixelement before the.usa-inputelement, and place the.usa-input-suffixelement after.usa-input. Both elements should be placed inside.usa-input-group. - Use text or icons.
- Input prefixes and suffixes can accept either plain text or icons.
- Use validation styles.
- Place input validation classes on
.usa-input-group.
USWDS Documentation
For more guidance, view the USWDS Input Prefix/Suffix Component Documentation.
Variants
| Variant | Description |
|---|---|
|
|
Displays an input group error state. |
|
|
Displays an input group success state. |
|
|
Displays an input group at a specific width. Accepts |