Référence des formulaires CSS Bootstrap


Paramètres par défaut de Bootstrap

Les contrôles de formulaire individuels reçoivent automatiquement un style global avec Bootstrap.

Tous les éléments textuels <input>, <textarea> et <select> avec class="form-control" sont définis sur width : 100 % ; par défaut.

Règles standard pour les trois mises en page de formulaire :

  • Enveloppez les étiquettes et les contrôles de formulaire <div class="form-group">(nécessaire pour un espacement optimal)
  • Ajouter une classe à tous les éléments .form-controltextuels <input>, <textarea>et<select>

L'exemple suivant crée un formulaire Bootstrap simple avec deux champs de saisie, une case à cocher et un bouton d'envoi :

Exemple de formulaire Bootstrap

<form>
  <div class="form-group">
    <label for="email">Email address:</label>
    <input type="email" class="form-control" id="email">
  </div>
  <div class="form-group">
    <label for="pwd">Password:</label>
    <input type="password" class="form-control" id="pwd">
  </div>
  <div class="checkbox">
    <label><input type="checkbox"> Remember me</label>
  </div>
  <button type="submit" class="btn btn-default">Submit</button>
</form>

Classes de formulaire

Class Description Example
.form-inline Makes a <form> left-aligned with inline-block controls (This only applies to forms within viewports that are at least 768px wide)
.form-horizontal Aligns labels and groups of form controls in a horizontal layout
.form-control Used on input, textarea, and select elements to span the entire width of the page and make them responsive
.form-control-feedback Form validation class
.form-control-static Adds plain text next to a form label within a horizontal form
.form-group Container for form input and label

Classes d'entrée

Class Description Example
.input-group Container to enhance an input by adding an icon, text or a button in front or behind it as a "help text"
.input-group-lg Large input group
.input-group-sm Small input group
.input-group-addon Together with the .input-group class, this class makes it possible to add an icon or help text next to the input field
.input-group-btn Together with the .input-group class, this class attaches a button next to an input. Often used as a search bar
.input-lg Large input field
.input-sm Small input field