Text Field
A text field is an input element that allows users to type text into a form. It is used for capturing short text entries, such as names, email addresses, or any other single-line information. Text fields can be single-line or multi-line (text area) for longer inputs.
Usage
cv-text-field_hero
When to use
Use a text field when you need to capture short, free-form input from users. For longer text or paragraphs, consider using a text area instead.
Variant | Purpose |
|---|---|
Default | Use a text field to capture short, free-form input from users. |
Autocomplete | To help users quickly find and select options by typing and receiving predictive suggestions. |
Recommendations
Recommended practices ensure clear guidance, usability, accessibility, appropriate sizing, and user support.
Do:
- Ensure that text fields have clear and descriptive labels that indicate what information is required.
- Provide input constraints (e.g., max-length, patterns) where necessary to guide user input.
- Include helper or placeholder text sparingly, as it should not be used as a substitute for labels.
- Use proper text field widths, ensuring they are large enough to accommodate typical input.
- If applicable, provide inline validation messages to guide users as they fill out the form.
Don't:
- Overuse text fields for all inputs — use the appropriate input type for different data (e.g., use email for email address).
- Use text fields without labels — always provide a label for accessibility and clarity.
- Allow unbounded, unvalidated user input in critical fields (e.g., email addresses or phone numbers).
Usage — additional resources
Style
Anatomy
cv-text-field_anatomy
- Icon that is commonly used to indicate search functionality.
- Communicates the type of text input being requested.
- Serves as placeholder text and will be replaced by the user's input.
- Contains the input field.
- Icon that is commonly used to clear the input field, communicate a warning or error, or toggle visibility.
- Communicates an in-line error message.
Label behavior
Before text input has been entered, the label for the text field should be shown inside the input area. After the text field has been focused, the label should move above the input area to make room for user input.
cv-text_field_anatomy_label_behavior
Placeholder behavior
A placeholder is optional and may be used to better communicate the type of input being requested. It becomes visible once the text field has been focused to show an example of appropriate input.
cv-text_field_anatomy_placeholder_behavior
Help and errors
The line of text directly underneath the text field should only be used to communicate an in-line error message.
To provide helpful content about the input being requested, use the header and message above the text field.
cv-text_field_help_and_errors
Typography
Use these text styles for text field:
- caption
- body-1
- caption
cv-text-field_typography
Content guidelines
Text fields are for collecting input. Clear labels and placeholders minimize input errors.
- Categorization: Use text fields for short, single-line inputs. Use text areas for longer text inputs.
- Tone: Use imperative verbs and short phrases to be clear and direct.
- Word Limit: Labels should be as few words as possible. Use one or two words to describe the input requested. Placeholder text up to 30 characters.
States
Enabled
cv-text-field_anatomy_enabled
Anatomy | Color token |
|---|---|
1, 2, 5, 6 | on-surface-variant |
3 | on-surface |
4 | outline |
Hovered
cv-text-field_anatomy_hovered
Anatomy | Color token |
|---|---|
1, 5, 6 | on-surface-variant |
2, 3, 4 | on-surface |
Focused
cv-text-field_anatomy_focused
Anatomy | Color token |
|---|---|
1, 5, 6 | on-surface-variant |
2, 4 | primary |
3 | on-surface |
Error
cv-text-field_anatomy_error
Anatomy | Color token |
|---|---|
1 | on-surface-variant |
2, 4, 5, 6 | negative |
3 | on-surface |
Error focused
cv-text-field_anatomy_error_focused
Anatomy | Color token |
|---|---|
1 | on-surface-variant |
2, 4, 5, 6 | negative |
3 | on-surface |
Disabled
cv-text-field_anatomy_disabled
Anatomy | Color token |
|---|---|
1, 2, 3, 5, 6 | on-surface-38 |
4 | outline-12 |
Web components
Demos
- Main
- AI Chat
Props
Prop | Description |
|---|---|
| Current value of the text field |
| Input type (text, search, tel, url, email, password, date, month, week, time, datetime-local, number, color) |
| Label text |
| Name attribute |
| Placeholder text |
| Helper text |
| Keep helper text visible |
| Outlined style variant |
| Whether input is required |
| Whether the field is disabled |
| Dense layout variant |
| Prefix text |
| Suffix text |
| Validation pattern |
| Minimum value |
| Maximum value |
| Size attribute |
| Step increment |
| Leading icon |
| Trailing icon |
| Maximum character length |
| Show character counter |
| Validity state |
| Auto-validate on change |
| Custom validation message |
| Whether the field will validate |
| Custom validity transform |
| Validate on initial render |
Code example
Methods
Method signature | Description |
|---|---|
| Returns |
| Runs |
| Sets a custom validity message (also overwrites |
| Re-calculate layout. If a textfield is styled with |
References
Accessibility
Overview
Text fields must provide clear labels, error messaging, and accessible feedback to help all users confidently complete tasks. Visual focus states and assistive technology support ensure inclusivity and clarity.
Keyboard interactions
- Tab key: Focuses the field.
- Shift + tab: Moves focus to the previous element.
- Arrow keys: Navigate within the field's content.
- Enter/Return key: Submits associated forms, where applicable.
cv-text-field_accessibility1
Tab index focus
- tabindex="0" includes fields in the natural tab flow.
- Disabled fields are removed from the tab order.
- Focus states must be clear and WCAG-compliant.
cv-text-field_accessibility2