Form Element



We set out in Foundation 3 to create an easy to handle, powerful, and versatile form layout system. A combination of form styles and the Foundation grid means you can do basically anything you need.

The Basics

Form elements in Foundation 3 are styled based on their type attribute rather than .input-text classes, so the Scss/CSS is much simpler.

Inputs in Foundation 3 have another major change — they are full width by default. That means that inputs will run as wide as the column that contains them. However, you have two options which make these forms extremely versatile:

  • You can size inputs using column sizes, like .six.
  • You can create row elements inside your form and use columns for the form, including inputs, labels and more. Rows inside a form inherit some special padding to even up input spacing.

Row Layouts

Here’s an example of a form layout controlled with rows and columns.

  • Sometimes you want a form with labels to the left of your inputs. Piece of cake. You can add a class of .right to a label to have it align to the right, and if your label is next to an input (in another column) adding a class of .inline will have it vertically center against an input.

  •  <!-- Row Layout for forms --> <form>   <label>This is a label.</label>   <input type="text" placeholder="Standard Input" />   <label>Address</label>   <input type="text" class="twelve" placeholder="Street" />   <div class="row">     <div class="six columns">       <input type="text" placeholder="City" />     </div>     <div class="three columns">       <input type="text" placeholder="State" />     </div>     <div class="three columns">       <input type="text" placeholder="ZIP" />     </div>   </div>   <textarea placeholder="Message"></textarea> </form>  <!-- Right aligned and inline labels --> <form>   <div class="row">     <div class="two mobile-one columns">       <label class="right inline">Address Name:</label>     </div>     <div class="ten mobile-three columns">       <input type="text" placeholder="e.g. Home" class="eight" />     </div>   </div>   <div class="row">     <div class="two mobile-one columns">       <label class="right inline">City:</label>     </div>     <div class="ten mobile-three columns">       <input type="text" class="eight" />     </div>   </div>   <div class="row">     <div class="two mobile-one columns">       <label class="right inline">ZIP:</label>     </div>     <div class="ten mobile-three columns">       <input type="text" class="three" />     </div>   </div> </form> 


Simple elements that can contain all or part of a form to create better division.

  • Fieldset Name

  •  <form>   <fieldset>      <legend>Fieldset Name</legend>      <label>This is a label.</label>     <input type="text" placeholder="Standard Input" />      <label>Address</label>     <input type="text" />     <input type="text" class="six" />    </fieldset> </form> 

Pre/Postfix Labels & Actions

Foundation forms support actions tied to buttons, and prefix / postfix labels, through a versatile approach using special grid properties. Essentially you can use a ‘collapsed’ row to create label / action / input combinations. Here are a few examples.

Note: for these prefix and postfix labels we’re using the mobile grid to size our labels correctly on small devices.

  • #


  •  <!-- Prefix label --> <label>Input with a prefix character</label> <div class="row">   <div class="four columns">     <div class="row collapse">       <div class="two mobile-one columns">         <span class="prefix">#</span>       </div>       <div class="ten mobile-three columns">         <input type="text" />       </div>     </div>   </div> </div>  <!-- Postfix label --> <label>Input with a postfix label</label> <div class="row">   <div class="five columns">     <div class="row collapse">       <div class="nine mobile-three columns">         <input type="text" />       </div>       <div class="three mobile-one columns">         <span class="postfix">.com</span>       </div>     </div>   </div> </div>  <!-- Postfix action --> <div class="row collapse">   <div class="ten mobile-three columns">     <input type="text" />   </div>   <div class="two mobile-one columns">     <a class="button expand postfix">Search</a>   </div> </div> 

Error States

Foundation includes error states for labels, inputs and messaging that you can have your app generate programatically.

You can attach a class of .error either to the individual elements (label, input, small) or to a column/div.

  • Invalid entry
    Invalid entry

  •  <div class="row">   <div class="five columns">     <label class="error">Error</label>     <input type="text" class="error" />     <small class="error">Invalid entry</small>   </div>    <div class="five columns end error">     <label>Another Error</label>     <input type="text" />     <small>Invalid entry</small>   </div> </div> 

Large Forms

Here’s an example of how you can use the grid to build out a complex form layout.
  •  <form>   <fieldset>     <legend>Large Form Example</legend>      <div class="row">       <div class="five columns">          <label>Name</label>         <input type="text">          <label>Occupation</label>         <input type="text">          <label>Twitter</label>         <div class="row collapse">           <div class="two mobile-one columns">             <span class="prefix">@</span>           </div>           <div class="ten mobile-three columns">             <input type="text" placeholder="foundationzurb">           </div>         </div>          <label>URL</label>         <div class="row collapse">           <div class="nine mobile-three columns">             <input type="text" placeholder="foundation.zurb">           </div>           <div class="three mobile-one columns">             <span class="postfix">.com</span>           </div>         </div>        </div>        <div class="five columns">          <label class="error">Field with Error</label>         <input type="text" class="error">         <small class="error">Invalid entry</small>          <div class="error">           <label>Another Error</label>           <input type="text">           <small>Invalid entry</small>         </div>        </div>     </div>      <label>Address</label>     <input type="text" placeholder="Street (e.g. 123 Awesome St.)">      <div class="row">       <div class="six columns">         <input type="text" placeholder="City">       </div>       <div class="two columns">         <select>           <option>CA</option>         </select>       </div>       <div class="four columns">         <input type="text" placeholder="ZIP">       </div>     </div>    </fieldset> </form> 

Custom Inputs

Creating easy to style custom form elements is so crazy easy, it’s practically a crime. Just add a class of «custom» to a form and, if you want, will do everything.
  • Once initialized it will look for any checkbox, radio button, or select element and replace it with custom markup that Foundation provides styles for. It will even correctly respect and apply default states for radio, checkbox and select elements. You can use the «checked» or «selected» properties just like normal.

    If you want to avoid a potential flash (waiting for js to load and replace your default elements) you can supply the custom markup as part of the page, and the js will instead simply map the custom elements to the inputs.

    If you dynamically add inputs to your page you’ll need to update the custom markup. You can safely call the previous function again, but to improve performance you can also scope it to only update a single input.

  •  <form class="custom">   <!-- No custom markup applied -->   <label for="radio1">     <input name="radio1" type="radio" id="radio1"> Radio Button 1   </label>    <!-- Above markup will become this -->   <label for="radio1">     <input name="radio1" type="radio" id="radio1" style="display:none;">     <span class="custom radio"></span> Radio Button 1   </label>    <!-- This markup will NOT be touched by Javascript -->   <label for="radio2">     <input name="radio1" type="radio" id="radio2" style="display:none;">     <span class="custom radio checked"></span> Radio Button 2   </label> </form>  <!-- The HTML for Scoping to Single Input --> <select id="changedSelectInput">   <option>Pick One</option> </select>  <!-- The JS for Scoping to Single Input --> $("#changedSelectInput").foundationCustomForms(); 

Radio Buttons and Checkboxes

With the patterns described above, we’re able to easily construct customizable radio buttons and checkboxes.

  • Select Elements

    Also made with the patterns described above, we’ve made it simple to create customizable select lists too!

  •  <form class="custom">    <!-- Custom Radio -->   <div class="row">     <div class="four columns">       <label for="radio1"><input name="radio1" type="radio" id="radio1" style="display:none;"><span class="custom radio"></span> Radio Button 1</label>       <label for="radio2"><input name="radio1" type="radio" id="radio2" style="display:none;"><span class="custom radio checked"></span> Radio Button 2</label>       <label for="radio3"><input name="radio1" type="radio" id="radio3" disabled style="display:none;"><span class="custom radio"></span> Radio Button 3</label>     </div>     <div class="four columns">       <label for="radio4"><input name="radio2" type="radio" id="radio4"> Radio Button 1</label>       <label for="radio5"><input name="radio2" CHECKED type="radio" id="radio5"> Radio Button 2</label>       <label for="radio6"><input name="radio2" type="radio" id="radio6"> Radio Button 3</label>     </div>      <!-- Custom Checkbox -->     <div class="four columns">       <label for="checkbox1"><input type="checkbox" id="checkbox1" style="display: none;"><span class="custom checkbox"></span> Label for Checkbox</label>       <label for="checkbox2"><input type="checkbox" id="checkbox2" checked style="display: none;"><span class="custom checkbox checked"></span> Label for Checkbox</label>       <label for="checkbox3"><input type="checkbox" CHECKED id="checkbox3"> Label for Checkbox</label>     </div>   </div>    <!-- Custom Selects -->   <label for="customDropdown">Dropdown Label</label>   <select style="display:none;" id="customDropdown">     <option SELECTED>This is a dropdown</option>     <option>This is another option</option>     <option>Look, a third option</option>   </select>   <div class="custom dropdown">     <a href="#" class="current">       This is a dropdown     </a>     <a href="#" class="selector"></a>     <ul>       <li>This is a dropdown</li>       <li>This is another option</li>       <li>Look, a third option</li>     </ul>   </div> </form> 

Listen to Navi

Navigation helps tell people where they should go on your site or app. We’ve included lots of handy elements that will let you build quick navigation.

Learn about our navigation »

Artículo anterior
Artículo siguiente


China se sitúa como el décimo emisor de turismo internacional a la ciudad de Madrid

El turismo chino aumenta en la capital con unas cifras que posicionan a este mercado como su décimo emisor de turismo internacional. En los primeros siete meses de 2023...

Cultura y Deporte publica el ‘Libro verde para la gestión sostenible del patrimonio cultural’

El ministro de Cultura y Deporte en funciones, Miquel Iceta, ha presentado en Madrid el 'Libro verde para la gestión sostenible del patrimonio cultural'. La publicación, impulsada por el...

Los ciclos musicales y los talleres de creación artística regresan a CentroCentro

Los ciclos musicales y los talleres de creación artística vuelven este mes de septiembre a CentroCentro. Este espacio del Área de Cultura, Turismo y Deporte del Ayuntamiento de Madrid...

Renfe pone en circulación el Tren del Mercurio entre Madrid y Puertollano

Renfe, en colaboración con Turismo de Castilla-La Mancha, pone en circulación el tren turístico `Tren del Mercurio´ el sábado 14 de octubre, con origen en la estación Madrid-Puerta de...

Telefónica y Microsoft lanzan Educa365 para ayudar a digitalizar los centros educativos

En el marco de la colaboración estratégica que mantienen desde 2019, Telefónica y Microsoft se han unido para desarrollar una novedosa propuesta educativa que facilite el aprendizaje en los...

Europa apuesta por la intermodalidad como solución integral y sostenible para la movilidad

Como cada año, la Confederación Española de Transporte en Autobús, CONFEBUS, se une a la campaña de la Semana Europea de la Movilidad (SEM) que se celebra del 16 al 22 de...
Esta web utiliza cookies propias y de terceros para su correcto funcionamiento y para fines analíticos y para mostrarte publicidad relacionada con sus preferencias en base a un perfil elaborado a partir de tus hábitos de navegación. Al hacer clic en el botón Aceptar, acepta el uso de estas tecnologías y el procesamiento de tus datos para estos propósitos.