Extensions do not allow customization, but they create very efficient CSS.
%button background-color: lightgrey &:hover, &:active background-color: white a @extend %button button @extend %button
Result:
a, button { background-color: lightgrey; } a:hover, button:hover, a:active, button:active { background-color: white; }
With mixins, you get duplicate CSS, but you can use arguments to change the result for each use.
=button($main-color: lightgrey, $active-color: white) background-color: $main-color border: 1px solid black border-radius: 0.2em &:hover, &:active background-color: $active-color a +button button +button(pink, red)
Results in:
a { background-color: lightgrey; border: 1px solid black; border-radius: 0.2em; } a:hover, a:active { background-color: white; } button { background-color: pink; border: 1px solid black; border-radius: 0.2em; } button:hover, button:active { background-color: red; }
Please follow this consistent set of code examples to find out how to make your code cleaner and easier to maintain using efficient extensions and mixins: http://thecodingdesigner.com/journal/balancing-ideal-sass-and-ideal-css
Please note that SASS, unfortunately, does not allow the use of extensions inside media queries (and the corresponding example from the link above is incorrect). In a situation where you need to expand based on media queries, use mixin:
=active display: block background-color: pink %active +active
Result:
#main-menu { display: block; background-color: pink; } @media (min-width: 20em) { #secondary-menu { display: block; background-color: pink; } }
Duplication is inevitable in this case, but you should not care about it, because gzip compression in the web server will take care of this.
PS Note that you can declare placeholder classes in media queries.
Update 2014-12-28 . It expands the possibilities of creating more compact CSS than mixins, but this advantage decreases when CSS is gzipped. If your server serves CSS with gzipped (it really should!), Then the extensions give you almost no benefit. Therefore, you can always use mixers! More on this here: http://www.sitepoint.com/sass-extend-nobody-told-you/