├── .scss-lint.yml ├── LICENSE.md └── README.md /.scss-lint.yml: -------------------------------------------------------------------------------- 1 | severity: error 2 | 3 | linters: 4 | 5 | BorderZero: 6 | enabled: true 7 | convention: zero 8 | 9 | BemDepth: 10 | enabled: true 11 | 12 | DeclarationOrder: 13 | enabled: false 14 | 15 | ExtendDirective: 16 | enabled: true 17 | 18 | LeadingZero: 19 | enabled: false 20 | 21 | NameFormat: 22 | enabled: true 23 | 24 | PrivateNamingConvention: 25 | enabled: true 26 | prefix: _ 27 | 28 | PropertySortOrder: 29 | enabled: false 30 | 31 | QualifyingElement: 32 | enabled: false 33 | 34 | SelectorFormat: 35 | enabled: true 36 | convention: hyphenated_BEM 37 | class_convention: ^(?!js-).* 38 | class_convention_explanation: should not be written in the form js-* 39 | 40 | SingleLinePerProperty: 41 | enabled: true 42 | allow_single_line_rule_sets: false 43 | 44 | StringQuotes: 45 | enabled: true 46 | style: double_quotes 47 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2015 Airbnb 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | | :exclamation: Deprecation Notice | 2 | |:-| 3 | |We want to express our sincere gratitude for your support and contributions to this open source project. As we are no longer using this technology internally, we have come to the decision to archive this repository. While we won't be providing further updates or support, the existing code and resources will remain accessible for your reference. We encourage anyone interested to fork the repository and continue the project's legacy independently. Thank you for being a part of this journey and for your patience and understanding.| 4 | 5 | # Airbnb CSS / Sass Styleguide 6 | 7 | *A mostly reasonable approach to CSS and Sass* 8 | 9 | ## Table of Contents 10 | 11 | 1. [Terminology](#terminology) 12 | - [Rule Declaration](#rule-declaration) 13 | - [Selectors](#selectors) 14 | - [Properties](#properties) 15 | 1. [CSS](#css) 16 | - [Formatting](#formatting) 17 | - [Comments](#comments) 18 | - [OOCSS and BEM](#oocss-and-bem) 19 | - [ID Selectors](#id-selectors) 20 | - [JavaScript hooks](#javascript-hooks) 21 | - [Border](#border) 22 | 1. [Sass](#sass) 23 | - [Syntax](#syntax) 24 | - [Ordering](#ordering-of-property-declarations) 25 | - [Variables](#variables) 26 | - [Mixins](#mixins) 27 | - [Extend directive](#extend-directive) 28 | - [Nested selectors](#nested-selectors) 29 | 1. [Translation](#translation) 30 | 1. [License](#license) 31 | 32 | ## Terminology 33 | 34 | ### Rule declaration 35 | 36 | A “rule declaration” is the name given to a selector (or a group of selectors) with an accompanying group of properties. Here's an example: 37 | 38 | ```css 39 | .listing { 40 | font-size: 18px; 41 | line-height: 1.2; 42 | } 43 | ``` 44 | 45 | ### Selectors 46 | 47 | In a rule declaration, “selectors” are the bits that determine which elements in the DOM tree will be styled by the defined properties. Selectors can match HTML elements, as well as an element's class, ID, or any of its attributes. Here are some examples of selectors: 48 | 49 | ```css 50 | .my-element-class { 51 | /* ... */ 52 | } 53 | 54 | [aria-hidden] { 55 | /* ... */ 56 | } 57 | ``` 58 | 59 | ### Properties 60 | 61 | Finally, properties are what give the selected elements of a rule declaration their style. Properties are key-value pairs, and a rule declaration can contain one or more property declarations. Property declarations look like this: 62 | 63 | ```css 64 | /* some selector */ { 65 | background: #f1f1f1; 66 | color: #333; 67 | } 68 | ``` 69 | 70 | **[⬆ back to top](#table-of-contents)** 71 | 72 | ## CSS 73 | 74 | ### Formatting 75 | 76 | * Use soft tabs (2 spaces) for indentation. 77 | * Prefer dashes over camelCasing in class names. 78 | - Underscores and PascalCasing are okay if you are using BEM (see [OOCSS and BEM](#oocss-and-bem) below). 79 | * Do not use ID selectors. 80 | * When using multiple selectors in a rule declaration, give each selector its own line. 81 | * Put a space before the opening brace `{` in rule declarations. 82 | * In properties, put a space after, but not before, the `:` character. 83 | * Put closing braces `}` of rule declarations on a new line. 84 | * Put blank lines between rule declarations. 85 | 86 | **Bad** 87 | 88 | ```css 89 | .avatar{ 90 | border-radius:50%; 91 | border:2px solid white; } 92 | .no, .nope, .not_good { 93 | // ... 94 | } 95 | #lol-no { 96 | // ... 97 | } 98 | ``` 99 | 100 | **Good** 101 | 102 | ```css 103 | .avatar { 104 | border-radius: 50%; 105 | border: 2px solid white; 106 | } 107 | 108 | .one, 109 | .selector, 110 | .per-line { 111 | // ... 112 | } 113 | ``` 114 | 115 | ### Comments 116 | 117 | * Prefer line comments (`//` in Sass-land) to block comments. 118 | * Prefer comments on their own line. Avoid end-of-line comments. 119 | * Write detailed comments for code that isn't self-documenting: 120 | - Uses of z-index 121 | - Compatibility or browser-specific hacks 122 | 123 | ### OOCSS and BEM 124 | 125 | We encourage some combination of OOCSS and BEM for these reasons: 126 | 127 | * It helps create clear, strict relationships between CSS and HTML 128 | * It helps us create reusable, composable components 129 | * It allows for less nesting and lower specificity 130 | * It helps in building scalable stylesheets 131 | 132 | **OOCSS**, or “Object Oriented CSS”, is an approach for writing CSS that encourages you to think about your stylesheets as a collection of “objects”: reusable, repeatable snippets that can be used independently throughout a website. 133 | 134 | * Nicole Sullivan's [OOCSS wiki](https://github.com/stubbornella/oocss/wiki) 135 | * Smashing Magazine's [Introduction to OOCSS](http://www.smashingmagazine.com/2011/12/12/an-introduction-to-object-oriented-css-oocss/) 136 | 137 | **BEM**, or “Block-Element-Modifier”, is a _naming convention_ for classes in HTML and CSS. It was originally developed by Yandex with large codebases and scalability in mind, and can serve as a solid set of guidelines for implementing OOCSS. 138 | 139 | * CSS Trick's [BEM 101](https://css-tricks.com/bem-101/) 140 | * Harry Roberts' [introduction to BEM](http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/) 141 | 142 | We recommend a variant of BEM with PascalCased “blocks”, which works particularly well when combined with components (e.g. React). Underscores and dashes are still used for modifiers and children. 143 | 144 | **Example** 145 | 146 | ```jsx 147 | // ListingCard.jsx 148 | function ListingCard() { 149 | return ( 150 | 159 | ); 160 | } 161 | ``` 162 | 163 | ```css 164 | /* ListingCard.css */ 165 | .ListingCard { } 166 | .ListingCard--featured { } 167 | .ListingCard__title { } 168 | .ListingCard__content { } 169 | ``` 170 | 171 | * `.ListingCard` is the “block” and represents the higher-level component 172 | * `.ListingCard__title` is an “element” and represents a descendant of `.ListingCard` that helps compose the block as a whole. 173 | * `.ListingCard--featured` is a “modifier” and represents a different state or variation on the `.ListingCard` block. 174 | 175 | ### ID selectors 176 | 177 | While it is possible to select elements by ID in CSS, it should generally be considered an anti-pattern. ID selectors introduce an unnecessarily high level of [specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity) to your rule declarations, and they are not reusable. 178 | 179 | For more on this subject, read [CSS Wizardry's article](http://csswizardry.com/2014/07/hacks-for-dealing-with-specificity/) on dealing with specificity. 180 | 181 | ### JavaScript hooks 182 | 183 | Avoid binding to the same class in both your CSS and JavaScript. Conflating the two often leads to, at a minimum, time wasted during refactoring when a developer must cross-reference each class they are changing, and at its worst, developers being afraid to make changes for fear of breaking functionality. 184 | 185 | We recommend creating JavaScript-specific classes to bind to, prefixed with `.js-`: 186 | 187 | ```html 188 | 189 | ``` 190 | 191 | ### Border 192 | 193 | Use `0` instead of `none` to specify that a style has no border. 194 | 195 | **Bad** 196 | 197 | ```css 198 | .foo { 199 | border: none; 200 | } 201 | ``` 202 | 203 | **Good** 204 | 205 | ```css 206 | .foo { 207 | border: 0; 208 | } 209 | ``` 210 | **[⬆ back to top](#table-of-contents)** 211 | 212 | ## Sass 213 | 214 | ### Syntax 215 | 216 | * Use the `.scss` syntax, never the original `.sass` syntax 217 | * Order your regular CSS and `@include` declarations logically (see below) 218 | 219 | ### Ordering of property declarations 220 | 221 | 1. Property declarations 222 | 223 | List all standard property declarations, anything that isn't an `@include` or a nested selector. 224 | 225 | ```scss 226 | .btn-green { 227 | background: green; 228 | font-weight: bold; 229 | // ... 230 | } 231 | ``` 232 | 233 | 2. `@include` declarations 234 | 235 | Grouping `@include`s at the end makes it easier to read the entire selector. 236 | 237 | ```scss 238 | .btn-green { 239 | background: green; 240 | font-weight: bold; 241 | @include transition(background 0.5s ease); 242 | // ... 243 | } 244 | ``` 245 | 246 | 3. Nested selectors 247 | 248 | Nested selectors, _if necessary_, go last, and nothing goes after them. Add whitespace between your rule declarations and nested selectors, as well as between adjacent nested selectors. Apply the same guidelines as above to your nested selectors. 249 | 250 | ```scss 251 | .btn { 252 | background: green; 253 | font-weight: bold; 254 | @include transition(background 0.5s ease); 255 | 256 | .icon { 257 | margin-right: 10px; 258 | } 259 | } 260 | ``` 261 | 262 | ### Variables 263 | 264 | Prefer dash-cased variable names (e.g. `$my-variable`) over camelCased or snake_cased variable names. It is acceptable to prefix variable names that are intended to be used only within the same file with an underscore (e.g. `$_my-variable`). 265 | 266 | ### Mixins 267 | 268 | Mixins should be used to DRY up your code, add clarity, or abstract complexity--in much the same way as well-named functions. Mixins that accept no arguments can be useful for this, but note that if you are not compressing your payload (e.g. gzip), this may contribute to unnecessary code duplication in the resulting styles. 269 | 270 | ### Extend directive 271 | 272 | `@extend` should be avoided because it has unintuitive and potentially dangerous behavior, especially when used with nested selectors. Even extending top-level placeholder selectors can cause problems if the order of selectors ends up changing later (e.g. if they are in other files and the order the files are loaded shifts). Gzipping should handle most of the savings you would have gained by using `@extend`, and you can DRY up your stylesheets nicely with mixins. 273 | 274 | ### Nested selectors 275 | 276 | **Do not nest selectors more than three levels deep!** 277 | 278 | ```scss 279 | .page-container { 280 | .content { 281 | .profile { 282 | // STOP! 283 | } 284 | } 285 | } 286 | ``` 287 | 288 | When selectors become this long, you're likely writing CSS that is: 289 | 290 | * Strongly coupled to the HTML (fragile) *—OR—* 291 | * Overly specific (powerful) *—OR—* 292 | * Not reusable 293 | 294 | 295 | Again: **never nest ID selectors!** 296 | 297 | If you must use an ID selector in the first place (and you should really try not to), they should never be nested. If you find yourself doing this, you need to revisit your markup, or figure out why such strong specificity is needed. If you are writing well formed HTML and CSS, you should **never** need to do this. 298 | 299 | **[⬆ back to top](#table-of-contents)** 300 | 301 | ## Translation 302 | 303 | This style guide is also available in other languages: 304 | 305 | - ![id](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Indonesia.png) **Bahasa Indonesia**: [mazipan/css-style-guide](https://github.com/mazipan/css-style-guide) 306 | - ![tw](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Taiwan.png) **Chinese (Traditional)**: [ArvinH/css-style-guide](https://github.com/ArvinH/css-style-guide) 307 | - ![cn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/China.png) **Chinese (Simplified)**: [Zhangjd/css-style-guide](https://github.com/Zhangjd/css-style-guide) 308 | - ![fr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/France.png) **French**: [mat-u/css-style-guide](https://github.com/mat-u/css-style-guide) 309 | - ![ka](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Georgia.png) **Georgian**: [DavidKadaria/css-style-guide](https://github.com/davidkadaria/css-style-guide) 310 | - ![ja](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Japan.png) **Japanese**: [nao215/css-style-guide](https://github.com/nao215/css-style-guide) 311 | - ![ko](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/South-Korea.png) **Korean**: [CodeMakeBros/css-style-guide](https://github.com/CodeMakeBros/css-style-guide) 312 | - ![PT-BR](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Brazil.png) **Portuguese (Brazil)**: [felipevolpatto/css-style-guide](https://github.com/felipevolpatto/css-style-guide) 313 | - ![pt-PT](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Portugal.png) **Portuguese (Portugal)**: [SandroMiguel/airbnb-css-style-guide](https://github.com/SandroMiguel/airbnb-css-style-guide) 314 | - ![ru](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png) **Russian**: [rtplv/airbnb-css-ru](https://github.com/rtplv/airbnb-css-ru) 315 | - ![es](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Spain.png) **Spanish**: [ismamz/guia-de-estilo-css](https://github.com/ismamz/guia-de-estilo-css) 316 | - ![vn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png) **Vietnamese**: [trungk18/css-style-guide](https://github.com/trungk18/css-style-guide) 317 | - ![vn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Italy.png) **Italian**: [antoniofull/linee-guida-css](https://github.com/antoniofull/linee-guida-css) 318 | - ![de](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Germany.png) **German**: [tderflinger/css-styleguide](https://github.com/tderflinger/css-styleguide) 319 | 320 | **[⬆ back to top](#table-of-contents)** 321 | 322 | ## License 323 | 324 | (The MIT License) 325 | 326 | Copyright (c) 2015 Airbnb 327 | 328 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 329 | 330 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 331 | 332 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 333 | 334 | **[⬆ back to top](#table-of-contents)** 335 | --------------------------------------------------------------------------------