diff --git a/docs/pages/ui/forms/form-floating.mdx b/docs/pages/ui/forms/form-floating.mdx new file mode 100644 index 000000000..5eb853d66 --- /dev/null +++ b/docs/pages/ui/forms/form-floating.mdx @@ -0,0 +1,107 @@ +--- +title: Floating labels +summary: Floating labels put the label inside the field. The label sits over the empty control and moves up when the user types or selects a value. +description: Show labels inside form controls. +layout: '@layouts/DocsMdxLayout.astro' +--- +import Example from '@components/Example.astro'; + +## Overview + +Use `.form-floating` to place a label inside a form control. The label covers the empty field and moves up when the field has a value or gets focus. This saves vertical space in dense forms. + +Wrap one control and its label in a `.form-floating` element. The control comes first, the label second. + + +
+
+ +Two rules make the effect work: + +- The control needs a `placeholder`. The label only moves up when the placeholder is not shown. The placeholder text itself is hidden. +- The label must come after the control in the markup. The style uses the `~` sibling selector. + +Link the label to the control with `for` and `id`, the same as for a normal `.form-label`. + +## Usage + +### Inputs + +Floating labels work with all text based inputs, for example `text`, `email`, `password`, and `number`. + + +
+
+ +### Textarea + +A textarea inside `.form-floating` gets the same fixed height as an input. Set your own height with a `style` or a utility class when you need more space. + + +
+
+ +### Select + +A select always shows a value, so its label stays in the floated position. A `placeholder` is not needed here. + + +
+
+ +### Readonly plaintext + +Use `.form-control-plaintext` to show a value without the input border. The label stays floated. + + +
+
+ +### Disabled state + +Add `disabled` to the control. The label turns gray to show the field cannot be edited. + + +
+
+ +### Input group + +Put `.form-floating` inside an `.input-group` to mix a floating label with text or buttons. The group keeps the rounded corners on the outer elements. + + +
@
+
+ +### Validation states + +Add `.is-valid` or `.is-invalid` to the control, the same as for other form elements. Put the feedback text after the label. + + +
Looks good
Enter a valid email address
+
+ +## Examples + +### Form in a grid + +Use the grid to place floating labels next to each other. Each field keeps its own `.form-floating` wrapper. + + +
+
+ +### Sign in card + +Floating labels keep login forms short, because the labels do not take an extra line. + + +

Sign in

+
+ +## Accessibility + +- Always use a real `