Textarea
A multi-line text field with label, help text, invalid state and optional auto-sizing.
Installation
bash
npx bootcn add textareabash
pnpm dlx bootcn add textareabash
yarn dlx bootcn add textareabash
bunx --bun bootcn add textareaThe CLI also installs the design tokens and these components: input. It prints the <link> and <script> tags to add to your layout.
Usage
html
<div class="bootcn-field">
<label for="bio" class="form-label bootcn-field__label">Bio</label>
<textarea
class="form-control bootcn-textarea"
id="bio"
name="bio"
rows="3"
aria-describedby="bio-help"
></textarea>
<p class="bootcn-field__help" id="bio-help">Up to 280 characters.</p>
</div>The bootcn-field, bootcn-field__label and bootcn-field__help classes come from the Input component's stylesheet. Install input too (it is a registry dependency) or replace them with Bootstrap's mb-3/form-text.
Modifiers and states
bootcn-textarea--autosize— grows with its content (up to 20rem) in browsers that supportfield-sizing: content; elsewhere it keeps itsrowsheight and can be resized by the user.- Invalid:
aria-invalid="true"plus an.invalid-feedbackelement referenced fromaria-describedby. - Disabled: the native
disabledattribute.
Customizing
| Variable | Default |
|---|---|
--bootcn-textarea-min-height | 5rem |
Dependencies
- Bootstrap 5.3+ CSS.
themes/tokens/tokens.css,input(field layout classes).
No JavaScript.
Accessibility
- Always pair the textarea with a
<label for>. - Connect help and error text with
aria-describedby; setaria-invalidonly while the value is invalid.
Source
The exact files the CLI installs (textarea@1.1.0). View on GitHub · Report an issue
html
<div class="bootcn-field">
<label for="bootcn-textarea-bio" class="form-label bootcn-field__label">Bio</label>
<textarea
class="form-control bootcn-textarea"
id="bootcn-textarea-bio"
name="bio"
rows="3"
aria-describedby="bootcn-textarea-bio-help"
placeholder="Tell us a little about yourself"
></textarea>
<p class="bootcn-field__help" id="bootcn-textarea-bio-help">Up to 280 characters.</p>
</div>
<div class="bootcn-field mt-3">
<label for="bootcn-textarea-notes" class="form-label bootcn-field__label"
>Notes (grows with content)</label
>
<textarea
class="form-control bootcn-textarea bootcn-textarea--autosize"
id="bootcn-textarea-notes"
name="notes"
rows="2"
></textarea>
</div>
<div class="bootcn-field mt-3">
<label for="bootcn-textarea-message" class="form-label bootcn-field__label">Message</label>
<textarea
class="form-control bootcn-textarea"
id="bootcn-textarea-message"
name="message"
rows="3"
required
aria-invalid="true"
aria-describedby="bootcn-textarea-message-error"
></textarea>
<div class="invalid-feedback" id="bootcn-textarea-message-error">
Write a message before sending.
</div>
</div>css
.bootcn-textarea {
--bootcn-textarea-min-height: 5rem;
min-height: var(--bootcn-textarea-min-height);
border-color: var(--bootcn-input);
border-radius: var(--bootcn-radius);
background-color: transparent;
box-shadow: var(--bootcn-shadow-sm);
font-size: 1rem;
resize: vertical;
transition:
border-color var(--bootcn-transition),
box-shadow var(--bootcn-transition);
}
.bootcn-textarea:focus {
outline: 0;
border-color: var(--bootcn-ring);
box-shadow: 0 0 0 3px var(--bs-focus-ring-color);
}
.bootcn-textarea[aria-invalid='true'] {
border-color: var(--bs-danger);
}
.bootcn-textarea[aria-invalid='true']:focus {
border-color: var(--bs-danger);
box-shadow: 0 0 0 3px rgba(var(--bs-danger-rgb), 0.2);
}
.bootcn-textarea[aria-invalid='true'] ~ .invalid-feedback {
display: block;
}
/* Progressive enhancement: grows with its content where supported. */
.bootcn-textarea--autosize {
field-sizing: content;
max-height: 20rem;
}
/* text-base on phones (no zoom on focus in iOS Safari), text-sm from md. */
@media (min-width: 768px) {
.bootcn-textarea {
font-size: var(--bootcn-control-font-size);
}
}
