Need help with formtastic-sass?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

202 Stars 16 Forks 40 Commits 9 Opened issues


Flexible Formtastic styling with Sass

Services available


Need anything else?

Contributors list

# 325,488
32 commits
# 68,796
4 commits
# 28,045
2 commits
# 71,517
1 commit


I will no longer be supporting this particular library as I'm currently using my own custom form builders instead of formtastic. This repo will stay intact for anyone who cares to fork it.

Thanks to everyone who has contributed or provided feedback. You guys rock!

h1. Formtastic Sass Mixins

A few simple, yet powerful macros that add flexible styling to your "Formtastic": forms.

Version Bump!: Some big changes are taking place here. As of this release (0.3.2) The +formtastic mixin will be deprecated in favor of tighter, more agile helpers.

Some improvements in this release:

  • All custom styling removed from core
  • Skinnable forms (example provided in _skintastic.sass)
  • New mixins for checkboxes and radio buttons (float and grid styling)
  • "Demo Rails app": is available, with a jQuery-powered debugging interface
  • Much less CSS selectors = smaller footprint
  • No more Safari Hacks :)

h2. Installation

First we will need to install Haml -- Yes even you ERB enthusiasts who wont drink the Haml-Aid need to get on the Sass track if you are serious about productivity and DRYness. Sass kicks ass!

  gem install haml
  cd my_rails_app
  haml --rails
  1. Set up a master Sass file and include it in your layout
  2. Drop this file in the same directory as your master.sass
  3. Include this file at the top of that sheet with:
  @import formtastic_base.sass

If you haven't already, you should also install "Formtastic":

Done! Are you ready to churn out beautiful forms in SECONDS?

Let's rock...

h2. Stacked Forms

Gives you labels above the inputs, everything on new lines.


Defaults are clearly labeled in formtasticbase.sass, although you can override them directly in your stylesheet:


h3. Stacked Form Settings

These are the arguments provided to the mixin (must be supplied in the correct order!)

+form-stack(!stackedfieldset-width, !stackedinput, !stackedpadding, !stackedbuttonalign, !stackedselect_width)

  1. !stacked_fieldset Full width of the fieldset (default = 100%)

  2. !stacked_input "auto" : automatic widths (default) "full" : same width as fieldset "960px" : custom width

  3. !stacked_padding Left-hand padding on all labels and inputs (default = 0)

  4. !stackedbuttonalign "buttons-left" : float submit buttons left (default) "buttons-right" : float submit buttons right "buttons-full" : submit button matches input width

  5. !stackedselectwidth "select-auto" : auto width (default) "select-full" : same as specified input width

h2. Floated Forms

Even more time-consuming are the typical floated column layouts on forms, labels left and inputs right. This used to take at least a good hour to look solid across browsers.

No longer:


or you can be specific:


h3. Floated Forms Options

  1. !floatedtotalwidth Total Width of form (default = 100%)

  2. !floatedinputwidth Width of inputs (default = 70%)

  3. !floatedlabelwidth Width of Label (default = 20%)

  4. !floatedlabelpadding_x How far labels are spaced from inputs (default = 0)

  5. !floatedbuttonalign "buttons-left" : float submit button left (default) "buttons-right" : float submit button right "buttons-full" : submit button matches input width

  6. !floatedselectwidth "select-auto" : auto width (default) "select-full" : same as specified input width

Note: It is very important that you do not mix units (px,em,%) as calculations must be done

h2. Checkbox & Radio Button Helpers

Previously, formtastic assumed that you wanted all your checks/radios floated, but after using it in production on several projects I decided it needed to be more flexible. By default the lists are still block (stacked), but you can easily override this using a couple of handy mixins:

h3. Floated Inputs

Make all the checkboxes line up next to each other, inline-style and specify the spacing between them


1st option is right margin, 2nd is line-height.

As cool as that may seem at first, sometimes you dont want ALL your checkboxes to line up a certain way. Wouldn't it be great if you could pass a dom id or class to the helper and have it style ONLY those elements?

I thought so:


You can isolate however you want, using the handy classes formtastic generates to your advantage. Sweet!

Bug Alert: Floated checkboxes tend to misbehave for some reason on IE 6 and 7 when using a floated form layout. Suggestions/patches would be welcome.

h3. Grid Inputs

Make all the checkboxes the same exact width, so they line up in columns.


1st option is the width, 2nd is line-height.

And of course, you can also define for specific elements:


h2. Original Formtastic Mixin

This helper will be deprecated in future versions. Please use the mixins specified above.

h3. Set width of entire fieldset


h3. Set label widths and hint/error left margins


h3. Set width of inputs, textareas and selects


h3. Set horizontal padding for labels


h3. Set alignment of labels

  • "left" = labels floated left and text-align left
  • "right" = labels floated left and text-align right
  • "clear" = labels above inputs

h3. Set alignment of commit buttons ("left" or "right")


Note: Do not mix units (em px %) as it will break the calculations.

Percentages will yield elastic forms.

As for other defaults (color, fonts, etc), the file is well-commented

h2. The Magic

In order to set the basic layout, you don't need to even touch the defaults.



Note: When using floated labels (left or right), it's good to give your form !total_width a little leeway (add 10px or 5% minimum) to keep those floats intact.

h2. Alternative Inline Order

You can align labels with error messages so they read like sentences.

Create formtastic.rb in config/initializers and add this:

  Formtastic::SemanticFormBuilder.inline_order = [:errors, :input, :hints]

This is best used with right-aligned labels


You will need to provide a margin-top value to align labels with error messages, there is a convenient mixin for that


The value must be adjusted until label and error message line up.

h2. Found a Bug?

Please direct all queries to the issue tracker:


h2. Compatibility

Tested and looking good on

  • Chrome Beta
  • Firefox 3+
  • Internet Explorer 6+ (except floated inputs)
  • Safari 3+

h2. Caveat

This is an active work in progress - currently only used on 3 live projects right now. Use at your own discretion.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.