ClickorAltL

Dragto resize

Nord Design System SearchDeveloperDeveloperGetting startedUsing Web ComponentsWebfontsCDNLocalizationCSS Framework Legacy ESLint PluginWorking with AIFAQDesignDesignGetting startedFoundationsThemesBrand assetsToolsComponentsComponentsAccordion New Aside New Autocomplete New AvatarBadgeBanner Updated ButtonButton GroupCalendar Updated CardCheckbox Updated Collapsible New Combobox New Command MenuDate Picker Updated Date Range Picker New DividerDrawerDropdownEmpty StateField New FieldsetFilter Bar New FooterHeaderIconInput Updated Item New Kbd New LayoutMessageMeter New ModalNavigationNotificationNumber Field New Otp Field New Outline New Pagination New Popout Updated ProgressProgress BarQrcodeRadio Updated Range Updated Scroll Area New Segmented ControlSelect Updated SkeletonSpinnerStackTabTableTagTextarea Updated Time Picker New ToastToggle Updated TooltipTop BarTruncate New Visually HiddenDesign TokensDesign TokensTailwind CSSTailwind CSSBlocksBlocksTemplatesTemplatesIconsIconsPlaygroundPlaygroundLatest UpdatesLatest UpdatesChangelogChangelogMigration guidesMigration guides
GitHub

Textarea Updated

Open in Storybook

Allows users to write text over multiple rows, used when the expected input is long.

Loading...

Usage

Textarea lets users write text across multiple rows. Reach for it when the expected input is long; for shorter, single-line input use an Input instead.

The textarea renders its built-in label, hint and error on its own. Wrapped in a Field, the Field takes over with a Field Label, Field Description and Field Error, and the built-in versions step aside automatically.

Copy code
import "@nordhealth/components/lib/Textarea"
import "@nordhealth/components/lib/Field"
import "@nordhealth/components/lib/FieldLabel"
import "@nordhealth/components/lib/FieldDescription"

Standalone or inside a Field

Use the control on its own with its built-in label, hint and error, or wrap it in a Field — the Field then provides the labelling. Both render the same control:

InlineWith Field

Examples

Sizes

Use the size attribute to render a small, medium (default) or large textarea.

Character counter

Set character-counter to show a count of the characters entered. When combined with maxlength, both the count and the maximum are shown.

Error

Show validation with a Field Error and mark the Field invalid.

Disabled and read-only

A disabled textarea cannot be focused or edited and is excluded from form submission. A readonly textarea can be focused but not edited, and its value is still submitted.

Expand

Use expand to make the textarea fill the width of its container.

Hint

Add a Field Hint to give the user extra guidance about what to enter.

Required

Set required on the Field Label to mark the field as mandatory and show the required indicator.

Hidden label

Use a visually hidden label when the context already makes the textarea's purpose clear. The label stays available to assistive technology.

Auto resize

Let the textarea grow to fit its content as the user types instead of showing a scrollbar.

Custom height

Set a fixed height with the rows attribute or a CSS custom property.

Text selection

Programmatically select text within the textarea using the selection APIs.

RTL

Textarea follows the document or container direction. Toggle the direction to see the layout mirror.

Accessibility

  • Always give the textarea an accessible name with a Field Label connected via for.
  • Convey validation with a Field Error rather than colour alone — it is associated with the textarea and announced to assistive technology.
  • Mark required fields by setting required on the Field Label; it shows the indicator and marks the control required.
  • When using character-counter with maxlength, the remaining-character count is exposed as a live region so screen reader users are informed as they approach the limit.
  • Prefer readonly over disabled when the value is still relevant but not editable, as disabled controls are removed from the tab order and not submitted with the form.

API reference

Textarea

Textarea is a component that allows user to write text over multiple rows. Used when the expected user input is long. For shorter input, use the Input component.

<nord-textarea></nord-textarea>

Props

PropertyAttribute Description TypeDefault
resizeresizeControls whether the textarea is resizable. By default is manually resizable vertically. Set to "auto" to enable auto-resizing as content grows.'vertical' | 'auto''vertical'
expandexpandControls whether the textarea expands to fill the width of its container.booleanfalse
maxLengthmaxlengthControls the max allowed length for the textarea.number | undefined
characterCountercharacter-counterControls whether to show a count of the number of characters in the textarea. When combined with maxlength, both the count and the max length are shown.booleanfalse
sizesizeThe size of the component.'s' | 'm' | 'l''m'
placeholderplaceholderPlaceholder text to display within the control.string | undefined
requiredrequiredDetermines whether the control is required or not. A required control is announced as such to assistive technology and, inside a <nord-field>, drives the required indicator on the <nord-field-label>. When using this property you need to also set “novalidate” attribute on a form element to prevent browser from displaying its own validation errors.booleanfalse
autocompleteautocompleteSpecifies the data type of the field, so that the browser may attempt to fill out the field automatically on behalf of the user.AutocompleteAttribute'off'
readonlyreadonlyMakes the component readonly, so that it is not editable. Readonly differs from disabled in that readonly fields are still focusable and will be submitted with a form.booleanfalse
disableddisabledMakes the component disabled. This prevents users from being able to interact with the component, and conveys its inactive state to assistive technologies.booleanfalse
namenameThe name of the form component.string | undefined
valuevalueThe value of the form component.string''
formformGets the form, if any, associated with the form element. The setter accepts a string, which is the id of the form.HTMLFormElement | null

Field properties

PropertyAttribute Description TypeDefault
labellabelLabel for the control. Ignored when the control is wrapped in a <nord-field>, which provides the label via <nord-field-label>.string''
hinthintOptional hint text shown with the control. Ignored inside a <nord-field>, which provides it via <nord-field-description>.string | undefined
hintBelowhint-belowRenders the hint below the control and any error instead of below the label.booleanfalse
hideLabelhide-labelVisually hide the label, but still expose it to assistive technologies.booleanfalse
errorerrorOptional error shown with the control. Ignored inside a <nord-field>, which provides it via <nord-field-error>.string | undefined
hideRequiredhide-requiredVisually hide the required indicator, but still expose the required state to assistive technologies.booleanfalse

Slots

Slot name Description
labelUse when a label requires more than plain text.
hintOptional slot that holds hint text for the textarea.
errorOptional slot that holds error text for the textarea.

Methods

Method nameParameters Description
focus(options?: FocusOptions) => voidoptions: An object which controls aspects of the focusing process.Programmatically move focus to the component.
blur() => voidN/AProgrammatically remove focus from the component.
click() => voidN/AProgrammatically simulates a click on the component.
EventDetail TypeDescription
selectNordEventFired when some text has been selected.
inputNordEventFired as the user types into the input.
changeNordEventFired whenever the input's value is changed via user interaction.

CSS Properties

CSS Custom Properties provide more fine grain control over component presentation. We advise utilizing existing properties on the component before using these.

PropertyDescriptionDefault
--n-textarea-inline-sizeControls the inline size, or width, of the textarea.240px
--n-textarea-block-sizeControls the minimum block size, or height, of the textarea. When resize="auto", the textarea grows from this height as content is added.76px
--n-textarea-max-block-sizeControls the maximum block size, or height, of the textarea. When resize="auto", the textarea stops growing at this height and a scrollbar appears.500px
--n-textarea-backgroundControls the background of the textarea, using our color tokens.var(--n-color-active)
--n-textarea-colorControls the text color of the textarea, using our color tokens.var(--n-color-text)
--n-textarea-border-colorControls the border color of the textarea, using our color tokens.var(--n-color-border-strong)
--n-textarea-border-radiusControls how rounded the corners are, using border radius tokens.var(--n-border-radius-s)
--n-label-colorControls the text color of the label, using our color tokens.var(--n-color-text)
Design guidelinesFor designers

Usage

This section includes guidelines for designers and developers about the usage of this component in different contexts.

Do

  • Use to allow text input where the expected input is long.

Don’t

  • Don’t use when the expected text input is short. Use input component instead.

Hint placement

Hint text is rendered above the control by default to preserve existing behavior for current consumers. Use the hint-below property to opt in to rendering the hint below the control and any error.

This is a non-breaking rollout for teams adopting the new layout gradually. Existing integrations keep the current placement unless hint-below is explicitly set.

Content guidelines

Textarea labels act as a title for the text field. Labels should typically be short and in noun form:

Company name
What is your company name?

When writing textarea labels, always write them in sentence case, not title case. The first word should be capitalized and the rest lowercase (unless a proper noun):

Provide description
Provide Description

When a textarea isn’t part of a form and is placed individually on a page, you could provide the textarea label as a call to action:

Leave a comment
Comment

Do not use colons in textarea labels:

Provide description
Provide description: