Form controls

Give textual form controls like <input>s and <textareas> an upgrade with custom styles, sizing, focus states, and more.

On this page

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.

vue
<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.

vue
<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.

Form text should be explicitly associated with the form control it relates to using the 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.

Your password must be 8-20 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji.
vue
<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.

Must be 8-20 characters long.
vue
<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.

vue
<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.

vue
<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.

vue
<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>
vue
<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"
          button="primary"
          margin="b-3"
        >
          Confirm identity
        </b-button>
      </Col>
    </Row>
  </BForm>
</template>

File input

vue
<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 heights and override some inconsistencies between browsers.

vue
<template>
  <BFormLabel for="exampleColorInput">
    Color picker
  </BFormLabel>
  <BFormColor
    id="exampleColorInput"
    value="#05bc90"
    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.

vue
<template>
  <BFormLabel for="exampleDataList">
    Datalist example
  </BFormLabel>
  <BFormInput
    id="exampleDataList"
    list="datalistOptions"
    placeholder="Type to search..."
  />
  <BDatalist id="datalistOptions">
    <b-option value="San Francisco" />
    <b-option value="New York" />
    <b-option value="Seattle" />
    <b-option value="Los Angeles" />
    <b-option value="Chicago" />
  </BDatalist>
</template>