3 Hamburgers is a collection of tasty CSS-animated hamburger icons. Also included is the source as a [Sass](#sass) library. It’s modular and customizable, so cook up your own hamburger.
5 ![](http://i.imgur.com/t7cUjDu.gif)
11 - [Customization](#customization)
12 - [Accessibility](#accessibility)
13 - [Browser Support](#browser-support)
17 1. [Download](https://github.com/jonsuh/hamburgers/blob/master/dist/hamburgers.css) and include the CSS in the `<head>` of your site:
20 <link href="dist/hamburgers.css" rel="stylesheet">
23 2. Add the base hamburger markup:
26 <button class="hamburger" type="button">
27 <span class="hamburger-box">
28 <span class="hamburger-inner"></span>
33 You *can* use `<div>`s if you insist, but they’re not [accessible](#accessibility) as a menu button.
36 <div class="hamburger">
37 <div class="hamburger-box">
38 <div class="hamburger-inner"></div>
43 3. Append the class name of the type of hamburger you’re craving:
46 <button class="hamburger hamburger--collapse" type="button">
47 <span class="hamburger-box">
48 <span class="hamburger-inner"></span>
53 Here’s the list of hamburger-type classes you can choose from:
67 hamburger--arrowturn-r
89 Note: `-r` classes are reverse variants (e.g. `hamburger--spin` spins clockwise whereas `hamburger--spin-r` spins counterclockwise.
91 4. Trigger the active state by appending class name `is-active`:
94 <button class="hamburger hamburger--collapse is-active" type="button">
95 <span class="hamburger-box">
96 <span class="hamburger-inner"></span>
101 Since the class name would have to be toggled via JavaScript and implementation would differ based on the context of how you plan on using the hamburger, I’m going to leave the rest up to you.
105 `.scss` source files are available if you use Sass as your CSS precompiler. It’s customizable and modular.
107 1. Hamburgers is available on [npm](https://www.npmjs.com/package/hamburgers), yarn and [Bower](http://bower.io/search/?q=css-hamburgers).
110 npm install hamburgers
114 bower install css-hamburgers
117 Also available as a [Ruby gem](https://rubygems.org/gems/hamburgers) to use within your Rails application—see [below](#install-for-ruby-on-rails) for more information.
119 Or to manually install it, [download](https://github.com/jonsuh/hamburgers/archive/master.zip) and unzip the source files, then copy the files from the `_sass/hamburgers` directory into your project.
121 2. Import the `hamburgers.scss` file in your Sass manifest file:
124 @import "path/to/hamburgers";
127 3. Customize your hamburger and/or remove any types you don’t want in `hamburgers.scss`.
128 4. Compile your Sass*, and voila!
130 \* Be sure to run the CSS through [Autoprefixer](https://github.com/postcss/autoprefixer) since the Sass doesn’t account for vendor prefixes.
132 ### Install for Ruby on Rails
134 1. Add Hamburgers to your Gemfile.
140 2. Run `bundle install`.
141 3. Include Hamburgers by using Sass’s native `@import`**:
145 @import "hamburgers";
148 \** [More information](https://blog.pivotal.io/pivotal-labs/labs/structure-your-sass-files-with-import) on why Sass’s native `@import` + why you should ditch Sprockets directives altogether.
152 To override default settings, declare them before importing Hamburgers:
155 $hamburgers-padding-x: 20px;
156 $hamburgers-padding-y: 15px;
157 $hamburger-types : (collapse);
159 @import "hamburgers";
162 You can also create a separate file (e.g. `hamburgers-settings.scss`) with those declarations, then import it before Hamburgers:
165 @import "hamburgers-settings"
166 @import "hamburgers";
169 Here is the full list of default settings (found in `_sass/hamburgers/hamburgers.scss`);
172 $hamburger-padding-x : 15px;
173 $hamburger-padding-y : 15px;
174 $hamburger-layer-width : 40px;
175 $hamburger-layer-height : 4px;
176 $hamburger-layer-spacing : 6px;
177 $hamburger-layer-color : #000;
178 $hamburger-layer-border-radius : 4px;
179 $hamburger-hover-opacity : 0.7;
180 $hamburger-hover-transition-duration : 0.15s;
181 $hamburger-hover-transition-timing-function: linear;
183 // To use CSS filters as the hover effect instead of opacity,
184 // set $hamburger-hover-use-filter as true and
185 // change the value of $hamburger-hover-filter accordingly.
186 $hamburger-hover-use-filter: false;
187 $hamburger-hover-filter : opacity(50%);
189 // Remove or comment out the hamburger types you don’t want
190 // or need, so they get excluded from the compiled CSS.
228 Wanna work with `ems` or `rems` instead of `px`? Just change all the `px` values to the unit of your choice. Note: Be consistent (all `px` or all `ems`), otherwise it may break—the math behind the customization will fail if it attempts to perform operations with values of different units.
232 Dig into `_base.scss` or `types/` and customize to your heart’s content. Fair warning: It‘s pretty delicate and may break, especially if you tweak the animations themselves.
236 Hamburger menu icons can be useful in the right context, but they’re not the most accessible.
238 ARIA will help make it accessible to people with disabilities.
242 <button class="hamburger hamburger--elastic" type="button"
243 aria-label="Menu" aria-controls="navigation" aria-expanded="true/false">
244 <span class="hamburger-box">
245 <span class="hamburger-inner"></span>
249 <div id="navigation">
250 <!--navigation goes here-->
255 You will need JavaScript to toggle between `aria-expanded` attribute being set to `true` and `false`, as this will indicate to visually impaired users whether the menu is opened or closed.
257 The hamburger button belongs __inside__ the `<nav>` so that assistive technologies will be able to locate the navigation, and to allow these users to easily locatate the hamburger button, without having to search up and down the DOM, once they realize they've found themselves in an empty navigation.
259 If you insist on using `<div>`s, by default they’re not focusable (i.e. via keyboard or assistive technology). Add the `tabindex` attribute alongside ARIA. You will also need to recreate expected keyboard functionality for these `<div>`s. Using JavaScript, you will need to make sure that both <kbd>Space</kbd> and <kbd>Enter</kbd> will toggle the hamburger states.
262 <nav id="navigation">
264 <div class="hamburger hamburger--elastic" tabindex="0"
265 aria-label="Menu" role="button" aria-controls="navigation" aria-expanded="true/false">
266 <div class="hamburger-box">
267 <div class="hamburger-inner"></div>
271 <div id="navigation">
272 <!--navigation goes here-->
277 A label will help make it more obvious that it toggles a menu.
280 <button class="hamburger hamburger--collapse" type="button">
281 <span class="hamburger-box">
282 <span class="hamburger-inner"></span>
284 <span class="hamburger-label">Menu</span>
288 Here are [some](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA) [resources](https://webaccessibility.withgoogle.com/course) on [web](http://a11yproject.com/) [accessibility](http://www.html5accessibility.com/) and [ARIA](https://w3c.github.io/aria-in-html/).
292 Animations use CSS3 3D transforms (`translate3d` whenever possible for GPU acceleration), which is supported by most browsers (not supported by IE9 and older and Opera Mini). For detailed browser support, check [caniuse.com](http://caniuse.com/#search=translate3d).