2.23.0
Textareas allow a user to input multiple lines of text.
See Forms for guidance on composing full forms.
Use when soliciting multiple lines of text.
<!-- Default -->
<textarea class="mds-form__textarea" id="textarea-id"></textarea>
<!-- With Placeholder Text -->
<textarea class="mds-form__textarea" id="textarea-id" placeholder="Tell us more here..."></textarea>
<!-- Disabled -->
<textarea class="mds-form__textarea" id="textarea-id" disabled></textarea>
<!-- Default -->
<mds-textarea id="textarea-id"></mds-textarea>
<!-- With Placeholder Text -->
<mds-textarea id="textarea-id" placeholder="Tell us more here..."></mds-textarea>
<!-- Disabled -->
<mds-textarea id="textarea-id" disabled></mds-textarea>
Always wrap grouped form elements in a mds-form__field-group
container. See the Forms composition section for more guidelines on constructing forms.
<!-- HTML -->
<div class="mds-form__field-group">
<label class="mds-form__label" for="comments">Comments</label>
<textarea class="mds-form__textarea" id="comments"></textarea>
</div>
<!-- Web Component -->
<mds-field-group>
<mds-label for="comments">Comments</mds-label>
<mds-textarea id="comments"></mds-textarea>
</mds-field-group>
Sizing affects textarea size, text size and internal spacing. The default size is medium, and you can use modifier classes or props to make the textarea smaller or larger.
<textarea class="mds-form__textarea mds-form__textarea--small" id="small-textarea" placeholder="Textarea"></textarea>
<mds-textarea placeholder="Textarea" size="small" id="small-textarea"></mds-textarea>
focus
. This is default behavior and a known issue, teams are still encouraged to use textareas in production.
Class
|
Applies to
|
Outcome
|
---|---|---|
|
|
Adjusts styling to render a small textarea. |
|
|
Adjusts styling to render a large textarea. |
When setting props as attributes on a custom HTML element, use kebab-case
instead of camelCase
.
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
String |
— |
— |
A space-separated list of element |
|
Boolean |
— |
— |
Adds the |
|
Boolean |
— |
|
If |
|
String |
Required |
— |
The |
|
Number |
— |
— |
If provided, sets the maximum number of characters allowed. |
|
Number |
— |
— |
If provided, sets the minimum number of characters allowed. |
|
String |
— |
— |
Adds the |
|
String |
— |
— |
Adds placeholder text. |
|
Boolean |
— |
|
Adds the |
|
Boolean |
— |
|
If |
|
Number |
— |
— |
Sets the number of visible text lines. |
|
String |
One of: |
|
Alters the size of the textarea. |
|
String |
— |
— |
The content for the textarea. |
Setting id
, size
, required
, and placeholder
via props:
<mds-textarea id="textarea-id" size="small" placeholder="Comments" required></mds-textarea>
Setting id
, ariaInvalid
, and minlength
via props:
<mds-textarea id="textarea-id" aria-invalid minlength="40"></mds-textarea>
Setting id
and text
via props:
<mds-textarea id="textarea-id" text="Text area content."></mds-textarea>
minlength
property in Edge v17+, if required
isn’t set, and the user didn’t specify a value, minlength
has no affect.aria-describedby
attribute on each textarea
that has an .mds-form__microcopy
or an .mds-form__field-error
component providing additional information. The value of the aria-describedby
attribute must match the id
attribute on the .mds-form__microcopy
or .mds-form__field-error
component.for
attribute on each label
with a value matching the id
attribute on the corresponding textarea
.