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.
<template>
<b-div margin="b-3">
<BFormLabel for="exampleBFormControlInput1">
Email address
</BFormLabel>
<BFormInput
id="exampleBFormControlInput1"
type="email"
placeholder="name@example.com"
/>
</b-div>
<b-div margin="b-3">
<BFormLabel for="exampleBFormControlTextarea1">
Example textarea
</BFormLabel>
<BFormTextarea
id="exampleBFormControlTextarea1"
rows="3"
/>
</b-div>
</template>
Sizing
Set heights using classes like .form-control-lg
and .form-control-sm
.
<template>
<BFormInput
size="lg"
type="text"
placeholder=".form-control-lg"
aria-label=".form-control-lg example"
/>
<BFormInput
type="text"
placeholder="Default input"
aria-label="default input example"
/>
<BFormInput
size="sm"
type="text"
placeholder=".form-control-sm"
aria-label=".form-control-sm example"
/>
</template>
Form text
Block-level or inline-level form text can be created using .form-text
.
aria-describedby
attribute. This will ensure that assistive technologies—such as screen readers—will announce this form text when the user focuses or enters the control. Form text below inputs can be styled with .form-text
. If a block-level element will be used, a top margin is added for easy spacing from the inputs above.
<template>
<BFormLabel for="inputPassword5">
Password
</BFormLabel>
<BFormInput
id="inputPassword5"
type="password"
aria-describedby="passwordHelpBlock"
/>
<BFormText id="passwordHelpBlock">
Your password must be 8-20 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji.
</BFormText>
</template>
Inline text can use any typical inline HTML element (be it a <span>
, <small>
, or something else) with nothing more than the .form-text
class.
<template>
<Row
align-items="center"
justify-content="start"
>
<Col col="auto">
<BColFormLabel for="inputPassword6">
Password
</BColFormLabel>
</Col>
<Col col="auto">
<BFormInput
id="inputPassword6"
type="password"
aria-describedby="passwordHelpInline"
/>
</Col>
<Col col="auto">
<BFormText id="passwordHelpInline">
<span>Must be 8-20 characters long.</span>
</BFormText>
</Col>
</Row>
</template>
Disabled
Add the disabled boolean attribute on an input to give it a grayed out appearance, remove pointer events, and prevent focusing.
<template>
<BFormInput
type="text"
placeholder="Disabled input"
aria-label="Disabled input example"
disabled
/>
<BFormInput
type="text"
value="Disabled readonly input"
aria-label="Disabled input example"
disabled
readonly
/>
</template>
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.
<template>
<BFormInput
type="text"
value="Readonly input here..."
aria-label="readonly input example"
readonly
/>
</template>
Readonly plain text
If you want to have <input>
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
.
<template>
<Row margin="b-3">
<BColFormLabel
for="staticEmail"
class="col-sm-2"
>
Email
</BColFormLabel>
<Col col="sm-10">
<BFormInput
id="staticEmail"
type="text"
readonly="plaintext"
value="email@example.com"
/>
</Col>
</Row>
<Row margin="b-3">
<BColFormLabel
for="inputPassword"
class="col-sm-2 col-form-label"
>
Password
</BColFormLabel>
<Col col="sm-10">
<BFormInput
id="inputPassword"
type="password"
/>
</Col>
</Row>
</template>
<template>
<BForm>
<Row gutter="3">
<Col col="auto">
<b-label
for="staticEmail2"
visually-hidden
>
Email
</b-label>
<BFormInput
id="staticEmail2"
type="text"
readonly="plaintext"
value="email@example.com"
/>
</Col>
<Col col="auto">
<b-label
for="inputPassword2"
visually-hidden
>
Password
</b-label>
<BFormInput
id="inputPassword2"
type="password"
placeholder="Password"
/>
</Col>
<Col col="auto">
<b-button
type="submit"
color="primary"
margin="b-3"
>
Confirm identity
</b-button>
</Col>
</Row>
</BForm>
</template>
File input
<template>
<Row margin="b-3">
<BFormLabel for="formFile">
Default file input example
</BFormLabel>
<BFormFile id="formFile" />
</Row>
<Row margin="b-3">
<BFormLabel for="formFileMultiple">
Multiple files input example
</BFormLabel>
<BFormFile
id="formFileMultiple"
multiple
/>
</Row>
<Row margin="b-3">
<BFormLabel for="formFileDisabled">
Disabled file input example
</BFormLabel>
<BFormFile
id="formFileDisabled"
disabled
/>
</Row>
<Row margin="b-3">
<BFormLabel for="formFileSm">
Small file input example
</BFormLabel>
<BFormFile
id="formFileSm"
size="sm"
/>
</Row>
<Row>
<BFormLabel for="formFileLg">
Large file input example
</BFormLabel>
<BFormFile
id="formFileLg"
size="lg"
/>
</Row>
</template>
Color
Set the type="color"
and add .form-control-color
to the <input>
. We use the modifier class to set fixed height
s and override some inconsistencies between browsers.
<template>
<BFormLabel for="exampleColorInput">
Color picker
</BFormLabel>
<BFormColor
id="exampleColorInput"
title="Choose your color"
/>
</template>
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 .
<template>
<BFormLabel for="exampleDataList">
Datalist example
</BFormLabel>
<BFormInput
id="exampleDataList"
list="datalistOptions"
placeholder="Type to search..."
/>
<BDatalist id="datalistOptions">
<option value="San Francisco" />
<option value="New York" />
<option value="Seattle" />
<option value="Los Angeles" />
<option value="Chicago" />
</BDatalist>
</template>