Text fields are used for inputs that appear in forms, such as registration or changing the delivery address. The text area is used similarly to the text field and is used for longer text inputs, such as the review of a product.
Configurator
LiveText field and text area: type, affixes, texts, validation and state
Vorname
HTML
<oc-text-field-v1 hint="Bitte gib deinen Vornamen so an wie im Personalausweis.">Vorname</oc-text-field-v1>
In comparison to the text field, the text area is used for longer inputs. Per default, it has a height of three lines. With the property resizable, users can manually resize it using the native handle in the bottom right corner. Text areas have the same variants as text fields.
Text area
Lieferhinweis
Resizable (drag the corner)
Lieferhinweis
Livedefault text area (left) vs. manually resized height of text area (right)HTML
<p class="demo-label">Text area</p>
<oc-text-area-v1 hint="Hinweis" maxlength="500" value="Bitte beim Nachbarn im Erdgeschoss abgeben, falls ich nicht zu Hause bin.">Lieferhinweis</oc-text-area-v1>
<p class="demo-label">Resizable (drag the corner)</p>
<oc-text-area-v1 hint="Hinweis" maxlength="500" resizable value="Bitte beim Nachbarn im Erdgeschoss abgeben, falls ich nicht zu Hause bin.">Lieferhinweis</oc-text-area-v1>
Text fields can also include a counter which is used for counting the letters and setting minimum or maximum values.
Text Fields come with an optional Hint. The Hint helps the user filling out the text field correctly and provides further context.
The error is shown additionally above the hint if the user made a wrong input. It helps the user understanding the mistake and fixing the input.
Counter (max.)
Titel
Hint and counter (min.)
Spitzname
Hint
Vorname
Error and hint
Vorname
Livecounter (left) and hint/error (right)HTML
<p class="demo-label">Counter (max.)</p>
<oc-text-field-v1 maxlength="30" value="Mein neuer Lieblingssessel">Titel</oc-text-field-v1>
<p class="demo-label">Hint and counter (min.)</p>
<oc-text-field-v1 minlength="2" value="WildFlora" hint="So nennen wir dich bei der Kommunikation und während des Bestellprozesses.">Spitzname</oc-text-field-v1>
<p class="demo-label">Hint</p>
<oc-text-field-v1 value="Lara" hint="Bitte gib deinen Vornamen an, wie er im Personalausweis angegeben ist.">Vorname</oc-text-field-v1>
<p class="demo-label">Error and hint</p>
<oc-text-field-v1 value="12345" validation-message="Der eingegebene Text ist kein Name. Bitte korrigiere deine Eingabe." hint="Bitte gib deinen Vornamen an, wie er im Personalausweis angegeben ist.">Vorname</oc-text-field-v1>
Placeholder
You can use placeholders to nudge users, which inputs are expected. In comparison to hints, placeholders are very short and mostly example content is provided. It is only visible, when focused but hidden as soon as input is provided.
Click the field: the placeholder appears once it has focus
E-Mail-Adresse
LiveplaceholderHTML
<p class="demo-label">Click the field: the placeholder appears once it has focus</p>
<oc-text-field-v1 type="email" placeholder="max.mustermann@abc.de">E-Mail-Adresse</oc-text-field-v1>
Pre- and suffix
The prefix and suffix of a text field are optional and can contain icons or text. The prefix is always placed at the left and the suffix on the right inside a text field. Pre- and suffixes are only shown in the focused or filled state.
When placing multiple Text Fields next to each other, make sure there is a gap of 8px in-between horizontally and a gap of 24px vertically. Be aware the vertical distance is measured not from the label but from the text field itself.
DoUse a text field for short input e.g. Name or Mail.
Kommentar
Don'tUse a text field for longer inputs like review or comments. Instead, use a text area.
Vorname
DoUse a text field for custom inputs.
Monat
Don'tUse a text field for predictable information. Instead, use a dropdown with suggestions.
VornameNachname
DoOnly place related text field on the same line.
VornameBestellnummer
Don'tPlace an unrelated text field on the same line.
VornameVorname
DoAlways ensure the text field has a visible label to provide context and help the user filling in information.
CautionWhen using a text field without a label, make sure the user has enough context to fill out the text field. Also ensure that there is no accessibility and usability issue.
DoUse a search bar for search requests.
Suche
Don'tUse a text field for search requests.
Content Guidelines
Vorname
DoOnly use short and precise wordings for the label.
In dieses Feld gibst du deinen Vornamen ein
Don'tUse long descriptions or sentences for the label.
Spitzname
DoPut further, longer information which help the user filling out the text field inside the hint.
Spitzname
Don'tPut short information like a title inside the hint. It should only be placed inside the label.
Spitzname
DoProvide clear and useful error that help the user fix the issue.
Spitzname
Don'tUse generic errors, such as "There is an error".
Accessibility
For information on accessibility, refer to the technical documentation.
Note: For full technical documentation of this component, visit Storybook/TextField and Storybook/TextArea.
Live demo
Deine Bestellung vom 12.09.
Loungesessel „Lotta“, Bouclé
Wie gefällt dir dein Sessel?
Deine Bewertung hilft anderen bei der Entscheidung.
Titel deiner BewertungDeine ErfahrungSpitznameBewertung abschicken
LiveReal OTTO components, rendered by the OTTO component runtimeHTML
<div style="max-width:720px;margin:0 auto;display:grid;grid-template-columns:repeat(auto-fit,minmax(15rem,1fr));gap:32px;align-items:start">
<div style="display:grid;gap:12px">
<img src="/previews/imagery/samples/otto-product-still/product-armchair.webp" alt="Loungesessel mit Holzgestell" style="display:block;width:100%;aspect-ratio:1;object-fit:cover;border-radius:12px">
<p class="oc-copy-75 oc-text-color-secondary">Deine Bestellung vom 12.09.</p>
<p class="oc-copy-100"><b>Loungesessel „Lotta“, Bouclé</b></p>
<div style="display:grid;gap:20px">
<div style="display:grid;gap:4px">
<p class="oc-headline-100">Wie gefällt dir dein Sessel?</p>
<p class="oc-copy-100 oc-text-color-secondary">Deine Bewertung hilft anderen bei der Entscheidung.</p>
<oc-text-field-v1 value="Richtig gemütlich" maxlength="50">Titel deiner Bewertung</oc-text-field-v1>
<oc-text-area-v1 maxlength="1000" hint="Was gefällt dir, was könnte besser sein?" value="Der Bouclé-Stoff fühlt sich toll an, und die Farbe ist genau wie auf den Fotos. Der Aufbau hat keine zehn Minuten gedauert.">Deine Erfahrung</oc-text-area-v1>
<oc-text-field-v1 value="LaraL" hint="Wird öffentlich neben deiner Bewertung angezeigt." maxlength="20">Spitzname</oc-text-field-v1>
<oc-button-v1 variant="primary">Bewertung abschicken</oc-button-v1>
The text field component provides a configurable single-line input field for user text input.
It has attributes for form identification, initial value setting and additional information display.
It supports various styling variants, as well as different input types, such as text, email, and more.
Default variation
Label
HTML
<oc-text-field-v1 name="myName" placeholder="this is a placeholder" type="text">Label</oc-text-field-v1>
Configuration
The text field component offers a variety of styling variants such as default, error, success, and warning.
This component is configurable, allowing you to tailor its features and appearance to your specific needs.
To explore all the available options and adjust the component, use the component configurator and see the changes affect the component in real-time.
Usage guidelines
Before integrating the text field component into your project, make sure you have correctly installed the OTTO components package.
Look through the variations page for examples of possible component variations.
Here, you can discover both common and specific variations that address different use cases.
This component has visual overflow.
It extends beyond its bounding box and is clipped by parent containers with overflow: hidden.
Ensure the parent container has sufficient padding to accommodate the component's full visual area.
If the text field component is used in a form, pressing Enter while focused on the text field triggers the submit action immediately (implicit submit) if an oc-button component or a normal HTML button with the type submit is also present in the form.
Use oc-aria-label
To make the text field recognizable for screen readers, use the oc-aria-label attribute to provide a clear and descriptive label when the component does not have content in the default slot.
See the general accessibility documentation for guidance on using oc-aria-label, including how it works with link and masked link behavior.
Configure the text field component with the controls below and see the changes live in the preview canvas.
Click the Show code button within the preview canvas to see the source code for the current component configuration.
Label
HTML
<oc-text-field-v1 name="myName" placeholder="this is a placeholder" type="text">Label</oc-text-field-v1>
Interactive configurator (Storybook controls); every option is listed in the API section of this file.
API v1
Text Field v1 API
API: <oc-text-field-v1> (TextFieldV1)
The Text Field component provides a single-line input field for user text input.
It has attributes for form identification, initial value setting and additional information display.
It supports various styling variants, as well as different input types, such as text, email, and more.
Attributes / properties
Attribute
Type
Default
Required
Description
variant
"default" | "error" | "success" | "warning"
"default"
no
Sets the main styling and behavior of the text field.
Specifies if browsers are permitted to provide assistance in filling out the field value. Set to one of the enum values to enable specific autocomplete.
Fired when the component is mounted to the DOM. The event is fired when the onMount hook of the component is called by the runtime.
oc-unmount
{ component: string; }
Fired when the component is unmounted from the DOM. The event is fired when the function returned by the onMount hook of the component is called by the runtime.
Methods
selectionStart: number
Gets or sets the start position of the current text selection in the text field.
This is a property with getter/setter access, not a callable method.
selectionEnd: number
Gets or sets the end position of the current text selection in the text field.
This is a property with getter/setter access, not a callable method.
Variations (v1)
Variations
Listed below are the most common variations of the text field component as well as specific component variations for different use cases.
You can explore all available options using the component configurator, adjust the component to your needs, and see the changes live in a preview canvas.
Variation using the maxlength attribute limits the number of characters that can be entered in the Text Field and displays a counter below the Text Field to show the remaining characters.
The hint attribute displays a hint below the Text Field.
Args: maxlength=50, hint=Hint
Label
HTML
<oc-text-field-v1 name="myName" placeholder="this is a placeholder" type="text" maxlength="50" hint="Hint">
Label
</oc-text-field-v1>
Variation using the maxlength attribute limits the number of characters that can be entered in the Text Field and displays a counter below the Text Field to show the remaining characters.
The hide-counter attribute hides the counter of the Text Field. Maximum number of characters allowed in the text field is still enforced.
Args: maxlength=50, hide-counter=true
Label
HTML
<oc-text-field-v1 name="myName" placeholder="this is a placeholder" type="text" hide-counter maxlength="50">
Label
</oc-text-field-v1>
The demo form showcases various configurations of the Text Area component using the attributes minlength, maxlength, type, placeholder, suffix-icon, suffix-text, and hint.
<h1 style="margin-bottom: 32px">Demo form</h1>
<form id="form1">
<oc-text-field-v1
name="first-name"
placeholder="Max"
minlength="3"
value=""
hint="First part of your name"
>First Name</oc-text-field-v1
>
<oc-text-field-v1
name="last-name"
placeholder="Mustermann"
maxlength="50"
hint="Last part of your name"
>Last Name</oc-text-field-v1
>
<oc-text-field-v1 name="email" type="email" placeholder="foo@bar.de" required
>E-Mail</oc-text-field-v1
>
<oc-text-field-v1 name="size" type="integer" suffix-text="cm">Size</oc-text-field-v1>
<oc-text-field-v1 name="money" type="decimal" suffix-icon="euro">Money</oc-text-field-v1>
<div class="buttons">
<oc-button-v1 type="reset" variant="secondary">Reset</oc-button-v1>
<oc-button-v1 type="submit">Submit</oc-button-v1>
</div>
</form>
<script>
(() => {
const [form] = document.getElementsByTagName("form");
form.addEventListener("submit", (ev) => {
let formData = new FormData(form);
let data = "";
formData.forEach((value, key) => (data += key + "=" + value + "\\n"));
console.log(data);
alert("sending:\\n" + data);
ev.preventDefault();
});
})();
</script>
<style>
form {
display: flex;
flex-direction: column;
gap: 24px;
}
.buttons {
display: flex;
gap: 16px;
}
</style>
Story source (TypeScript, verbatim from Storybook)
A Autocomplete demo form showcases various configurations of the Text Area component using the autocomplete attribute to permit browsers to provide assistance in filling out the field value.
A demo showcasing a birthday input using three separate Text Fields for day, month, and year with appropriate attributes for each field. Utilizes the min and max attributes to restrict input values.
Birthday
This story demonstrates a birthday input using three separate Text Fields for day, month,
and year with appropriate attributes for each field.
Note that this is just a visual demo. In a real-world application, additional logic would be
needed to validate the combined date input.
Values are restricted using the min and max attributes to ensure
valid date components.
Day:min="1", max="31", maxlength="2"
Month:min="1", max="12", maxlength="2"
Year:min="1900", max="2025", maxlength="4"
Day
Month
Year
HTML
<h1 style="margin-bottom: 32px">Birthday</h1>
<p>
This story demonstrates a birthday input using three separate Text Fields for day, month,
and year with appropriate attributes for each field.
</p>
<p>
Note that this is just a visual demo. In a real-world application, additional logic would be
needed to validate the combined date input.
</p>
<p>
Values are restricted using the <code>min</code> and <code>max</code> attributes to ensure
valid date components.
</p>
<div style="margin-bottom: 16px">
<ul class="oc-list--unordered">
<li><strong>Day:</strong> <code>min="1", max="31", maxlength="2"</code></li>
<li><strong>Month:</strong> <code>min="1", max="12", maxlength="2"</code></li>
<li><strong>Year:</strong> <code>min="1900", max="2025", maxlength="4"</code></li>
</ul>
<div style="display: flex; gap: 16px">
<oc-text-field-v1
name="day"
placeholder="DD"
type="integer"
min="1"
max="31"
maxlength="2"
style="flex-shrink: 0; width: 60px"
hide-counter
>Day
</oc-text-field-v1>
<oc-text-field-v1
name="month"
placeholder="MM"
type="integer"
min="1"
max="12"
maxlength="2"
style="flex-shrink: 0; width: 80px"
hide-counter
>Month
</oc-text-field-v1>
<oc-text-field-v1
name="year"
placeholder="YYYY"
type="integer"
min="1900"
max="2025"
maxlength="4"
style="flex-shrink: 0; width: 80px"
hide-counter
>Year
</oc-text-field-v1>
<style>
form {
display: flex;
flex-direction: column;
gap: 24px;
}
.buttons {
display: flex;
gap: 16px;
}
</style>
Story source (TypeScript, verbatim from Storybook)
{
name: "Demo birthday",
parameters: {
controls: {
disabled: true
},
chromatic: {
disableSnapshot: true,
hideInChromatic: true
}
},
argTypes: hideControlsBadge(Metadata),
render() {
return html`
<h1 style="margin-bottom: 32px">Birthday</h1>
<p>
This story demonstrates a birthday input using three separate Text Fields for day, month,
and year with appropriate attributes for each field.
</p>
<p>
Note that this is just a visual demo. In a real-world application, additional logic would be
needed to validate the combined date input.
</p>
<p>
Values are restricted using the <code>min</code> and <code>max</code> attributes to ensure
valid date components.
</p>
<div style="margin-bottom: 16px">
<ul class="oc-list--unordered">
<li><strong>Day:</strong> <code>min="1", max="31", maxlength="2"</code></li>
<li><strong>Month:</strong> <code>min="1", max="12", maxlength="2"</code></li>
<li><strong>Year:</strong> <code>min="1900", max="2025", maxlength="4"</code></li>
</ul>
</div>
<div style="display: flex; gap: 16px">
<oc-text-field-v1
name="day"
placeholder="DD"
type="integer"
min="1"
max="31"
maxlength="2"
style="flex-shrink: 0; width: 60px"
hide-counter
>Day
</oc-text-field-v1>
<oc-text-field-v1
name="month"
placeholder="MM"
type="integer"
min="1"
max="12"
maxlength="2"
style="flex-shrink: 0; width: 80px"
hide-counter
>Month
</oc-text-field-v1>
<oc-text-field-v1
name="year"
placeholder="YYYY"
type="integer"
min="1900"
max="2025"
maxlength="4"
style="flex-shrink: 0; width: 80px"
hide-counter
>Year
</oc-text-field-v1>
</div>
<style>
form {
display: flex;
flex-direction: column;
gap: 24px;
}
.buttons {
display: flex;
gap: 16px;
}
</style>
`;
}
}
The text area component provides users with a multi-line input field for text input.
It has attributes for form identification, initial value setting, additional information display such as hint and placeholder, styling variants, and form validation.
Default variation
Label
HTML
<oc-text-area-v1 name="myName" placeholder="this is a placeholder">Label</oc-text-area-v1>
Configuration
The text area component offers a variety of styling variants such as default, error, success, and warning.
This component is configurable, allowing you to tailor its features and appearance to your specific needs.
To explore all the available options and adjust the component, use the component configurator and see the changes affect the component in real-time.
Usage guidelines
Before integrating the text area component into your project, make sure you have correctly installed the OTTO components package.
Look through the variations page for examples of possible component variations. Here, you can discover both common and specific variations that address different use cases.
This component has visual overflow.
It extends beyond its bounding box and is clipped by parent containers with overflow: hidden.
Ensure the parent container has sufficient padding to accommodate the component's full visual area.
To make the text area recognizable for screen readers, use the default slot to provide a clear and descriptive label.
Use the aria-label attribute on the label to provide additional context if the visible label is not sufficient.
See the general accessibility documentation for guidance on using oc-aria-label, including how it works with link and masked link behavior.
Configure the text area component with the controls below and see the changes live in the preview canvas.
Click the Show code button within the preview canvas to see the source code for the current component configuration.
Label
HTML
<oc-text-area-v1 name="myName" placeholder="this is a placeholder">Label</oc-text-area-v1>
Interactive configurator (Storybook controls); every option is listed in the API section of this file.
API v1
Text Area v1 API
API: <oc-text-area-v1> (TextAreaV1)
The Text Area component provides users with a multi-line input field for text input.
It has attributes for form identification, initial value setting, additional information display, styling variants, and form validation.
Attributes / properties
Attribute
Type
Default
Required
Description
variant
"default" | "error" | "success" | "warning"
"default"
no
Sets the main styling and behavior of the text area.
value
string
""
no
Sets the initial and reset value of the text area to the provided value for form processing.
placeholder
string
undefined
no
Provides additional information related to the desired input value of the text area. Displayed as a faint text inside the text area when it's empty.
hint
string
undefined
no
Provides additional information related to the text area below the input element.
validation-message
string
undefined
no
Provides a validation message related to the text area below the input element.
Implicitly sets the text area to the error state.
disabled
boolean
false
no
Disables the text area, preventing user interaction and input.
required
boolean
false
no
Marks the input as required for screen readers. Doesn't prevent form submission on its own.
hide-counter
boolean
false
no
Hides the counter. Maximum number of characters allowed in the text field is still enforced.
resizable
boolean
false
no
Enables the vertical resizing of the text area.
maxlength
number
undefined
no
Specifies the maximum number of characters allowed in the textarea.
name
string
undefined
no
Sets the name tag to identify the text area when submitting a form.
oc-aria-label
string
undefined
no
Sets the ARIA label of the textarea.
without-optional-label
boolean
false
no
Excludes the automatic "(optional)" label suffix even if the feature toggle is active.
Slots
Slot
Required
Description
default
yes
Sets the label for the text area to provide a brief description of the input field.
Events
Event
Detail type
Description
oc-property-change
OcTextAreaV1Events["oc-property-change"]
Whenever a property value changes, this event triggers. Use this event to track all property changes within the component.
Fired when the component is mounted to the DOM. The event is fired when the onMount hook of the component is called by the runtime.
oc-unmount
{ component: string; }
Fired when the component is unmounted from the DOM. The event is fired when the function returned by the onMount hook of the component is called by the runtime.
CSS custom properties
Custom property
Default
Description
--min-height
Sets the min-height of the textarea element.
Variations (v1)
Variations
Listed below are the most common variations of the text area component as well as specific component variations for different use cases.
You can explore all available options using the component configurator, adjust the component to your needs, and see the changes live in a preview canvas.
A Text Area using the maxlength attribute limits the number of characters that can be entered in the Text Area and displays a counter below the Text Area to show the remaining characters.
The hint attribute displays a hint below the Text Area.
Args: maxlength=50, hint=Hint
Label
HTML
<oc-text-area-v1 name="myName" placeholder="this is a placeholder" maxlength="50" hint="Hint">Label</oc-text-area-v1>
Variation using the maxlength attribute limits the number of characters that can be entered in the Text Field and displays a counter below the Text Field to show the remaining characters.
The hide-counter attribute hides the counter of the Text Field. Maximum number of characters allowed in the text field is still enforced.
Args: maxlength=50, hide-counter=true
Label
HTML
<oc-text-area-v1 name="myName" placeholder="this is a placeholder" hide-counter maxlength="50">Label</oc-text-area-v1>