Easily create nicely looking forms with different styles and layouts.
\n\nUsage
\n\nTo apply this component, add the .uk-form
class to a form element. All form control elements are placed side by side within the next row.
Example
\n\n \n\nNOTE In this example we used a button from the Button component. To add a top margin to form elements, when they stack on smaller viewports, just add the data-uk-margin
attribute from the Utility component to the parent element.
Markup
\n\n<form class="uk-form">\n\n <fieldset data-uk-margin>\n <legend>...</legend>\n <input type="text" placeholder="">\n <input type="password" placeholder="">\n <select>\n <option>...</option>\n <option>...</option>\n </select>\n <button class="uk-button">...</button>\n <label><input type="checkbox"> ...</label>\n </fieldset>\n\n</form>
\n\n \n\n
Rows
\n\nAdd the .uk-form-row
class to a <div>
element to stack form controls.
Example
\n\n \n\nMarkup
\n\n<form class="uk-form">\n <fieldset>\n <legend>...</legend>\n <div class="uk-form-row">...</div>\n <div class="uk-form-row">...</div>\n </fieldset>\n</form>
\n\n \n
Control states
\nProvide the user with basic information through feedback states on form controls.
\n\nDisabled
\n\nAdd the disabled
attribute to a form control and it will be appear muted.
Example
\n\n \n\nMarkup
\n\n<input type="text" placeholder="" disabled>
\n\n \n\n
Validation states
\n\nAdd the .uk-form-danger
or .uk-form-success
class to a form control to notify the user, whether or not the value is validated.
Example
\n\n \n\nMarkup
\n\n<input type="text" placeholder="" class="uk-form-danger">\n<input type="text" placeholder="" class="uk-form-success">
\n\n \n\n
Control modifiers
\n\nSize modifiers
\n\nAdd the .uk-form-large
or .uk-form-small
class to an <input>
, <select>
or <textarea>
element to make it smaller or larger.
Example
\n\n \n\nMarkup
\n\n<input type="text" placeholder="" class="uk-form-large">\n<input type="text" placeholder="" class="uk-form-small">
\n\n \n\n
Width modifiers
\n\nAdd the .uk-form-width-large
, .uk-form-width-medium
, .uk-form-width-small
or .uk-form-width-mini
class to an <input>
, <select>
or <textarea>
element to adjust its width.
Example
\n\n \n\nMarkup
\n\n<input type="text" placeholder="" class="uk-form-width-large">\n<input type="text" placeholder="" class="uk-form-width-medium">\n<input type="text" placeholder="" class="uk-form-width-small">\n<input type="text" placeholder="" class="uk-form-width-mini">
\n\n You can also apply the .uk-width-*
classes from the Grid component to form controls. This is especially useful, if you want form controls to extend to the full width of their parent container.
Example
\n\n \n\nMarkup
\n\n<input type="text" placeholder="" class="uk-width-1-1">
\n\n \n\n
Form blank
\n\nAdd the .uk-form-blank
class to minimize the styling of form controls.
Example
\n\n \n\nMarkup
\n\n<input type="text" placeholder="" class="uk-form-blank">
\n\n \n\n
Help text
\n\nUse the .uk-form-help-inline
or .uk-form-help-block
class to add inline and block level help text for the controls.
Example
\n\n \n\nMarkup
\n\n<div class="uk-form-row">\n <input type="text" placeholder=""> <span class="uk-form-help-inline">...</span>\n</div>\n\n<div class="uk-form-row">\n <textarea cols="" rows="" placeholder="">...</textarea>\n <p class="uk-form-help-block">...</p>\n</div>
\n\n \n\n
Layout modifiers
\n\nThere are two layout modifiers available: .uk-form-stacked
and .uk-form-horizontal
. Both require form controls to be wrapped with the .uk-form-row
class in order to stack them. Labels need the .uk-form-label
class and controls must be wrapped in the .uk-form-controls
class.
Markup
\n\n<form class="uk-form uk-form-stacked">\n <div class="uk-form-row">\n <label class="uk-form-label" for="">...</label>\n <div class="uk-form-controls">...</div>\n </div>\n</form>
\n\n NOTE Layout modifiers can also be added to a <fieldset>
element. This means, if you use fieldsets, you can have different form layouts for each fieldset.
\n\n
Form stacked
\n\nAdd the .uk-form-stacked
class to display labels on top of controls.
Example
\n\n \n\n\n\n
Form horizontal
\n\nAdd the .uk-form-horizontal
class to display labels and controls side by side.
Example
\n\n \n\n\n\n
Text in form controls
\n\nIf you use text and checkboxes or radio buttons in form controls, just add the .uk-form-controls-text
class to align the text properly.
Markup
\n\n<div class="uk-form-controls uk-form-controls-text">...</div>
\n\n \n\n
Vertical spacing in form controls
\n\nIf you create paragraphs in form controls, add the .uk-form-controls-condensed
class to reduce spacing.
Example
\n\n \n\nMarkup
\n\n<div class="uk-form-controls uk-form-controls-text">\n <p class="uk-form-controls-condensed">...</p>\n <p class="uk-form-controls-condensed">...</p>\n</div>
\n\n \n\n
Form and grid
\n\nThis is an example of how to use forms with the Grid component.
\n\nExample
\n\n \n\nMarkup
\n\n<form class="uk-form">\n\n <div class="uk-grid">\n <div class="uk-width-1-2"><input type="text" placeholder="" class="uk-width-1-1"></div>\n <div class="uk-width-1-4"><input type="text" placeholder="" class="uk-width-1-1"></div>\n <div class="uk-width-1-4"><input type="text" placeholder="" class="uk-width-1-1"></div>\n </div>\n\n</form>
\n\n \n\n
Form and icons
\n\nThis is an example of how to add an icon from the Icon component to a form.
\n\nExample
\n\n \n\nMarkup
\n\n<div class="uk-form-icon">\n <i class="uk-icon-calendar"></i>\n <input type="text">\n</div>
\n\n \n\n