Skip to di men tin dɛn we de insay Skip to doks nevigishɔn
in English

Dizayn

Gi yu fɔm dɛn sɔm strɔkchɔ—frɔm inlayn to ɔrizɔntal to kɔstɔm grid implimɛnt dɛn—wit wi fɔm layout opshɔn dɛn.

Fɔm dɛn

Ɛvri grup fɔ fɔm fil dɛn fɔ de insay wan <form>ɛlimɛnt. Bootstrap nɔ de gi difɔlt stayl fɔ di <form>ɛlimɛnt, bɔt sɔm pawaful brawza ficha dɛn de we dɛn gi bay difɔlt.

  • Nyu to brɔuza fɔm dɛn? Tink bɔt fɔ rivyu di MDN fɔm dɔkyumɛnt dɛn fɔ wan ɔvaviu ɛn kɔmplit list fɔ di atribyut dɛn we de.
  • <button>s insay wan <form>difɔlt to type="submit", so tray fɔ bi spɛshal ɛn ɔltɛm inklud wan type.
  • Yu kin disable ɛvri fɔm ɛlimɛnt insay wan fɔm wit di disabledatribyut na di <form>.

Bikɔs Bootstrap de aplay display: blockɛn width: 100%to ɔlmost ɔl wi fɔm kɔntrol dɛn, fɔm dɛn go bay difɔlt stak vertikal. Yu kin yuz ɔda klas dɛn fɔ chenj dis layout pan ɛni fɔm.

Yutiliti dɛn

Margin utilities na di izi we fɔ ad sɔm strɔkchɔ to fɔm dɛn. Dɛn de gi besik grupin fɔ lɛbl dɛn, kɔntrol dɛn, opshɔnal fɔm tɛks, ɛn fɔm validɛshɔn mɛsej. Wi kin advays yu fɔ stik to margin-bottomyutiliti dɛn, ɛn yuz wan dairekshɔn ɔlsay na di fɔm fɔ mek yu kɔnsistɛns.

Fil fri fɔ bil yu fɔm dɛn aw yu want, wit <fieldset>s, <div>s, ɔ nia ɛni ɔda ɛlimɛnt.

<div class="mb-3">
  <label for="formGroupExampleInput" class="form-label">Example label</label>
  <input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input placeholder">
</div>
<div class="mb-3">
  <label for="formGroupExampleInput2" class="form-label">Another label</label>
  <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input placeholder">
</div>

Fɔm grid fɔm

Yu kin bil mɔ kɔmpleks fɔm dɛn we yu de yuz wi grid klas dɛn. Yuz dɛn wan ya fɔ fɔm layout dɛn we nid bɔku kɔlɔm dɛn, difrɛn wit dɛn, ɛn ɔda alaynɛshɔn opshɔn dɛn. Rikways di $enable-grid-classesSass vɛriɔbul fɔ bi ɛnabul (on bay difɔlt).

<div class="row">
  <div class="col">
    <input type="text" class="form-control" placeholder="First name" aria-label="First name">
  </div>
  <div class="col">
    <input type="text" class="form-control" placeholder="Last name" aria-label="Last name">
  </div>
</div>

Gɔta dɛn

By adding gutter modifier classes , yu kin gɛt kɔntrol oba di gɔta wit in as wɛl di inlayn as blɔk dairekshɔn. Dɔn bak, i nid $enable-grid-classesfɔ mek dɛn ɛnabul di Sass vɛriɔbul (on bay difɔlt).

<div class="row g-3">
  <div class="col">
    <input type="text" class="form-control" placeholder="First name" aria-label="First name">
  </div>
  <div class="col">
    <input type="text" class="form-control" placeholder="Last name" aria-label="Last name">
  </div>
</div>

Yu kin mek mɔ kɔmpleks layout dɛn bak wit di grid sistem.

<form class="row g-3">
  <div class="col-md-6">
    <label for="inputEmail4" class="form-label">Email</label>
    <input type="email" class="form-control" id="inputEmail4">
  </div>
  <div class="col-md-6">
    <label for="inputPassword4" class="form-label">Password</label>
    <input type="password" class="form-control" id="inputPassword4">
  </div>
  <div class="col-12">
    <label for="inputAddress" class="form-label">Address</label>
    <input type="text" class="form-control" id="inputAddress" placeholder="1234 Main St">
  </div>
  <div class="col-12">
    <label for="inputAddress2" class="form-label">Address 2</label>
    <input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
  </div>
  <div class="col-md-6">
    <label for="inputCity" class="form-label">City</label>
    <input type="text" class="form-control" id="inputCity">
  </div>
  <div class="col-md-4">
    <label for="inputState" class="form-label">State</label>
    <select id="inputState" class="form-select">
      <option selected>Choose...</option>
      <option>...</option>
    </select>
  </div>
  <div class="col-md-2">
    <label for="inputZip" class="form-label">Zip</label>
    <input type="text" class="form-control" id="inputZip">
  </div>
  <div class="col-12">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" id="gridCheck">
      <label class="form-check-label" for="gridCheck">
        Check me out
      </label>
    </div>
  </div>
  <div class="col-12">
    <button type="submit" class="btn btn-primary">Sign in</button>
  </div>
</form>

Ɔrizɔntal fɔm

Krio ɔrizɔntal fɔm dɛn wit di grid bay we yu ad di .rowklas to fɔm grup dɛn ɛn yuz di .col-*-*klas dɛn fɔ sho di wit fɔ yu lɛbl ɛn kɔntrol dɛn. Mek shɔ se yu ad .col-form-labelto yu <label>s bak so dɛn de vertikal sɛntrɛd wit dɛn asosiet fɔm kɔntrol dɛn.

Sɔntɛnde, yu go nid fɔ yuz margin ɔ padding utilities fɔ mek da pafɛkt alaynɛshɔn de we yu nid. Fɔ ɛgzampul, wi dɔn pul di padding-toppan wi stak redio input dɛn lɛbl fɔ mek di tɛks beslayn alaynɛd ​​fayn fayn wan.

Redio dɛn
<form>
  <div class="row mb-3">
    <label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
    <div class="col-sm-10">
      <input type="email" class="form-control" id="inputEmail3">
    </div>
  </div>
  <div class="row mb-3">
    <label for="inputPassword3" class="col-sm-2 col-form-label">Password</label>
    <div class="col-sm-10">
      <input type="password" class="form-control" id="inputPassword3">
    </div>
  </div>
  <fieldset class="row mb-3">
    <legend class="col-form-label col-sm-2 pt-0">Radios</legend>
    <div class="col-sm-10">
      <div class="form-check">
        <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios1" value="option1" checked>
        <label class="form-check-label" for="gridRadios1">
          First radio
        </label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios2" value="option2">
        <label class="form-check-label" for="gridRadios2">
          Second radio
        </label>
      </div>
      <div class="form-check disabled">
        <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios3" value="option3" disabled>
        <label class="form-check-label" for="gridRadios3">
          Third disabled radio
        </label>
      </div>
    </div>
  </fieldset>
  <div class="row mb-3">
    <div class="col-sm-10 offset-sm-2">
      <div class="form-check">
        <input class="form-check-input" type="checkbox" id="gridCheck1">
        <label class="form-check-label" for="gridCheck1">
          Example checkbox
        </label>
      </div>
    </div>
  </div>
  <button type="submit" class="btn btn-primary">Sign in</button>
</form>

Ɔrizɔntal fɔm lɛbl saiz

Mek shɔ se yu yuz .col-form-label-smɔ .col-form-label-lgto yu <label>s ɔ <legend>s fɔ fala di sayz fɔ .form-control-lgɛn kɔrɛkt wan .form-control-sm.

<div class="row mb-3">
  <label for="colFormLabelSm" class="col-sm-2 col-form-label col-form-label-sm">Email</label>
  <div class="col-sm-10">
    <input type="email" class="form-control form-control-sm" id="colFormLabelSm" placeholder="col-form-label-sm">
  </div>
</div>
<div class="row mb-3">
  <label for="colFormLabel" class="col-sm-2 col-form-label">Email</label>
  <div class="col-sm-10">
    <input type="email" class="form-control" id="colFormLabel" placeholder="col-form-label">
  </div>
</div>
<div class="row">
  <label for="colFormLabelLg" class="col-sm-2 col-form-label col-form-label-lg">Email</label>
  <div class="col-sm-10">
    <input type="email" class="form-control form-control-lg" id="colFormLabelLg" placeholder="col-form-label-lg">
  </div>
</div>

Di sayz fɔ di kɔlɔm dɛn

As wi bin dɔn sho na di ɛgzampul dɛn we dɔn pas, wi grid sistɛm de mek yu ebul fɔ put ɛni nɔmba pan .cols insay wan .row. Dem go split di avaylabl width ikwal bitwin dem. Yu kin pik wan sɔbsɛt bak pan yu kɔlɔm dɛn fɔ tek mɔ ɔ smɔl ples, we di ɔda .colwan dɛn we lɛf ikwal split di ɔda wan dɛn, wit sɔm patikyula kɔlɔm klas dɛn lɛk .col-sm-7.

<div class="row g-3">
  <div class="col-sm-7">
    <input type="text" class="form-control" placeholder="City" aria-label="City">
  </div>
  <div class="col-sm">
    <input type="text" class="form-control" placeholder="State" aria-label="State">
  </div>
  <div class="col-sm">
    <input type="text" class="form-control" placeholder="Zip" aria-label="Zip">
  </div>
</div>

Awto-sayz

Di ɛgzampul we de dɔŋ ya de yuz wan fleksbɔks yutiliti fɔ sɛnt di tin dɛn we de insay vertikal wan ɛn chenj .colto .col-autoso dat yu kɔlɔm dɛn go jɔs tek bɔku ples we dɛn nid. If wi put am ɔda we, di kɔlɔm de saiz insɛf bay di tin dɛn we de insay.

@
<form class="row gy-2 gx-3 align-items-center">
  <div class="col-auto">
    <label class="visually-hidden" for="autoSizingInput">Name</label>
    <input type="text" class="form-control" id="autoSizingInput" placeholder="Jane Doe">
  </div>
  <div class="col-auto">
    <label class="visually-hidden" for="autoSizingInputGroup">Username</label>
    <div class="input-group">
      <div class="input-group-text">@</div>
      <input type="text" class="form-control" id="autoSizingInputGroup" placeholder="Username">
    </div>
  </div>
  <div class="col-auto">
    <label class="visually-hidden" for="autoSizingSelect">Preference</label>
    <select class="form-select" id="autoSizingSelect">
      <option selected>Choose...</option>
      <option value="1">One</option>
      <option value="2">Two</option>
      <option value="3">Three</option>
    </select>
  </div>
  <div class="col-auto">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" id="autoSizingCheck">
      <label class="form-check-label" for="autoSizingCheck">
        Remember me
      </label>
    </div>
  </div>
  <div class="col-auto">
    <button type="submit" class="btn btn-primary">Submit</button>
  </div>
</form>

Dɔn yu kin rimiks dat wan tɛm bak wit saiz-spɛsifi k kɔlɔm klas dɛn.

@
<form class="row gx-3 gy-2 align-items-center">
  <div class="col-sm-3">
    <label class="visually-hidden" for="specificSizeInputName">Name</label>
    <input type="text" class="form-control" id="specificSizeInputName" placeholder="Jane Doe">
  </div>
  <div class="col-sm-3">
    <label class="visually-hidden" for="specificSizeInputGroupUsername">Username</label>
    <div class="input-group">
      <div class="input-group-text">@</div>
      <input type="text" class="form-control" id="specificSizeInputGroupUsername" placeholder="Username">
    </div>
  </div>
  <div class="col-sm-3">
    <label class="visually-hidden" for="specificSizeSelect">Preference</label>
    <select class="form-select" id="specificSizeSelect">
      <option selected>Choose...</option>
      <option value="1">One</option>
      <option value="2">Two</option>
      <option value="3">Three</option>
    </select>
  </div>
  <div class="col-auto">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" id="autoSizingCheck2">
      <label class="form-check-label" for="autoSizingCheck2">
        Remember me
      </label>
    </div>
  </div>
  <div class="col-auto">
    <button type="submit" class="btn btn-primary">Submit</button>
  </div>
</form>

Fɔm dɛn we de insay di layn

Yuz di .row-cols-*klas dɛn fɔ mek ɔrizɔntal layout dɛn we de ansa. Bay we wi ad gɔta modifya klas dɛn , wi go gɛt gɔta dɛn na ɔrizɔntal ɛn vertikal dairekshɔn dɛn. Na smɔl mobayl viupɔt dɛn, di .col-12ɛp fɔ stak di fɔm kɔntrol dɛn ɛn mɔ. Di .align-items-centeralayns di fɔm ɛlimɛnt dɛn to di midul, mek di .form-checkboxalaynɛshɔn fayn fayn wan.

@
<form class="row row-cols-lg-auto g-3 align-items-center">
  <div class="col-12">
    <label class="visually-hidden" for="inlineFormInputGroupUsername">Username</label>
    <div class="input-group">
      <div class="input-group-text">@</div>
      <input type="text" class="form-control" id="inlineFormInputGroupUsername" placeholder="Username">
    </div>
  </div>

  <div class="col-12">
    <label class="visually-hidden" for="inlineFormSelectPref">Preference</label>
    <select class="form-select" id="inlineFormSelectPref">
      <option selected>Choose...</option>
      <option value="1">One</option>
      <option value="2">Two</option>
      <option value="3">Three</option>
    </select>
  </div>

  <div class="col-12">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" id="inlineFormCheck">
      <label class="form-check-label" for="inlineFormCheck">
        Remember me
      </label>
    </div>
  </div>

  <div class="col-12">
    <button type="submit" class="btn btn-primary">Submit</button>
  </div>
</form>