Floating labels
Create beautifully simple form labels that float over your input fields.
Example
Wrap a FormControl and FormLabel pair in FormFloatingLabel to enable floating labels.
A non-empty placeholder is required on each text FormControl. The CSS-only implementation relies on the :placeholder-shown pseudo-element to detect an empty input. The placeholder stays transparent until the control is focused, then uses the normal placeholder color; only FormLabel is shown while the field is empty and unfocused.
FormFloatingLabel places FormLabel before the control so screen readers announce the label before the field's value. Its CSS reacts to the control's state with the :has() selector.
<Stack gap={3}>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingInput"
plain
>
Email address
</FormLabel>
<FormControl
id="floatingInput"
placeholder="name@example.com"
type="email"
/>
</FormFloatingLabel>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingPassword"
plain
>
Password
</FormLabel>
<FormControl
id="floatingPassword"
placeholder="Password"
type="password"
/>
</FormFloatingLabel>
</Stack>When defaultValue or a controlled value is set, FormLabel automatically moves to its floated position.
<FormFloatingLabel>
<FormLabel
htmlFor="floatingInputValue"
plain
>
Input with value
</FormLabel>
<FormControl
defaultValue="test@example.com"
id="floatingInputValue"
placeholder="name@example.com"
type="email"
/>
</FormFloatingLabel>Form validation styles also work as expected.
<FormFloatingLabel>
<FormLabel
htmlFor="floatingInputInvalid"
plain
>
Invalid input
</FormLabel>
<FormControl
defaultValue="test@example.com"
id="floatingInputInvalid"
placeholder="name@example.com"
type="email"
validation="invalid"
/>
</FormFloatingLabel>Textareas
By default, FormTextArea has the same height as FormControl.
<FormFloatingLabel>
<FormLabel
htmlFor="floatingTextarea"
plain
>
Comments
</FormLabel>
<FormTextArea
id="floatingTextarea"
placeholder="Leave a comment here"
/>
</FormFloatingLabel>To set a custom height on FormTextArea, do not use the rows attribute. Instead, override the --bs-form-floating-height CSS variable on FormFloatingLabel through a CSS module so the label floats correctly at any height.
<FormFloatingLabel className="_tallFloating_1w73o_50">
<FormLabel
htmlFor="floatingTextarea2"
plain
>
Comments
</FormLabel>
<FormTextArea
id="floatingTextarea2"
placeholder="Leave a comment here"
/>
</FormFloatingLabel>Selects
FormSelect works in the same way, but always shows FormLabel in its floated state. Selects with size and multiple are not supported.
<FormFloatingLabel>
<FormLabel
htmlFor="floatingSelect"
plain
>
Works with selects
</FormLabel>
<FormSelect
aria-label="Floating label select example"
defaultValue="Open this select menu"
id="floatingSelect"
>
<option>
Open this select menu
</option>
<option value="1">
One
</option>
<option value="2">
Two
</option>
<option value="3">
Three
</option>
</FormSelect>
</FormFloatingLabel>Date and time
Date, time, datetime-local, month, and week FormControl inputs also always show FormLabel in its floated state. These input types do not support placeholders the way textual inputs do, so a placeholder is not required (and is ignored by most browsers).
<Stack gap={3}>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingDate"
plain
>
Date
</FormLabel>
<FormControl
id="floatingDate"
type="date"
/>
</FormFloatingLabel>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingTime"
plain
>
Time
</FormLabel>
<FormControl
id="floatingTime"
type="time"
/>
</FormFloatingLabel>
</Stack>Disabled
Add the disabled boolean attribute on an input, a textarea or a select to give it a grayed out appearance, remove pointer events, and prevent focusing.
<Stack gap={3}>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingInputDisabled"
plain
>
Email address
</FormLabel>
<FormControl
disabled
id="floatingInputDisabled"
placeholder="name@example.com"
type="email"
/>
</FormFloatingLabel>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingTextareaDisabled"
plain
>
Comments
</FormLabel>
<FormTextArea
disabled
id="floatingTextareaDisabled"
placeholder="Leave a comment here"
/>
</FormFloatingLabel>
<FormFloatingLabel className="_tallFloating_1w73o_50">
<FormLabel
htmlFor="floatingTextarea2Disabled"
plain
>
Comments
</FormLabel>
<FormTextArea
defaultValue="Disabled textarea with some text inside"
disabled
id="floatingTextarea2Disabled"
placeholder="Leave a comment here"
/>
</FormFloatingLabel>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingSelectDisabled"
plain
>
Works with selects
</FormLabel>
<FormSelect
aria-label="Floating label disabled select example"
defaultValue="Open this select menu"
disabled
id="floatingSelectDisabled"
>
<option>
Open this select menu
</option>
<option value="1">
One
</option>
<option value="2">
Two
</option>
<option value="3">
Three
</option>
</FormSelect>
</FormFloatingLabel>
</Stack>Readonly plaintext
Floating labels also support the plaintext prop on FormControl, which is useful for toggling from an editable input to a plaintext value without affecting the page layout.
<Stack gap={3}>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingEmptyPlaintextInput"
plain
>
Empty input
</FormLabel>
<FormControl
id="floatingEmptyPlaintextInput"
placeholder="name@example.com"
plaintext
readOnly
type="email"
/>
</FormFloatingLabel>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingPlaintextInput"
plain
>
Input with value
</FormLabel>
<FormControl
defaultValue="name@example.com"
id="floatingPlaintextInput"
placeholder="name@example.com"
plaintext
readOnly
type="email"
/>
</FormFloatingLabel>
</Stack>Input groups
Floating labels also work inside InputGroup.
<InputGroup>
<InputGroupText>
@
</InputGroupText>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingInputGroup1"
plain
>
Username
</FormLabel>
<FormControl
id="floatingInputGroup1"
placeholder="Username"
type="text"
/>
</FormFloatingLabel>
</InputGroup>When using InputGroup and FormFloatingLabel with validation, place FormFeedback outside InputGroup but inside FormField.
<FormField>
<InputGroup>
<InputGroupText>
@
</InputGroupText>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingInputGroup2"
plain
>
Username
</FormLabel>
<FormControl
id="floatingInputGroup2"
placeholder="Username"
required
type="text"
validation="invalid"
/>
</FormFloatingLabel>
</InputGroup>
<FormFeedback>
{' '}Please choose a username.{' '}
</FormFeedback>
</FormField>Always floating
Set the always prop on FormFloatingLabel to keep the label floated and the placeholder visible.
<Stack gap={3}>
<FormFloatingLabel always>
<FormLabel
htmlFor="alwaysFloatingInput"
plain
>
Email address
</FormLabel>
<FormControl
id="alwaysFloatingInput"
placeholder="name@example.com"
type="email"
/>
</FormFloatingLabel>
<FormFloatingLabel always>
<FormLabel
htmlFor="alwaysFloatingPassword"
plain
>
Password
</FormLabel>
<FormControl
id="alwaysFloatingPassword"
placeholder="••••••••"
type="password"
/>
</FormFloatingLabel>
</Stack>By default, placeholders stay transparent until the control is focused. With always, the placeholder stays visible in both states.
Layout
When using the grid, place form elements inside Col components.
<Row className="g-2">
<Col md>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingInputGrid"
plain
>
Email address
</FormLabel>
<FormControl
defaultValue="mdo@example.com"
id="floatingInputGrid"
placeholder="name@example.com"
type="email"
/>
</FormFloatingLabel>
</Col>
<Col md>
<FormFloatingLabel>
<FormLabel
htmlFor="floatingSelectGrid"
plain
>
Works with selects
</FormLabel>
<FormSelect
defaultValue="Open this select menu"
id="floatingSelectGrid"
>
<option>
Open this select menu
</option>
<option value="1">
One
</option>
<option value="2">
Two
</option>
<option value="3">
Three
</option>
</FormSelect>
</FormFloatingLabel>
</Col>
</Row>CSS
Variables
.example {
--bs-form-floating-height: calc(3.75rem + var(--bs-border-width) * 2);
--bs-form-floating-line-height: 1.25;
--bs-form-floating-padding-x: calc(var(--bs-btn-input-padding-x) * 1.25);
--bs-form-floating-padding-y: 1rem;
--bs-form-floating-input-padding-t: 1.625rem;
--bs-form-floating-input-padding-b: 0.625rem;
--bs-form-floating-label-height: 1.5em;
--bs-form-floating-label-bg: var(--bs-btn-input-bg);
--bs-form-floating-label-disabled-bg: var(--bs-bg-2);
--bs-form-floating-label-opacity: 0.65;
--bs-form-floating-label-transform: scale(0.85) translateY(-0.5rem) translateX(0.15rem);
--bs-form-floating-label-disabled-color: var(--bs-fg-3);
--bs-form-floating-transition-property: opacity, transform;
--bs-form-floating-transition-duration: 0.1s;
--bs-form-floating-transition-timing: ease-in-out;
}