JustBusiness - Luxury Services
23/12/24

FormsTwitter Bootstrap Based

Default styles

Individual form controls receive styling, but without any required base class on the <form> or large changes in markup. Results in stacked, left-aligned labels on top of form controls.

Legend



Example block-level help text here.


  1. <form>
  2. <fieldset>
  3. <legend>Legend</legend>
  4. <label>Label name</label>
  5. <input type="text" placeholder="Type something…">
  6. <span class="help-block">Example block-level help text here.</span>
  7. <label class="checkbox">
  8. <input type="checkbox"> Check me out
  9. </label>
  10. <button type="submit" class="btn">Submit</button>
  11. </fieldset>
  12. </form>

Optional layouts

Included with Bootstrap are three optional form layouts for common use cases.

Search form

Add .form-search to the form and .search-query to the <input> for an extra-rounded text input.

  1. <form class="form-search">
  2. <input type="text" class="input-medium search-query">
  3. <button type="submit" class="btn">Search</button>
  4. </form>

Inline form

Add .form-inline for left-aligned labels and inline-block controls for a compact layout.





  1. <form class="form-inline">
  2. <input type="text" class="input-small" placeholder="Email">
  3. <input type="password" class="input-small" placeholder="Password">
  4. <label class="checkbox">
  5. <input type="checkbox"> Remember me
  6. </label>
  7. <button type="submit" class="btn">Sign in</button>
  8. </form>

Horizontal form

Right align labels and float them to the left to make them appear on the same line as controls. Requires the most markup changes from a default form:

  • Add .form-horizontal to the form
  • Wrap labels and controls in .control-group
  • Add .control-label to the label
  • Wrap any associated controls in .controls for proper alignment


  1. <form class="form-horizontal">
  2. <div class="control-group">
  3. <label class="control-label" for="inputEmail">Email</label>
  4. <div class="controls">
  5. <input type="text" id="inputEmail" placeholder="Email">
  6. </div>
  7. </div>
  8. <div class="control-group">
  9. <label class="control-label" for="inputPassword">Password</label>
  10. <div class="controls">
  11. <input type="password" id="inputPassword" placeholder="Password">
  12. </div>
  13. </div>
  14. <div class="control-group">
  15. <div class="controls">
  16. <label class="checkbox">
  17. <input type="checkbox"> Remember me
  18. </label>
  19. <button type="submit" class="btn">Sign in</button>
  20. </div>
  21. </div>
  22. </form>

Supported form controls

Examples of standard form controls supported in an example form layout.

Inputs

Most common form control, text-based input fields. Includes support for all HTML5 types: text, password, datetime, datetime-local, date, month, time, week, number, email, url, search, tel, and color.

Requires the use of a specified type at all times.


  1. <input type="text" placeholder="Text input">

Textarea

Form control which supports multiple lines of text. Change rows attribute as necessary.


  1. <textarea rows="3"></textarea>

Checkboxes and radios

Checkboxes are for selecting one or several options in a list while radios are for selecting one option from many.

Default (stacked)





  1. <label class="checkbox">
  2. <input type="checkbox" value="">
  3. Option one is this and that—be sure to include why it's great
  4. </label>
  5.  
  6. <label class="radio">
  7. <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
  8. Option one is this and that—be sure to include why it's great
  9. </label>
  10. <label class="radio">
  11. <input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">
  12. Option two can be something else and selecting it will deselect option one
  13. </label>

Inline checkboxes

Add the .inline class to a series of checkboxes or radios for controls appear on the same line.




  1. <label class="checkbox inline">
  2. <input type="checkbox" id="inlineCheckbox1" value="option1"> 1
  3. </label>
  4. <label class="checkbox inline">
  5. <input type="checkbox" id="inlineCheckbox2" value="option2"> 2
  6. </label>
  7. <label class="checkbox inline">
  8. <input type="checkbox" id="inlineCheckbox3" value="option3"> 3
  9. </label>

Selects

Use the default option or specify a multiple="multiple" to show multiple options at once.

  1. <select>
  2. <option>1</option>
  3. <option>2</option>
  4. <option>3</option>
  5. <option>4</option>
  6. <option>5</option>
  7. </select>
  8.  
  9. <select multiple="multiple">
  10. <option>1</option>
  11. <option>2</option>
  12. <option>3</option>
  13. <option>4</option>
  14. <option>5</option>
  15. </select>

Extending form controls

Adding on top of existing browser controls, Bootstrap includes other useful form components.

Prepended and appended inputs

Add text or buttons before or after any text-based input. Do note that select elements are not supported here.

Default options

Wrap an .add-on and an input with one of two classes to prepend or append text to an input.

@


.00
  1. <div class="input-prepend">
  2. <span class="add-on">@</span>
  3. <input class="span2" id="prependedInput" type="text" placeholder="Username">
  4. </div>
  5. <div class="input-append">
  6. <input class="span2" id="appendedInput" type="text">
  7. <span class="add-on">.00</span>
  8. </div>

Combined

Use both classes and two instances of .add-on to prepend and append an input.

$

.00
  1. <div class="input-prepend input-append">
  2. <span class="add-on">$</span>
  3. <input class="span2" id="appendedPrependedInput" type="text">
  4. <span class="add-on">.00</span>
  5. </div>

Buttons instead of text

Instead of a <span> with text, use a .btn to attach a button (or two) to an input.


  1. <div class="input-append">
  2. <input class="span2" id="appendedInputButton" type="text">
  3. <button class="btn" type="button">Go!</button>
  4. </div>


  1. <div class="input-append">
  2. <input class="span2" id="appendedInputButtons" type="text">
  3. <button class="btn" type="button">Search</button>
  4. <button class="btn" type="button">Options</button>
  5. </div>

Button dropdowns


  1. <div class="input-append">
  2. <input class="span2" id="appendedDropdownButton" type="text">
  3. <div class="btn-group">
  4. <button class="btn dropdown-toggle" data-toggle="dropdown">
  5. Action
  6. <span class="caret"></span>
  7. </button>
  8. <ul class="dropdown-menu">
  9. ...
  10. </ul>
  11. </div>
  12. </div>


  1. <div class="input-prepend">
  2. <div class="btn-group">
  3. <button class="btn dropdown-toggle" data-toggle="dropdown">
  4. Action
  5. <span class="caret"></span>
  6. </button>
  7. <ul class="dropdown-menu">
  8. ...
  9. </ul>
  10. </div>
  11. <input class="span2" id="prependedDropdownButton" type="text">
  12. </div>


  1. <div class="input-prepend input-append">
  2. <div class="btn-group">
  3. <button class="btn dropdown-toggle" data-toggle="dropdown">
  4. Action
  5. <span class="caret"></span>
  6. </button>
  7. <ul class="dropdown-menu">
  8. ...
  9. </ul>
  10. </div>
  11. <input class="span2" id="appendedPrependedDropdownButton" type="text">
  12. <div class="btn-group">
  13. <button class="btn dropdown-toggle" data-toggle="dropdown">
  14. Action
  15. <span class="caret"></span>
  16. </button>
  17. <ul class="dropdown-menu">
  18. ...
  19. </ul>
  20. </div>
  21. </div>

Segmented dropdown groups

  1. <form>
  2. <div class="input-prepend">
  3. <div class="btn-group">...</div>
  4. <input type="text">
  5. </div>
  6. <div class="input-append">
  7. <input type="text">
  8. <div class="btn-group">...</div>
  9. </div>
  10. </form>

Search form

  1. <form class="form-search">
  2. <div class="input-append">
  3. <input type="text" class="span2 search-query">
  4. <button type="submit" class="btn">Search</button>
  5. </div>
  6. <div class="input-prepend">
  7. <button type="submit" class="btn">Search</button>
  8. <input type="text" class="span2 search-query">
  9. </div>
  10. </form>

Control sizing

Use relative sizing classes like .input-large or match your inputs to the grid column sizes using .span* classes.

Block level inputs

Make any <input> or <textarea> element behave like a block level element.

  1. <input class="input-block-level" type="text" placeholder=".input-block-level">

Relative sizing






  1. <input class="input-mini" type="text" placeholder=".input-mini">
  2. <input class="input-small" type="text" placeholder=".input-small">
  3. <input class="input-medium" type="text" placeholder=".input-medium">
  4. <input class="input-large" type="text" placeholder=".input-large">
  5. <input class="input-xlarge" type="text" placeholder=".input-xlarge">
  6. <input class="input-xxlarge" type="text" placeholder=".input-xxlarge">

Heads up! In future versions, we’ll be altering the use of these relative input classes to match our button sizes. For example, .input-large will increase the padding and font-size of an input.

Grid sizing

Use .span1 to .span12 for inputs that match the same sizes of the grid columns.



  1. <input class="span1" type="text" placeholder=".span1">
  2. <input class="span2" type="text" placeholder=".span2">
  3. <input class="span3" type="text" placeholder=".span3">
  4. <select class="span1">
  5. ...
  6. </select>
  7. <select class="span2">
  8. ...
  9. </select>
  10. <select class="span3">
  11. ...
  12. </select>

For multiple grid inputs per line, use the .controls-row modifier class for proper spacing. It floats the inputs to collapse white-space, sets the proper margins, and clears the float.





  1. <div class="controls">
  2. <input class="span5" type="text" placeholder=".span5">
  3. </div>
  4. <div class="controls controls-row">
  5. <input class="span4" type="text" placeholder=".span4">
  6. <input class="span1" type="text" placeholder=".span1">
  7. </div>
  8. ...

Uneditable inputs

Present data in a form that’s not editable without using actual form markup.

Some value here
  1. <span class="input-xlarge uneditable-input">Some value here</span>

Form actions

End a form with a group of actions (buttons). When placed within a .form-actions, the buttons will automatically indent to line up with the form controls.


  1. <div class="form-actions">
  2. <button type="submit" class="btn btn-primary">Save changes</button>
  3. <button type="button" class="btn">Cancel</button>
  4. </div>

Help text

Inline and block level support for help text that appears around form controls.

Inline help

Inline help text
  1. <input type="text"><span class="help-inline">Inline help text</span>

Block help


A longer block of help text that breaks onto a new line and may extend beyond one line.
  1. <input type="text"><span class="help-block">A longer block of help text that breaks onto a new line and may extend beyond one line.</span>

Form control states

Provide feedback to users or visitors with basic feedback states on form controls and labels.

Input focus

We remove the default outline styles on some form controls and apply a box-shadow in its place for :focus.


  1. <input class="input-xlarge" id="focusedInput" type="text" value="This is focused...">

Invalid inputs

Style inputs via default browser functionality with :invalid. Specify a type, add the required attribute if the field is not optional, and (if applicable) specify a pattern.

This is not available in versions of Internet Explorer 7-9 due to lack of support for CSS pseudo selectors.


  1. <input class="span3" type="email" required>

Disabled inputs

Add the disabled attribute on an input to prevent user input and trigger a slightly different look.


  1. <input class="input-xlarge" id="disabledInput" type="text" placeholder="Disabled input here..." disabled>

Validation states

Bootstrap includes validation styles for error, warning, info, and success messages. To use, add the appropriate class to the surrounding .control-group.


Something may have gone wrong


Please correct the error


Username is taken


Woohoo!
  1. <div class="control-group warning">
  2. <label class="control-label" for="inputWarning">Input with warning</label>
  3. <div class="controls">
  4. <input type="text" id="inputWarning">
  5. <span class="help-inline">Something may have gone wrong</span>
  6. </div>
  7. </div>
  8.  
  9. <div class="control-group error">
  10. <label class="control-label" for="inputError">Input with error</label>
  11. <div class="controls">
  12. <input type="text" id="inputError">
  13. <span class="help-inline">Please correct the error</span>
  14. </div>
  15. </div>
  16.  
  17. <div class="control-group info">
  18. <label class="control-label" for="inputInfo">Input with info</label>
  19. <div class="controls">
  20. <input type="text" id="inputInfo">
  21. <span class="help-inline">Username is already taken</span>
  22. </div>
  23. </div>
  24.  
  25. <div class="control-group success">
  26. <label class="control-label" for="inputSuccess">Input with success</label>
  27. <div class="controls">
  28. <input type="text" id="inputSuccess">
  29. <span class="help-inline">Woohoo!</span>
  30. </div>
  31. </div>