Easily create nice looking forms with different styles and layouts.
Usage
Add one of the following classes to form controls inside a <form>
element to define them.
Class | Description |
---|---|
.gls-input |
Add this class to <input> elements. |
.gls-select |
Add this class to <select> elements. |
.gls-textarea |
Add this class to <textarea> elements. |
.gls-radio |
Add this class to <input type="radio"> elements to create radio buttons. |
.gls-checkbox |
Add this class to <input type="checkbox"> elements to create checkboxes. |
.gls-range |
Add this class to <input type="range"> elements to create range forms. |
<form>
<select class="gls-select">
<option></option>
<option></option>
</select>
<textarea class="gls-textarea"></textarea>
<input class="gls-radio" type="radio">
<input class="gls-checkbox" type="checkbox">
<input class="gls-range" type="range">
</form>
Add the .gls-fieldset
class to a <fieldset>
element and the .gls-legend
class to a <legend>
element to define a fieldset and a form legend.
<form> <fieldset class="gls-fieldset"> <legend class="gls-legend">Legend</legend> <div class="gls-margin"> <input class="gls-input" type="text" placeholder="Input"> </div> <div class="gls-margin"> <select class="gls-select"> <option>Option 01</option> <option>Option 02</option> </select> </div> <div class="gls-margin"> <textarea class="gls-textarea" rows="5" placeholder="Textarea"></textarea> </div> <div class="gls-margin gls-grid-small gls-child-width-auto gls-grid"> <label><input class="gls-radio" type="radio" name="radio2" checked> A</label> <label><input class="gls-radio" type="radio" name="radio2"> B</label> </div> <div class="gls-margin gls-grid-small gls-child-width-auto gls-grid"> <label><input class="gls-checkbox" type="checkbox" checked> A</label> <label><input class="gls-checkbox" type="checkbox"> B</label> </div> <div class="gls-margin"> <input class="gls-range" type="range" value="2" min="0" max="10" step="0.1"> </div> </fieldset> </form>
States modifiers
Provide the user with basic information through feedback states on form controls by using one of the following classes.
Class | Description |
---|---|
.gls-form-danger |
Add this class to notify the user that the value is not validated. |
.gls-form-success |
Add this class to notify the user that the value is validated. |
Add the disabled
attribute to a form control. It will appear muted.
-
<div class="gls-margin"> <input class="gls-input gls-form-danger gls-form-width-medium" type="text" placeholder="form-danger" value="form-danger"> </div> <div class="gls-margin"> <input class="gls-input gls-form-success gls-form-width-medium" type="text" placeholder="form-success" value="form-success"> </div> <div class="gls-margin"> <input class="gls-input gls-form-width-medium" type="text" placeholder="disabled" value="disabled" disabled> </div>
Size modifiers
Add one of the classes to an <input>
, <select>
or <textarea>
element to modify its size.
Class | Description |
---|---|
.gls-form-large |
Add this class to make the element larger. |
.gls-form-small |
Add this class to make the element smaller. |
<form> <div class="gls-margin"> <input class="gls-input gls-form-width-medium gls-form-large" type="text" placeholder="Large"> </div> <div class="gls-margin"> <input class="gls-input gls-form-width-medium" type="text" placeholder="Default"> </div> <div class="gls-margin"> <input class="gls-input gls-form-width-medium gls-form-small" type="text" placeholder="Small"> </div> </form>
Width modifiers
Add one of the following classes to an <input>
, <select>
or <textarea>
element to adjust its width.
Class | Description |
---|---|
.gls-form-width-large |
Applies a width of 500px. |
.gls-form-width-medium |
Applies a width of 200px. |
.gls-form-width-small |
Applies a width of 130px. |
.gls-form-width-xsmall |
Applies a width of 40px. |
<form> <div class="gls-margin"> <input class="gls-input gls-form-width-large" type="text" placeholder="Large"> </div> <div class="gls-margin"> <input class="gls-input gls-form-width-medium" type="text" placeholder="Medium"> </div> <div class="gls-margin"> <input class="gls-input gls-form-width-small" type="text" placeholder="Small"> </div> <div class="gls-margin"> <input class="gls-input gls-form-width-xsmall" type="text" placeholder="X-Small"> </div> </form>
You can also apply the .gls-width-*
classes from the Width component to form controls.
<form> <input class="gls-input gls-width-1-2" type="text" placeholder="gls-width-1-2"> </form>
Blank modifier
Add the .gls-form-blank
class to minimize the styling of form controls.
<form> <input class="gls-input gls-form-blank gls-form-width-medium" type="text" placeholder="Form blank"> </form>
Layout
Define labels and controls and apply a stacked or horizontal layout to form elements. Layout modifiers can be added to any parent element like the <fieldset>
element. This makes it possible to have different form layouts for each fieldset.
Class | Description |
---|---|
.gls-form-stacked |
Add this class to display labels on top of controls. |
.gls-form-horizontal |
Add this class to display labels and controls side by side. |
.gls-form-label |
Add this class to define form labels. |
.gls-form-controls |
Add this class to define form controls. |
<form class="gls-form-stacked">
<div>
<label class="gls-form-label"></label>
<div class="gls-form-controls">...</div>
</div>
<div>
<div class="gls-form-label"></div>
<div class="gls-form-controls">...</div>
</div>
</form>
<form class="gls-form-stacked"> <div class="gls-margin"> <label class="gls-form-label" for="form-stacked-text">Text</label> <div class="gls-form-controls"> <input class="gls-input" id="form-stacked-text" type="text" placeholder="Some text..."> </div> </div> <div class="gls-margin"> <label class="gls-form-label" for="form-stacked-select">Select</label> <div class="gls-form-controls"> <select class="gls-select" id="form-stacked-select"> <option>Option 01</option> <option>Option 02</option> </select> </div> </div> <div class="gls-margin"> <div class="gls-form-label">Radio</div> <div class="gls-form-controls"> <label><input class="gls-radio" type="radio" name="radio1"> Option 01</label><br> <label><input class="gls-radio" type="radio" name="radio1"> Option 02</label> </div> </div> </form>
Horizontal form
Use the .gls-form-controls-text
class to better align checkboxes and radio buttons when using them with text in a horizontal layout.
<form class="gls-form-horizontal">
<div>
<label class="gls-form-label"></label>
<div class="gls-form-controls">...</div>
</div>
<div>
<div class="gls-form-label"></div>
<div class="gls-form-controls gls-form-controls-text">...</div>
</div>
</form>
<form class="gls-form-horizontal gls-margin-large"> <div class="gls-margin"> <label class="gls-form-label" for="form-horizontal-text">Text</label> <div class="gls-form-controls"> <input class="gls-input" id="form-horizontal-text" type="text" placeholder="Some text..."> </div> </div> <div class="gls-margin"> <label class="gls-form-label" for="form-horizontal-select">Select</label> <div class="gls-form-controls"> <select class="gls-select" id="form-horizontal-select"> <option>Option 01</option> <option>Option 02</option> </select> </div> </div> <div class="gls-margin"> <div class="gls-form-label">Radio</div> <div class="gls-form-controls gls-form-controls-text"> <label><input class="gls-radio" type="radio" name="radio1"> Option 01</label><br> <label><input class="gls-radio" type="radio" name="radio1"> Option 02</label> </div> </div> </form>
Form and icons
You use an icon from the Icon component inside a form. Add the .gls-form-icon
class to a <span>
element. Group it with an <input>
element by adding the .gls-inline
class from the Utility component to a container element around both. The icon has to come first in the markup. By default, the icon will be placed on the left side of the form. To change the alignment, add the .gls-form-icon-flip
class.
<div class="gls-inline">
<span class="gls-form-icon" gls-icon="icon: user"></span>
<input class="gls-input">
</div>
<form> <div class="gls-margin"> <div class="gls-inline"> <span class="gls-form-icon" gls-icon="icon: user"></span> <input class="gls-input" type="text"> </div> </div> <div class="gls-margin"> <div class="gls-inline"> <span class="gls-form-icon gls-form-icon-flip" gls-icon="icon: lock"></span> <input class="gls-input" type="text"> </div> </div> </form>
Clickable icons
To enable an action, for example opening a modal to pick an image or link, use an <a>
or <button>
element to create the icon.
<div class="gls-inline">
<a class="gls-form-icon gls-form-icon-flip" href="" gls-icon="icon: user"></a>
<input class="gls-input">
</div>
<form> <div class="gls-margin"> <div class="gls-inline"> <a class="gls-form-icon" href="#" gls-icon="icon: pencil"></a> <input class="gls-input" type="text"> </div> </div> <div class="gls-margin"> <div class="gls-inline"> <a class="gls-form-icon gls-form-icon-flip" href="#" gls-icon="icon: link"></a> <input class="gls-input" type="text"> </div> </div> </form>
Form and grid
You can also use the Grid and Width components to define the layout of a form.
<form class="gls-grid-small" gls-grid> <div class="gls-width-1-1"> <input class="gls-input" type="text" placeholder="100"> </div> <div class="gls-width-1-2@s"> <input class="gls-input" type="text" placeholder="50"> </div> <div class="gls-width-1-4@s"> <input class="gls-input" type="text" placeholder="25"> </div> <div class="gls-width-1-4@s"> <input class="gls-input" type="text" placeholder="25"> </div> <div class="gls-width-1-2@s"> <input class="gls-input" type="text" placeholder="50"> </div> <div class="gls-width-1-2@s"> <input class="gls-input" type="text" placeholder="50"> </div> </form>
Custom controls
To replace a file inputs or select forms with your own HTML content, like a button or text, add the gls-form-custom
attribute to a container element.
File
Use a button or text as a file input.
<div gls-form-custom>
<input type="file">
<button type="button"></button>
</div>
<form> <div class="gls-margin"> <div gls-form-custom> <input type="file"> <button class="gls-button gls-button-default" type="button" tabindex="-1">Select</button> </div> </div> <div class="gls-margin"> <span class="gls-text-middle">Here is a text</span> <div gls-form-custom> <input type="file"> <span class="gls-link">upload</span> </div> </div> <div class="gls-margin" gls-margin> <div gls-form-custom="target: true"> <input type="file"> <input class="gls-input gls-form-width-medium" type="text" placeholder="Select file" disabled> </div> <button class="gls-button gls-button-default">Submit</button> </div> </form>
Select
Use a button, text or a link as a select form. Just add the target: SELECTOR
option to the gls-form-custom
attribute to select where the option value should be displayed. target: true
will select the adjacent element in the markup.
<div gls-form-custom="target: true">
<select>
<option></option>
<option></option>
</select>
<button type="button"></button>
</div>
<form> <div class="gls-margin"> <div gls-form-custom="target: true"> <select> <option value="1">Option 01</option> <option value="2">Option 02</option> <option value="3">Option 03</option> <option value="4">Option 04</option> </select> <span></span> </div> </div> <div class="gls-margin"> <div gls-form-custom="target: > * > span:last-child"> <select> <option value="1">Option 01</option> <option value="2">Option 02</option> <option value="3">Option 03</option> <option value="4">Option 04</option> </select> <span class="gls-link"> <span gls-icon="icon: pencil"></span> <span></span> </span> </div> </div> <div class="gls-margin"> <div gls-form-custom="target: > * > span:first-child"> <select> <option value="">Please select...</option> <option value="1">Option 01</option> <option value="2">Option 02</option> <option value="3">Option 03</option> <option value="4">Option 04</option> </select> <button class="gls-button gls-button-default" type="button" tabindex="-1"> <span></span> <span gls-icon="icon: chevron-down"></span> </button> </div> </div> </form>
Component option
You can add this option to the gls-form-custom
attribute. Learn more
Option | Value | Default | Description |
---|---|---|---|
target |
CSS selector, Boolean | false | Value display target. |
JavaScript
Learn more about JavaScript components.
Initialization
Gloss.formCustom(element, options);