Form Elements
Build quick and clean forms with generic form elements
Basic inputs
Basic HTML input elements have 100% width and work best when used alongside OrbitCSS' grids.
<div class="column is-half"> <input type="text" placeholder="HTML text input"> </div>
Input controls
Readonly
The readonly
attribute will prevent modification of the input element's value.
<input type="text" placeholder="Readonly text input" readonly>
Disabled
The disabled
attribute is similar to the readonly
attribute but will also grey out the input element and retain the pointer cursor.
<input type="text" placeholder="Disabled text input" disabled>
Labels
Label elements will neatly sit above the input element.
<div class="column is-half"> <label>Name</label> <input type="text"> </div>
Inline labels
You can use columns to create inline labels and the is-inline-label
modifier to vertically align the label.
<div class="column is-shrink is-inline-label"> <label>Name</label> </div> <div class="column is-half"> <input type="text"> </div>
The is-inline-label
modifier can actually be used on any content, not just labels.
Select
Use the is-select
modifier to create a clean and simple select element.
<div class="is-select"> <select> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select> </div>
The is-loading
modifier can be used to replace the arrow with a loading spinner.
<div class="is-select is-loading"> <select> ... </select> </div>
Multiple select
If you are withing a multiple select element, you'll want to use the is-multiple-select
modifier on the div wrapper and the multiple
attribute on the select element.
<div class="is-multiple-select"> <select multiple> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> <option>Option 4</option> <option>Option 5</option> </select> </div>
Textarea
Textareas are simply a multi-line version of the input element.
<textarea rows="3"></textarea>
Resizing
If you want the textarea to be resizable, use one of the following modifiers:
has-resize
has-resize-vertical
has-resize-horizontal
<textarea rows="3" class="has-resize"></textarea>
The has-resize-vertical
and has-resize-horizontal
modifiers will limit resizing to only either the x (horizontal) or y (vertical) axis.
Checkbox
Use the is-checkbox
modifier to create a flexbox powered checkbox container. Each input
element and optional label
element should be wrapped in a span
.
<div class="is-checkbox"> <span> <input type="checkbox"> <label>Cats</label> </span> <span> <input type="checkbox"> <label>Dogs</label> </span> <span> <input type="checkbox"> <label>Ducks (the obvious choice)</label> </span> </div>
Radio
Just like the checkbox, the is-radio
modifier will create a flexbox powered container for your radio fields. Each input
element and optional label
element should be wrapped in a span
.
<div class="is-radio"> <span> <input type="radio" name="fav-animal"> <label>Cats</label> </span> <span> <input type="radio" name="fav-animal"> <label>Dogs</label> </span> <span> <input type="radio" name="fav-animal"> <label>Ducks (the obvious choice)</label> </span> </div>
Input group
The is-input-group
modifier can be used to group form elements inline.
<div class="is-input-group"> <span>+61</span> <input type="text" placeholder="Your phone number"> </div>
All span
and label
HTML elements will be displayed in a bordered box with a light background, only taking up as much room as required to display their inner content.
<div class="is-input-group"> <label>Percentage:</label> <input type="number" value="20"> <span>%</span> </div>
Each input
and select
element will divide up the remaining space equally.
<div class="is-input-group"> <div class="is-select"> <select> <option>Option 1</option> <option>Option 2</option> </select> </div> <input type="text"> </div>
Input groups also support the use of Buttons.
<div class="is-input-group"> <input type="text"> <button class="button is-primary">Search</button> </div>
Form errors
The has-error
modifier can be used to indicate an error. This will add a red border and background to input
, textarea
and select
elements.
<input type="text" class="has-error">
<textarea class="has-error"></textarea>
<div class="is-select"> <select class="has-error"> <option>Option 1</option> <option>Option 2</option> </select> </div>
File input
You can create a clean and modern looking file input using the is-file-input
modifier and a button.
<div class="is-file-input"> <input type="file" id="exampleFileInput"> <label for="exampleFileInput" class="button is-primary"> <span>Upload File</span> <span class="icon"> <i class="fas fa-upload"></i> </span> </label> </div>
CSS variables
Customize the basic input element using the following CSS variables.
input, textarea, select { --border-width: 1px; --border-radius: 0; --box-shadow: inset 0 1px 2px hsl(0deg, 0%, 3.9215686275%, 0.1); --font-size: 1rem; --line-height: 1.5; --padding: 0.5rem; --background-color: var(--color-white); --border-color: hsl(0deg, 0%, 85.8823529412%, 1); --font-color: var(--color-black); --padding: 0.5rem; --focus-border-color: var(--color-info); --focus-box-shadow: 0 0 0 0.125em hsl(217deg, 71%, 53%, 0.25); --disabled-background-color: var(--color-disabled); --disabled-box-shadow: none; --disabled-font-color: var(--color-muted); --disabled-border-color: var(--color-disabled); --error-border-color: var(--color-danger); --error-background-color: var(--color-danger-alert); --error-font-color: var(--color-black); }
Select elements have the additional variables.
.is-select { --arrow-color: hsl(232deg, 100%, 72%, 1); --arrow-width: 0.625em; --loading-spinner-speed: 0.8s; --loading-icon-width: 2px; --loading-icon-color: var(--color-light-grey); }
You can customize form labels with these variables.
label { --font-size: 1rem; --font-weight: 600; --line-height: 1.6; --font-color: inherit; }
Input groups also have their own set of variables.
.is-input-group { --background-color: var(--color-disabled); --border-color: hsl(0deg, 0%, 86%, 1); --border-width: 1px; --font-color: var(--color-black); --font-size: 1rem; --focus-color: var(--color-info); }
Sass variables
The default styles can be overridden with the following variables. Set one or more of these variables before you import the framework.
Variable | Type | Default value |
---|---|---|
$input-background-color | color | hsl(0deg, 0%, 100%, 1) |
$input-border-color | color | hsl(0deg, 0%, 86%, 1) |
$input-border-width | units | 1px |
$input-border-radius | units | 0 |
$input-color | color | hsl(0deg, 0%, 22%, 1) |
$input-shadow | box-shadow | inset 0 1px 2px hsl(0deg, 0%, 4%, 0.1) |
$input-font-size | units | 1rem |
$input-line-height | unitless | 1.5 |
$input-padding | units | 0.5rem |
$input-focus-border | color | hsl(215, 97%, 87%, 1) |
$input-focus-shadow | box-shadow | 0 0 0 0.125em hsl(217deg, 70%, 53%, 0.25) |
$input-disabled-background | color | hsl(0deg, 0%, 97%, 1) |
$input-disabled-border | color | hsl(0deg, 0%, 97%, 1) |
$input-disabled-color | color | hsl(0deg, 0%, 73%, 1) |
$input-error-background | color | hsl(348deg, 100%, 58%, 0.2) |
$input-error-color | color | hsl(0deg, 0%, 22%, 1) |
$input-error-border-color | color | hsl(347deg, 100%, 58%, 1) |
$select-arrow-color | color | hsl(232deg, 100%, 72%, 1) |
$select-arrow-width | units | 0.625em |
$select-padding | units | 0.5rem |
$select-multiple-padding | padding | .5rem 1rem |
$select-loading-speed | seconds | .8s |
$select-loading-width | units | 2px |
$select-loading-color | color | hsl(32deg, 12%, 82%, 1) |
$label-font-weight | unitless | 600 |
$label-bottom-margin | units | 0.375rem |
$label-line-height | unitless | 1.6 |
$label-font-size | units | 1rem |