2015-03-21 02:30:22 +03:00
---
layout: page
title: Forms
---
Style individual form controls and utilize common layouts.
< div class = "flash" >
< strong > Heads up!< / strong > Forms need some reworking to clean up the specificity and required markup. We'll get to that soon!
< / div >
## Contents
* Will be replaced with the ToC, excluding the "Contents" header
{:toc}
## Overview
- We reset several elements' default styles for cross browser consistency and easier manipulation later. This includes `<fieldset>` s, WebKit validation bubbles, and most textual `<input>` s.
- Specific types of textual `<input>` s are styled automatically, but `.form-control` is available should you need it.
- Always declare a `type` on your `<button>` s.
- Form layouts rely on form groups.
## Example form
Form controls in Primer currently have no basic layout specified (this is by design). You'll need to use `<fieldset>` s, `<div>` s, or other elements and styles to rearrange them.
{% example html %}
< form >
< label for = "name" > Name< / label >
2015-09-11 21:17:39 +03:00
< input class = "form-control" type = "text" id = "name" >
2015-03-21 02:30:22 +03:00
< label for = "email" > Email address< / label >
2015-09-11 21:17:39 +03:00
< input class = "form-control" type = "email" id = "email" >
2015-03-21 02:30:22 +03:00
< label >
< input type = "checkbox" > Remember me
< / label >
< label >
< input type = "radio" id = "herp" name = "herpderp" checked > Herp
< / label >
< label >
< input type = "radio" id = "derp" name = "herpderp" > Derp
< / label >
< button class = "btn" type = "submit" > Submit< / button >
< / form >
{% endexample %}
## Form contrast
Textual form controls have a white background by default. You can change this to a light gray with `.input-contrast` .
{% example html %}
< form >
2015-09-11 21:17:39 +03:00
< input class = "form-control" type = "text" placeholder = "Default input" >
< input class = "form-control input-contrast" type = "text" placeholder = "Input with contrast" >
2015-03-21 02:30:22 +03:00
< / form >
{% endexample %}
## Sizing
Make inputs smaller, larger, or full-width with an additional class.
2015-09-11 21:17:39 +03:00
### Small
2015-03-21 02:30:22 +03:00
{% example html %}
< form >
2015-09-11 21:17:39 +03:00
< input class = "form-control input-sm" type = "text" placeholder = "Small input" >
2015-03-21 02:30:22 +03:00
< / form >
{% endexample %}
### Large
{% example html %}
< form >
2015-09-11 21:17:39 +03:00
< input class = "form-control input-lg" type = "text" placeholder = "Large input" >
2015-03-21 02:30:22 +03:00
< / form >
{% endexample %}
### Block
{% example html %}
< form >
2015-09-11 21:17:39 +03:00
< input class = "form-control input-block" type = "text" placeholder = "Full-width input" >
2015-03-21 02:30:22 +03:00
< / form >
{% endexample %}
2015-06-10 22:40:25 +03:00
## Selects
2015-06-10 01:17:02 +03:00
2015-06-10 22:40:25 +03:00
Primer adds light `height` and `vertical-align` styles to `<select>` s for all browsers to render them consistently with textual inputs.
2015-06-10 01:17:02 +03:00
{% example html %}
< form >
2016-03-14 18:44:18 +03:00
< select class = "form-select" >
2015-06-10 01:17:02 +03:00
< option > Choose an option< / option >
< option > Git< / option >
< option > Subversion< / option >
< option > Social Coding< / option >
< option > Beets< / option >
< option > Bears< / option >
< option > Battlestar Galactica< / option >
< / select >
2015-06-10 22:40:40 +03:00
< / form >
{% endexample %}
### Custom
2015-06-10 01:17:02 +03:00
2015-06-10 22:40:40 +03:00
Custom `<select>` s are also available—just add `.select` . **Only available in latest WebKit, Firefox, and IE browsers.**
{% example html %}
< form >
2016-03-14 18:44:18 +03:00
< select class = "form-select" >
2015-06-10 01:17:02 +03:00
< option > Choose an option< / option >
< option > Git< / option >
< option > Subversion< / option >
< option > Social Coding< / option >
< option > Beets< / option >
< option > Bears< / option >
< option > Battlestar Galactica< / option >
< / select >
< / form >
{% endexample %}
### Small
2015-06-10 22:41:40 +03:00
Use the `.select-sm` class to resize both default and custom `<select>` s to match the size of [our small buttons ](/buttons/#default-buttons ).
2015-06-10 01:17:02 +03:00
{% example html %}
2016-03-14 18:44:18 +03:00
< select class = "form-select select-sm" >
2015-06-10 01:17:02 +03:00
< option > Choose an option< / option >
< option > Git< / option >
< option > Subversion< / option >
< option > Social Coding< / option >
< option > Beets< / option >
< option > Bears< / option >
< option > Battlestar Galactica< / option >
< / select >
2016-03-14 18:44:18 +03:00
< select class = "form-select select-sm" >
2015-06-10 01:17:02 +03:00
< option > Choose an option< / option >
< option > Git< / option >
< option > Subversion< / option >
< option > Social Coding< / option >
< option > Beets< / option >
< option > Bears< / option >
< option > Battlestar Galactica< / option >
< / select >
{% endexample %}
2015-03-21 02:30:22 +03:00
## Form groups
{% example html %}
< form >
2016-03-14 18:13:00 +03:00
< dl class = "form-group" >
2015-03-21 02:30:22 +03:00
< dt > < label > Example Text< / label > < / dt >
2015-09-11 21:17:39 +03:00
< dd > < input class = "form-control" type = "text" value = "Example Value" > < / dd >
2015-03-21 02:30:22 +03:00
< / dl >
2016-03-14 18:13:00 +03:00
< dl class = "form-group" >
< dt > < label > Example Select< / label > < / dt >
2015-03-21 02:30:22 +03:00
< dd >
2016-03-14 18:44:18 +03:00
< select class = "form-select" >
2015-03-21 02:30:22 +03:00
< option > Choose an option< / option >
< option > Git< / option >
< option > Subversion< / option >
< option > Social Coding< / option >
< option > Beets< / option >
< option > Bears< / option >
< option > Battlestar Galactica< / option >
< / select >
< / dd >
< / dl >
2016-03-14 18:13:00 +03:00
< dl class = "form-group" >
< dt > < label > Example Textarea< / label > < / dt >
< dd >
< textarea class = "form-control" > < / textarea >
< / dd >
< / dl >
2015-03-21 02:30:22 +03:00
< / form >
{% endexample %}
2015-06-24 23:38:28 +03:00
## Form group validation
2016-03-14 18:13:00 +03:00
Convey errors and warnings for form groups. Add the appropriate class—either `.errored` or `.warn` —to the `<dl class="form-group">` to start. Then, house your error messaging in an additional `<dd>` with either `.error` or `.warning` .
2015-06-24 23:38:28 +03:00
{% example html %}
< form >
2016-03-14 18:13:00 +03:00
< dl class = "form-group errored" >
2015-06-24 23:38:28 +03:00
< dt > < label > Example Text< / label > < / dt >
2015-09-11 21:17:39 +03:00
< dd > < input class = "form-control" type = "text" value = "Example Value" > < / dd >
2015-06-24 23:38:28 +03:00
< dd class = "error" > This example input has an error.< / dd >
< / dl >
< br >
2016-03-14 18:13:00 +03:00
< dl class = "form-group warn" >
2015-06-24 23:38:28 +03:00
< dt > < label > Example Text< / label > < / dt >
2015-09-11 21:17:39 +03:00
< dd > < input class = "form-control" type = "text" value = "Example Value" > < / dd >
2015-06-25 00:42:42 +03:00
< dd class = "warning" > This example input has a warning.< / dd >
2015-06-24 23:38:28 +03:00
< / dl >
< / form >
{% endexample %}
2015-03-21 02:30:22 +03:00
## Checkboxes and radios
Utilities to spice up the alignment and styling of checkbox and radio controls.
{% example html %}
< form >
< div class = "form-checkbox" >
< label >
< input type = "checkbox" checked = "checked" >
Available for hire
< / label >
< p class = "note" >
This will do insanely < strong > awesome< / strong > and < strong > amazing< / strong > things!
< / p >
< / div >
< / form >
{% endexample %}
You may also add emphasis to the label:
{% example html %}
< form >
< div class = "form-checkbox" >
< label >
< input type = "checkbox" checked = "checked" >
< em class = "highlight" > Available for hire< / em >
< / label >
< / div >
< / form >
{% endexample %}
## Input group
Attached an input and button to one another.
{% example html %}
< form >
< div class = "input-group" >
2015-09-11 21:17:39 +03:00
< input class = "form-control" type = "text" placeholder = "Username" >
2015-03-21 02:30:22 +03:00
< span class = "input-group-button" >
< button class = "btn" >
< span class = "octicon octicon-clippy" > < / span >
< / button >
< / span >
< / div >
< / form >
{% endexample %}
## Form actions
Align buttons to the right—via `float: right` on the buttons—in forms with `.form-actions` . The floats are automatically cleared for you.
{% example html %}
< div class = "form-actions" >
< button type = "button" class = "btn btn-primary" > Save changes< / button >
< button type = "button" class = "btn" > Cancel< / button >
< / div >
{% endexample %}