Sass for Big Sites, Part 2

In part 1 of this series, I detailed how Behance maintains the CSS for our giant codebase (over 130 pages large!). I shared how we use Sass and Compass to organize, modularize and streamline code, as well as how we keep code consistent. In this part 2, I’m going to focus on the general “care and feeding” of your Sass codebase: how to use your modular Sass to create style guides, other tools to maintain code consistency, and ways to keep your team up-to-date on coding standards and guidelines.

Living Style Guide

As I described in part 1, Behance utilizes partials for every repeatable module, making it easy to include the styles for a component with just one line of Sass. We rely on the mustache template engine to create small blocks of markup that can be imported and reused in other templates (just like Sass partials). Having our styles and markup split into partials not only makes it easy to manage discrete sections of code, but also makes it easier for us to maintain consistency. Since we only have to update code in one place at a time, there is less danger of breaking or forgetting other parts of the site.

Not only do we use partials to make styling components across the site easy, we also use them to make a living style guide of these components. The style guide serves a purpose for both the designers and the developers by giving us a central place to see what modules already exist and what they look like. The Behance style guide is only available internally, but MailChimp and Starbucks have public ones that are great examples.

Here’s an abbreviated look at the markup and Sass for our styleguide:

styleguide.mustache

<section>
  <h1>Buttons</h1>
  {{#buttons}}
    {{> form/button}}
  {{/buttons}}
</section>

<section>
  <h1>Inputs</h1>
  <h2>Text</h2>
  {{#texts}}
    {{> form/text}}
  {{/texts}}

<h2>Checkboxes</h2>
{{#checkboxes}}
{{> form/checkbox}}
{{/checkboxes}}
</section>

<section>
  <h1>Multiple Owners</h1>
  {{> components/_multiple-owners}}
</section>
…

styleguide.scss

@import '_global/*.scss';
@import 'partials/multiple-owners.scss';

// styleguide-specific styles
section {
  margin-bottom: 50px;
}

Since the style guide is built using the same exact partials as the rest of the site, any changes made to the individual pieces are reflected immediately in both the front-end of the website and the style guide.

Documentation

Let’s say you joined Behance as a front-end developer today. How would you find out how we write our Sass? If one of our developers were abducted by aliens in the night, how easy would it be for another person to take over an existing feature or pick up where someone else left off? These are things we’ve spent a lot of time considering, since it’s not just our website that grows, but our team as well.

Inline Sass Comments

To reduce the potential for problems, we document everything. We use a documentation style very similar to TomDoc and start every mixin, function and extend with a block of documentation (colloquially, “doc block”) explaining:

  • what the following piece of code does
  • what arguments it accepts (if any)
  • an example for how to use it

We write them all in single-line Sass comments so that they do not get compiled into the generated CSS, allowing us to have documentation without worrying about bloating our code with unnecessary comments.

//
// Prints out the width and height of an element.
//
// $width - String or number representation of the element width
// $height - String or number representation of the element height
// false if it is the same as the width
//
// Examples
// @include size(10px);
// @include size(10px, 30px);
//

@mixin size($width, $height: false) {
  width: $width;
  height: if($height, $height, $width);
}

Having documentation inline in our Sass makes it easy to see at a glance what things do as we’re working with our code. Although we mainly focus on commenting mixins and functions, it can also be very helpful to have doc blocks for classes, extends and anything else!

There are also third-party tools you can use to generate style guides based on comments like these. Knyle Style Sheets (KSS) is a human-readable documentation syntax that uses Ruby to parse these comments and generate a style guide. This makes it easy to show your markup, styles and documentation together in one place. Hologram is a similar tool with a different documentation syntax. No matter what route you go, any documentation is better than none.

GitHub Wiki

We also keep a wiki on GitHub containing information that doesn’t fit into our style guide or inline comments. It contains information about our Sass that might also extend into our PHP or JavaScript, such as:

  • how to enable or disable the responsive layout and different site footers
  • how to customize the look and feel of various page headers
  • If you use Sublime Text, use the Dependents package to easily navigate through Sass @import dependencies for any given file.

Where the style guide is meant to provide a visualization of different components — and inline comments are intended to provide information about how a small piece of code works — the wiki is used as a higher-level utility to provide more robust information about how all the pieces fit together, making it especially useful for new team members to jump into Sass and start using existing components.

Code Consistency

For as much as we are the keepers of consistency for the UI of the website, we are also the keepers of consistency for our code. But what does “code consistency” really mean? It’s all about coding style and, at Behance, we place a high value on code consistency and cleanliness. Coding style encompasses many aspects of writing code, such as:

  • how and when to use comments
  • how and when to use whitespace
  • naming conventions for variables, functions and mixins
  • code grouping and organization

The list could go on and on and on. Every programmer has their own natural coding style, formed by any number of factors from how they learned to code originally to the editor they like to code in. But these individual styles are less important than consistency, explains Nicholas Zakas:

I liken the situation to a group of musicians trying to form a band. Each one comes in believing that their way of doing things is best (their “method” or “process”). The band will struggle so long as everyone is trying to do their own thing. It’s impossible to create good music unless everyone in the band agrees on the tempo, the style and who should take lead during a song. Anyone who has ever heard a high school band perform knows this to be true. Unless everyone is on the same page, you aren’t going to accomplish much.

We maintain a living wiki in Github of all the coding style standards that our team has agreed on for all of the languages we use (PHP, Sass/CSS, JavaScript and more). Since our standards grow and change over time as we acclimate to new tools, best practices, etc., everyone is a contributor to the coding style guide, and we discuss all changes or additions as a team.

We’ve set up hooks in Github to run scss-lint on any Sass code we push before it can go to master, which runs checks on our coding style (or “lints” it) to make sure the code abides by our standards. There are many other popular linting and code quality tools for other languages (such as JSHint, JSCS and PHPCS — all of which we use. And for “vanilla” CSS, there is CSS Lint.

These tools mean that our pull request reviews — the process by which a team member gets their code into master in Git — are more meaningful, since we can focus on the integrity of the functionality and ideas behind the code, rather than on code style.

Output from scss-lint lets you know the style problems in your code, which helps unify code style and leads to more meaningful code reviews by others later on.

Onwards to Scalable Sass!

If you’ve read part 1, you now know how to use Sass to organize and optimize your code using partials, how to utilize powerful Sass and Compass features, and how to create your own custom frameworks. With this part 2, you learned various ways to document and share knowledge of your codebase with other developers, maintain style guides for consistency and transparency, and how to keep code healthy with coding standards and tools. Using these starting points, you and your team can be writing and maintaining healthy code for a big website in no time!

Pitfalls to Avoid

  • Don’t over-fragment your code – you should come up with a system that makes your modular components neatly packaged and easy to understand.
  • Don’t be afraid to experiment with different documentation styles and tools to find the one that works best for you and your team.
  • Don’t put off documenting your code. Why do tomorrow what you can do today?

Things to Do

  • Have a set of coding standards that you and your team follow.
  • Use linting tools to make sure your code is maintaining code style standards.
  • Keep it simple! The more straightforward your code is, the easier it is to understand.

Further Reading

How do you maintain a style guide for your website?

Discussion

  1. , stevenjames said:

    Get the best web hosting services at SSCS World

    The leading web hosting company SSCS World is always there for you to give the most guaranteed services for the web development. It provides you the best designs for the websites of your business. It conceptualizes the unique idea for bringing the best in web designing and web hosting. The cutting-edge, goal oriented and best designs are fair enough to compose the HTML Web design, Corporate Web Design, Creative Web Design, Flash & Action Script and the other things.  To know more details please visit http://www.sscsworld.com/

  2. , avathomas said:

    Really nice and touchy things written on blog, i really admire from it. an occasion sort of blogging here. http://www.bestessaywriting.com/

  3. , zoejackson said:

    I know that you are leading web hosting company but this is an informational website don’t spam on here. build your own website by enosite

  4. , goldcruderesearch said:

    Gold Crude Research is a best comex signals provider. We provide high accurat crude oil singals, WTI signalsnatural gas signalsNYMEX signals, Forex signals.

  5. , goldcruderesearch said:

    Gold Crude Research is a best MCX market tips provider. We provide high accurcy MCX tips, Crude oil tips, Natural gas Tips, Crude oil trading tips, Bullion trading tips.

  6. , cyberworx said:

    I am first Time Here. This is very good and useful information for us. Thank to share it…
    Ecommerce Website Development Company

  7. , muhammad27 said:

    nixe your blog i like it
    pantun

  8. , orentation said:

    nice information thanks for sharing
    web development company bangalore

  9. , Elsye Besi Cnp said:

    I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work Distributor Baja Ringan Surabaya

  10. , Syaiful Anam said:

    The information you have posted is very useful. The sites you have referred was good. Thanks for sharing… Grosir Payung Choirose Parfume

  11. , linkpk12 said:

    This is really a great stuff for sharing. Keep it up .Thanks for sharing.
    panda global protection 2016

  12. , linkpk12 said:

    The content of your post is awesome” Great work!
    movie box app download free

  13. , Appstore said:

    nice information thanks for sharing GraphPad Prism 7 Crack

  14. , John Mark said:

    Nice Informaion thanks for great article Driver Toolkit here is about Office Toolkit well if you need this tookit for PC here you go Driver Toolkit Licesne key

  15. , paulsam said:

    Great work. hay day

  16. , mikejasson2 said:

    Finance Dissertation help providers Finance Assignment, Finance Dissertation Help Finance Homework and Project of financial management Finance Dissertation Help Finance is a vast academic discipline, which comprises on many different fields.

  17. , jollyoph said:

    The content of your post is awesome” Great work!
    Website Designing Company in Dubai

  18. , jollyoph said:

    I am first Time Here. This is very good and useful information for us. Thanks for sharing.
    Website Designing Company in Dubai

  19. , jollyoph said:

    I am first Time Here. This is very good and useful information for us. Thanks for sharing.
    Ecommerce Website Designing Company in delhi

  20. , Sher Singh said:

    pcehelp technical support ids provide you tech support for bt if you are using bt products and you face any kind of issue in pt products now dial our toll free customer care help line no 0800-680-0619
    or visit our website for more info
     http://pcehelp.com/bt-support/bt-technical-support-number-0800-680-0619/

    http://pcehelp.com/avg/avg-antivirus-technical-support-0800-680-0619/

  21. , cyberdesign said:

    Nice post Thank you for information.

    Web Design Delhi, Ecommerce Web Development, Wordpress Web Development

  22. , Jamesbush said:

    Nice information thank you……….


    Website Designing Company

    Web Development Company

    Digital Marketing Agency

    Mobile App Development

    Ecommerce Web Development

  23. , AnnaGrace said:

    Thanks for this great article.

    Gmail Support Number  |  Hotmail Support Number | Canon Printer Support Number | Epson Printer Support Number | HP printer helpline number

  24. , John Mark said:

    Nice post Thank you for information. Auslogics BoostSpeed Crack 

  25. , John Mark said:

    Nice post Thank you for information. Auslogics BoostSpeed Crack 

  26. , Aftab Akmal said:

    sketchup 8 crack
    nice psots for this big site of sass

  27. , voyagermieux said:

    Séjours de dernières minutes : depart immediat ! Vous êtes prêts à partir en vacances et cherchez sans relâche le voyage de vos rêves !

  28. , mali90 said:

    happy to join your community, thank you guys for the info!
     192.168.1.1

  29. , dsummerbell10 said:

    It is a wonderful information and also get good knowledge and ideas from this article. The author is giving good thoughts and suggestions to each and every readers through this article.The good advantages of this article is giving good thought to each and every readers and also it’s giving good impressions. Looking forward to another article.
    Iasosource.com | Emblemzone.com

  30. , sap onlinetraining said:

    Nice info thank you for sharing.

    sap online training

  31. , sap onlinetraining said:

    Nice info thank you for sharing..
    SAP FICO Online Training
    etl testing online training

  32. , krishnaweb said:

    Thanks for this great article.

    web designing company

  33. , roshnikhanna said:

    I am so impressed to read this type of perfect article. I am very glad that I am here to see your ideal knowledge.
     Thanks.

    Female Gurgaon Escorts Roshni and Female Delhi Escorts Roshni

     

  34. , roshnikhanna said:

    Your writing style is one of the best and I like to say that your post is unique and to the point.
     Thanks.


    Gurgaon Escorts Services, Gurgaon Escorts in Delhi, Female Escorts Services in Gurgaon, Female Escorts in Gurgaon, Female Escorts Services in GurgaonIndependent Escorts Services in Gurgaon

  35. , mali90 said:

    was looking for this information, thanks to the author for the post!
     192.168.1.1

  36. , meestersin2 said:

    Thanks for this awesome post. It is extremely helpful for me. Would you mind updating your blog with more information

    Inhuren Interim management bureau professional - Meesters in Management

  37. , Rabia said:

    It is a wonderful information and also get good knowledge and ideas from this article. The author is giving good thoughts and suggestions to each and every readers through this article.The good advantages of this article is giving good thought to each and every readers and also it’s giving good impressions. Hitman pro 2016 Crack

  38. , procracks said:

    Auslogics BoostSpeed keygen is the best suit for maximizing your Computer’s operating efficiency. Furthermore, it also provides some extra features that help you to manage everything about your system.

  39. , PruDhvi Reborn said:

    Parts of ic engine
    Types of Engineering Degrees
    Types of Engineering
    What are the types of Engineering Degrees
    All the types of Engineering Degrees

    Engineering Types
    Types of Engineering
    Different Types of Turbines
    Types of Turbines

    Ultrasonic machining
    Abrasive jet machining
    Comfort air conditioning system
    Best V12 cars

    V12 Lamborghini
    Lamborghini v12 cars
    Best v12 engine
    best v12 lamborghini cars

    Mechanical Energy

    What do mechanical engineers do


    What does an engineer do
    working of supercharger turbocharger twin charger
    Types of Brakes

    Types of Disc Brakes

    Disc brake types
    List of Associates and Bachelors degree
    Online degree programs
    Online masters degree
    Comfort air conditioning
    How do electric cars work
    Types of Mufflers
    What is a Muffler

    Small Mufflers
    Define Mechanical Energy
    Conservation of Mechanical Energy

    Define conservation of energy
    Compensation mesothelioma
    Aggregate Production plan
    Production schedule example
    Magnetocaloric cooling
    How do ball bearings reduce friction
    What is a thread
    Thread Types
    Types of threads

    What does a mechanical engineer do
    College Degree Levels

    Degree Levels
    Ivanpah Solar Power Facility
    Ivanpah Solar

    Light and Heat energy
    List of Welding process
    Electrochemical Machining
    Electrochemical Grinding process
    Electrochemical Honing process
    Electrical Discharge Machining
    Electrical Discharge Grinding
    Wire edm

    Electrical Discharge Machining


    ebm process
    Electron Beam Machining process
    Laser beam machining

    Different types of lasers
    Types of lasers

    How does a plasma cutter work

    plasma cutter working
    Plasma Arc Machining
    internal combustion engine history
    bs in industrial Engineering
    What is an arc reactor of iron man
    Different types of Machining process
    Types of Hammers
    Types of Machining process
    Types of Gears
    Gear Types
    Types of Chips
    Types of Gears
    Gear Types
    Parts of a Lathe Machine
    Venturimeter
    Venturimeter Working
    Refrigeration Cycle
    First Law of Thermodynamics
    Refrigeration Cycle
    Second Law of Thermodynamics

    What are the different levels of college degrees

    How do solar panels work
    Non Renewable Energy Sources


    Earth Movers
    Earth Mover truck


    Types of construction trucks

    Different Types of Energy
    Solar Energy Definition
    Parts of ic engine
    Types of Engineering Degrees
    Types of Engineering
    What are the types of Engineering Degrees
    All the types of Engineering Degrees

    Engineering Types
    Types of Engineering
    Different Types of Turbines
    Types of Turbines

    Ultrasonic machining
    Abrasive jet machining
    Comfort air conditioning system
    Best V12 cars

    V12 Lamborghini
    Lamborghini v12 cars
    Best v12 engine
    best v12 lamborghini cars

    Mechanical Energy

    What do mechanical engineers do


    What does an engineer do
    working of supercharger turbocharger twin charger
    Types of Brakes

    Types of Disc Brakes

    Disc brake types
    List of Associates and Bachelors degree
    Online degree programs
    Online masters degree
    Comfort air conditioning
    How do electric cars work
    Types of Mufflers
    What is a Muffler

    Small Mufflers
    Define Mechanical Energy
    Conservation of Mechanical Energy

    Define conservation of energy
    Compensation mesothelioma
    Aggregate Production plan
    Production schedule example
    Magnetocaloric cooling
    How do ball bearings reduce friction
    What is a thread
    Thread Types
    Types of threads

    What does a mechanical engineer do
    College Degree Levels

    Degree Levels
    Ivanpah Solar Power Facility
    Ivanpah Solar

    Light and Heat energy
    List of Welding process
    Electrochemical Machining
    Electrochemical Grinding process
    Electrochemical Honing process
    Electrical Discharge Machining
    Electrical Discharge Grinding
    Wire edm

    Electrical Discharge Machining


    ebm process
    Electron Beam Machining process
    Laser beam machining

    Different types of lasers
    Types of lasers

    How does a plasma cutter work

    plasma cutter working
    Plasma Arc Machining
    internal combustion engine history
    bs in industrial Engineering
    What is an arc reactor of iron man
    Different types of Machining process
    Types of Hammers
    Types of Machining process
    Types of Gears
    Gear Types
    Types of Chips
    Types of Gears
    Gear Types
    Parts of a Lathe Machine
    Venturimeter
    Venturimeter Working
    Refrigeration Cycle
    First Law of Thermodynamics
    Refrigeration Cycle
    Second Law of Thermodynamics

    What are the different levels of college degrees

    How do solar panels work
    Non Renewable Energy Sources


    Earth Movers
    Earth Mover truck


    Types of construction trucks

    Different Types of Energy
    Solar Energy Definition
    Parts of ic engine
    Types of Engineering Degrees
    Types of Engineering
    What are the types of Engineering Degrees
    All the types of Engineering Degrees

    Engineering Types
    Types of Engineering
    Different Types of Turbines
    Types of Turbines

    Ultrasonic machining
    Abrasive jet machining
    Comfort air conditioning system
    Best V12 cars

    V12 Lamborghini
    Lamborghini v12 cars
    Best v12 engine
    best v12 lamborghini cars

    Mechanical Energy

    What do mechanical engineers do


    What does an engineer do
    working of supercharger turbocharger twin charger
    Types of Brakes

    Types of Disc Brakes

    Disc brake types
    List of Associates and Bachelors degree
    Online degree programs
    Online masters degree
    Comfort air conditioning
    How do electric cars work
    Types of Mufflers
    What is a Muffler

    Small Mufflers
    Define Mechanical Energy
    Conservation of Mechanical Energy

    Define conservation of energy
    Compensation mesothelioma
    Aggregate Production plan
    Production schedule example
    Magnetocaloric cooling
    How do ball bearings reduce friction
    What is a thread
    Thread Types
    Types of threads

    What does a mechanical engineer do
    College Degree Levels

    Degree Levels
    Ivanpah Solar Power Facility
    Ivanpah Solar

    Light and Heat energy
    List of Welding process
    Electrochemical Machining
    Electrochemical Grinding process
    Electrochemical Honing process
    Electrical Discharge Machining
    Electrical Discharge Grinding
    Wire edm

    Electrical Discharge Machining


    ebm process
    Electron Beam Machining process
    Laser beam machining

    Different types of lasers
    Types of lasers

    How does a plasma cutter work

    plasma cutter working
    Plasma Arc Machining
    internal combustion engine history
    bs in industrial Engineering
    What is an arc reactor of iron man
    Different types of Machining process
    Types of Hammers
    Types of Machining process
    Types of Gears
    Gear Types
    Types of Chips
    Types of Gears
    Gear Types
    Parts of a Lathe Machine
    Venturimeter
    Venturimeter Working
    Refrigeration Cycle
    First Law of Thermodynamics
    Refrigeration Cycle
    Second Law of Thermodynamics

    What are the different levels of college degrees

    How do solar panels work
    Non Renewable Energy Sources


    Earth Movers
    Earth Mover truck


    Types of construction trucks

    Different Types of Energy
    Solar Energy Definition
    Parts of ic engine
    Types of Engineering Degrees
    Types of Engineering
    What are the types of Engineering Degrees
    All the types of Engineering Degrees

    Engineering Types
    Types of Engineering
    Different Types of Turbines
    Types of Turbines

    Ultrasonic machining
    Abrasive jet machining
    Comfort air conditioning system
    Best V12 cars

    V12 Lamborghini
    Lamborghini v12 cars
    Best v12 engine
    best v12 lamborghini cars

    Mechanical Energy

    What do mechanical engineers do


    What does an engineer do
    working of supercharger turbocharger twin charger
    Types of Brakes

    Types of Disc Brakes

    Disc brake types
    List of Associates and Bachelors degree
    Online degree programs
    Online masters degree
    Comfort air conditioning
    How do electric cars work
    Types of Mufflers
    What is a Muffler

    Small Mufflers
    Define Mechanical Energy
    Conservation of Mechanical Energy

    Define conservation of energy
    Compensation mesothelioma
    Aggregate Production plan
    Production schedule example
    Magnetocaloric cooling
    How do ball bearings reduce friction
    What is a thread
    Thread Types
    Types of threads

    What does a mechanical engineer do
    College Degree Levels

    Degree Levels
    Ivanpah Solar Power Facility
    Ivanpah Solar

    Light and Heat energy
    List of Welding process
    Electrochemical Machining
    Electrochemical Grinding process
    Electrochemical Honing process
    Electrical Discharge Machining
    Electrical Discharge Grinding
    Wire edm

    Electrical Discharge Machining


    ebm process
    Electron Beam Machining process
    Laser beam machining

    Different types of lasers
    Types of lasers

    How does a plasma cutter work

    plasma cutter working
    Plasma Arc Machining
    internal combustion engine history
    bs in industrial Engineering
    What is an arc reactor of iron man
    Different types of Machining process
    Types of Hammers
    Types of Machining process
    Types of Gears
    Gear Types
    Types of Chips
    Types of Gears
    Gear Types
    Parts of a Lathe Machine
    Venturimeter
    Venturimeter Working
    Refrigeration Cycle
    First Law of Thermodynamics
    Refrigeration Cycle
    Second Law of Thermodynamics

    What are the different levels of college degrees

    How do solar panels work
    Non Renewable Energy Sources


    Earth Movers
    Earth Mover truck


    Types of construction trucks

    Different Types of Energy
    Solar Energy Definition

  40. , Cameron656 said:

    Full Free ActivePresenter Professional with serial
    Amazing work info and i really like your work,thanks your information.

  41. , johnag said:

    Thanks for sharing a useful information.  gadecosmetics.se

  42. , pitaracoupon said:

    Here is the best Sass for Big Sites, Part 2 ,this is very help us.
     http://www.couponpitara.com/offers/hostgator/

  43. , Leila Hatafi said:


      http://www.plan-cul.org/wp-content/uploads/2015/11/3.jpg

  44. , nandu41 said:

    Great post,It is helpful and informative..Thank you for sharing!!

    web designing company hyderabad
    web designing company
    sap fico online training institutes

Share Your Thoughts

Please log in or sign up to share your thoughts.