0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-04 16:24:22 +01:00
Bootstrap/site/content/docs/5.3/forms/form-control.md
XhmikosR cf9454caa0
Release v5.3.0-alpha1 (#37661)
* Bump version to 5.3.0-alpha1

* Dist

* Add docs versions updates

* Update note in homepage hero

Co-authored-by: Mark Otto <markdotto@gmail.com>
2022-12-24 18:37:22 +02:00

6.2 KiB

layout title description group toc
docs Form controls Give textual form controls like `<input>`s and `<textarea>`s an upgrade with custom styles, sizing, focus states, and more. forms true

Example

Form controls are styled with a mix of Sass and CSS variables, allowing them to adapt to color modes and support any customization method.

{{< example >}}

{{< /example >}}

Sizing

Set heights using classes like .form-control-lg and .form-control-sm.

{{< example >}} {{< /example >}}

Disabled

Add the disabled boolean attribute on an input to give it a grayed out appearance, remove pointer events, and prevent focusing.

{{< example >}} {{< /example >}}

Readonly

Add the readonly boolean attribute on an input to prevent modification of the input's value. readonly inputs can still be focused and selected, while disabled inputs cannot.

{{< example >}} {{< /example >}}

Readonly plain text

If you want to have <input readonly> elements in your form styled as plain text, replace .form-control with .form-control-plaintext to remove the default form field styling and preserve the correct margin and padding.

{{< example >}}

{{< /example >}}

{{< example >}}

Confirm identity
{{< /example >}}

File input

{{< example >}}

{{< /example >}}

Color

Set the type="color" and add .form-control-color to the <input>. We use the modifier class to set fixed heights and override some inconsistencies between browsers.

{{< example >}} {{< /example >}}

Datalists

Datalists allow you to create a group of <option>s that can be accessed (and autocompleted) from within an <input>. These are similar to <select> elements, but come with more menu styling limitations and differences. While most browsers and operating systems include some support for <datalist> elements, their styling is inconsistent at best.

Learn more about support for datalist elements.

{{< example >}}

{{< /example >}}

CSS

Variables

Form controls make use of a small amount of CSS variables to support custom styling across color modes.

{{< scss-docs name="form-control-vars" file="scss/_root.scss" >}}

Sass variables

$input-* are shared across most of our form controls (and not buttons).

{{< scss-docs name="form-input-variables" file="scss/_variables.scss" >}}

$form-label-* and $form-text-* are for our <label>s and .form-text component.

{{< scss-docs name="form-label-variables" file="scss/_variables.scss" >}}

{{< scss-docs name="form-text-variables" file="scss/_variables.scss" >}}

$form-file-* are for file input.

{{< scss-docs name="form-file-variables" file="scss/_variables.scss" >}}