OTTODesign System

ComponentsForm

Text field / text area

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>

Usage

Anatomy

Vorname 1 2 3 4 5
  1. Container
  2. Label
  3. Input
  4. Hint
  5. Counter
LiveAnatomy
HTML
<div class="anatomy" style="display:block;max-width:360px;margin:28px auto">
<oc-text-field-v1 value="Lara" hint="Hinweis" maxlength="30">Vorname</oc-text-field-v1>
<span class="anatomy-pin" style="left:-16px;top:35%">1</span>
<span class="anatomy-pin" style="left:6%;top:-18px">2</span>
<span class="anatomy-pin" style="left:18%;top:38%">3</span>
<span class="anatomy-pin" style="left:-16px;top:92%">4</span>
<span class="anatomy-pin" style="left:calc(100% + 16px);top:92%">5</span>
<ol class="anatomy-key"><li data-n="1">Container</li><li data-n="2">Label</li><li data-n="3">Input</li><li data-n="4">Hint</li><li data-n="5">Counter</li></ol>

Variants

Text fields have the following semantic variants:

  • Default
  • Error
  • Success
  • Warning

The error, success, or warning variants can occur after an input from the default state.

Default

Vorname

Error

Vorname

Success

Vorname

Warning

Vorname
LiveSemantic variants
HTML
<oc-text-field-v1 hint="Hinweis" maxlength="30">Vorname</oc-text-field-v1>
<oc-text-field-v1 hint="Hinweis" maxlength="30" variant="error">Vorname</oc-text-field-v1>
<oc-text-field-v1 hint="Hinweis" maxlength="30" variant="success">Vorname</oc-text-field-v1>
<oc-text-field-v1 hint="Hinweis" maxlength="30" variant="warning">Vorname</oc-text-field-v1>

Text area

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>

Input types

text

Vorname

tel

Telefonnummer

email

E-Mail-Adresse

url

Website

integer

Anzahl

decimal

Betrag
LiveInput types
HTML
<p class="demo-label">text</p>
<oc-text-field-v1 type="text" value="Lara" hint="Hinweis">Vorname</oc-text-field-v1>
<p class="demo-label">tel</p>
<oc-text-field-v1 type="tel" value="04012897096782" hint="Hinweis">Telefonnummer</oc-text-field-v1>
<p class="demo-label">email</p>
<oc-text-field-v1 type="email" value="name@provider.de" hint="Hinweis">E-Mail-Adresse</oc-text-field-v1>
<p class="demo-label">url</p>
<oc-text-field-v1 type="url" value="www.otto.de" hint="Hinweis">Website</oc-text-field-v1>
<p class="demo-label">integer</p>
<oc-text-field-v1 type="integer" value="1" hint="Hinweis">Anzahl</oc-text-field-v1>
<p class="demo-label">decimal</p>
<oc-text-field-v1 type="decimal" value="12.24" hint="Hinweis">Betrag</oc-text-field-v1>

Counter, hint, and error

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
LivePlaceholder
HTML
<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.

Prefix and suffix icon

Wunschbetrag

Suffix text

Wunschbetrag
LivePre- and suffix
HTML
<p class="demo-label">Prefix and suffix icon</p>
<oc-text-field-v1 type="decimal" value="50" prefix-icon="money-banknotes" suffix-icon="euro">Wunschbetrag</oc-text-field-v1>
<p class="demo-label">Suffix text</p>
<oc-text-field-v1 type="decimal" value="50" suffix-text="€">Wunschbetrag</oc-text-field-v1>

Behavior

States

All semantic variants have the following states, as shown in the image.

Enabled (hover, focus, type)

Vorname

Filled

Vorname

Disabled

Vorname
LiveStates
HTML
<p class="demo-label">Enabled (hover, focus, type)</p>
<oc-text-field-v1 hint="Hinweis">Vorname</oc-text-field-v1>
<p class="demo-label">Filled</p>
<oc-text-field-v1 value="Lara" hint="Hinweis">Vorname</oc-text-field-v1>
<p class="demo-label">Disabled</p>
<oc-text-field-v1 disabled hint="Hinweis">Vorname</oc-text-field-v1>

Placement

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.

Side by side, 8px gap

Vorname Nachname
Live8px horizontal gap
HTML
<p class="demo-label">Side by side, 8px gap</p>
<oc-form-group-v1 orientation="horizontal" flex-behavior="grow" gap="var(--oc-base-dimension-8)" oc-aria-label="Name">
<oc-text-field-v1>Vorname</oc-text-field-v1>
<oc-text-field-v1>Nachname</oc-text-field-v1>
</oc-form-group-v1>

Stacked, 24px gap

Straße Hausnummer Postleitzahl
Live24px vertical gap
HTML
<p class="demo-label">Stacked, 24px gap</p>
<oc-form-group-v1 orientation="vertical" gap="var(--oc-base-dimension-24)" oc-aria-label="Adresse">
<oc-text-field-v1 hint="Hinweis">Straße</oc-text-field-v1>
<oc-text-field-v1 value="1">Hausnummer</oc-text-field-v1>
<oc-text-field-v1>Postleitzahl</oc-text-field-v1>
</oc-form-group-v1>

Best practices

Vorname
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.
Vorname Nachname
DoOnly place related text field on the same line.
Vorname Bestellnummer
Don'tPlace an unrelated text field on the same line.
Vorname Vorname
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

Implementation

Live demo

Loungesessel mit Holzgestell

Deine Bestellung vom 12.09.

Loungesessel „Lotta“, Bouclé

Wie gefällt dir dein Sessel?

Deine Bewertung hilft anderen bei der Entscheidung.

Titel deiner Bewertung Deine Erfahrung Spitzname Bewertung abschicken
LiveReal OTTO components, rendered by the OTTO component runtime
HTML
<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>

Code

Version Tag Status API
v1 <oc-text-field-v1> Stable TextFieldV1

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.
type
9 values"number" | "text" | "email" | "tel" | "url" | "integer" | "decimal" | "file" | "date"
"text" no Defines the type of the input value.

The type integer is a stricter variant of type number and only accepts integer numbers.

The type decimal is a stricter variant of type number and only allows decimal numbers.
value string "" no Sets the initial and reset value of the text field to the provided value for form processing.
placeholder string undefined no Provides additional information related to the desired input value of the text field. Displayed as a faint text in the text field when it's empty.

Note: This does not work when the type is set to date.
hint string undefined no Provides additional information related to the text field below the input element.
validation-message string undefined no Provides a validation message related to the text field below the input element.

Implicitly sets the text field to the error state.
prefix-icon icon name undefined no Sets an icon that shows on the left side of the text field and before the prefix-text.
prefix-text string undefined no Sets a text or symbol that is displayed before the input text to provide the user some context, e.g. a unit.
suffix-icon icon name undefined no Sets an icon that shows on the right side of the text field and after the suffix-text.
suffix-text string undefined no Sets a text or symbol that is displayed on the right side of the text field to provide the user some context or information.
text-transform uppercase undefined no Defines the text transformation of the input value.

- "uppercase" transforms the input value to uppercase letters.
disabled boolean false no Disables the text field, 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.
name string undefined no Sets the name tag to identify the text field when submitting a form.
autocomplete
48 values"" | "off" | "on" | "email" | "tel" | "tel-area-code" | "tel-country-code" | "tel-extension" | "tel-local" | "tel-local-prefix" | "tel-local-suffix" | "tel-national" | "additional-name" | "address-level1" | "address-level2" | "address-level3" | "address-level4" | "address-line1" | "address-line2" | "address-line3" | "bday-day" | "bday-month" | "bday-year" | "cc-csc" | "cc-exp" | "cc-exp-month" | "cc-exp-year" | "cc-family-name" | "cc-given-name" | "cc-name" | "cc-number" | "cc-type" | "country" | "country-name" | "current-password" | "family-name" | "given-name" | "honorific-prefix" | "honorific-suffix" | "name" | "new-password" | "one-time-code" | "organization" | "postal-code" | "street-address" | "transaction-amount" | "transaction-currency" | "username"
"off" no 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.
inputmode "text" | "search" | "none" | "email" | "tel" | "url" | "decimal" | "numeric" undefined no Specifies the input mode for the text field, which hints at the type of data that might be entered by the user.

This can influence the virtual keyboard layout on mobile devices.
min number undefined no Specifies the minimum value allowed in the text field. Note: This only applies when the type is set to number or integer
max number undefined no Specifies the maximum value allowed in the text field. Note: This only applies when the type is set to number or integer
minlength number undefined no Specifies the minimum number of characters required in the text field.
maxlength number undefined no Specifies the maximum number of characters allowed in the text field.
pattern string undefined no Sets a regular expression that defines a required pattern for the input value. The input is considered valid if it matches the pattern.
oc-aria-label string undefined no Sets the ARIA label of the text field.
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 of the text field to provide a brief description of the input field.
Events
Event Detail type Description
oc-property-change OcTextFieldV1Events["oc-property-change"] Whenever a property value changes, this event triggers. Use this event to track all property changes within the component.

Refer to the Events documentation for more information.
oc-mount { component: string; } 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.

Examples

Listed below are the most common variations of the text field component as well as specific component variations for different use cases.

Default

The default configuration uses the default variant and the placeholder attribute to show a placeholder text in the Text Field when clicked.

Label
HTML
<oc-text-field-v1 name="myName" placeholder="this is a placeholder" type="text">Label</oc-text-field-v1>
Error

The error variant uses a red color to indicate an error state.

Label
HTML
<oc-text-field-v1 name="myName" placeholder="this is a placeholder" type="text" validation-message="Invalid input">
Label
</oc-text-field-v1>
Success

The success variant uses a green color to indicate a success state.

Label
HTML
<oc-text-field-v1 name="myName" placeholder="this is a placeholder" type="text" variant="success">
Label
</oc-text-field-v1>
Warning

The warning variant uses a yellow color to indicate a warning state.

Label
HTML
<oc-text-field-v1 name="myName" placeholder="this is a placeholder" type="text" variant="warning">
Label
</oc-text-field-v1>
Disabled

Variation with the attribute disabled set to true disables the Text Field, preventing users from interacting with it.

Label
HTML
<oc-text-field-v1 name="myName" placeholder="this is a placeholder" type="text" disabled>Label</oc-text-field-v1>
With hint

The hint attribute displays a hint below the Text Field.

Label
HTML
<oc-text-field-v1 name="myName" placeholder="this is a placeholder" type="text" hint="Hint">Label</oc-text-field-v1>
Version Tag Status API
v1 <oc-text-area-v1> Stable TextAreaV1

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.

Refer to the Events documentation for more information.
oc-mount { component: string; } 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.

Examples

Listed below are the most common variations of the text area component as well as specific component variations for different use cases.

Default

The default configuration uses the default variant and the placeholder attribute to show a placeholder text in the Text Area when clicked.

Label
HTML
<oc-text-area-v1 name="myName" placeholder="this is a placeholder">Label</oc-text-area-v1>
Error

The error variant uses a red color to indicate an error state.

Label
HTML
<oc-text-area-v1 name="myName" placeholder="this is a placeholder" validation-message="Invalid input">
Label
</oc-text-area-v1>
Success

The success variant uses a green color to indicate a success state.

Label
HTML
<oc-text-area-v1 name="myName" placeholder="this is a placeholder" variant="success">Label</oc-text-area-v1>
Warning

The warning variant uses a yellow color to indicate a warning state.

Label
HTML
<oc-text-area-v1 name="myName" placeholder="this is a placeholder" variant="warning">Label</oc-text-area-v1>
Disabled

The disabled attribute set to true disables the Text Area, preventing users from interacting with it.

Label
HTML
<oc-text-area-v1 name="myName" placeholder="this is a placeholder" disabled>Label</oc-text-area-v1>
With hint

The hint attribute displays a hint below the Text Field.

Label
HTML
<oc-text-area-v1 name="myName" placeholder="this is a placeholder" hint="Hint">Label</oc-text-area-v1>