Getting Started With Pattern Libraries

Three weeks ago, A List Apart went open source. The markup on the website is something I feel very close to. Over the years, if I’ve been unsure of how to mark something up, I’ve often referenced the HTML on A List Apart to see how it’s been done there because I know the people who work on it really care about semantics.

Uncertain of how I could help, I suggested to the team that A List Apart have its own pattern library. Pattern libraries are something I do a lot for client projects and I thought the site could really benefit from one.

It’s a technique I first saw former Clearlefty Natalie Downe develop for client projects back in 2009, and has been used by Clearleft as a front-end deliverable since. They’ve evolved a lot over time to include things like usage notes and code snippets.

A couple of days later, with some help from Mat “Wilto” Marquis, we had a repository for the pattern library up and running complete with a live preview.

Features of A List Apart’s pattern library

A screenshot showing the layout of A List Apart’s pattern library site.
Clicking on the # shows the pattern in isolation (great for bug-fixing). Usage examples can be included by adding a .txt file with the same name in the pattern folder.

All the pattern files (snippets of markup) are in their own folder, and adding one in there automatically adds it to the library. I’m using some PHP from Paul Lloyd’s Barebones, his own blend of a pattern library, to output the patterns in the right format.

By breaking the site up into patterns, it’s easier to find those bits of markup. I noticed an issue on GitHub about there being no styles for dl, dd, and dt elements, and it took a while to find an example of them being used on the site. With a pattern library, all the elements that appear on the site are in one place so you don’t have to go searching round for them.

It also makes device testing easier because everything is on one page. I made a special patchwork view specifically for this, which is the same as the regular view, but all the patterns are at full width and it excludes the code and usage examples. It’s also quick to see if CSS changes to one pattern affect other patterns.

It’s a work in progress, and the first time I’ve built one after a site has gone live. (Normally I do them during development). There aren’t many patterns there at the moment, but I’ll be adding more. I’d also like to make it a one-stop-shop for grabbing site assets like logos.

Code for America’s Pattern Library

An example of a fully-fledged pattern library is Code for America’s, which I worked on with Clearleft.

The Code for America site is huge, and maintained by many different people. They wanted a redesign of their site, but delivering mockups of template after template would only be a tip of the iceberg and not really help them in the long-term. Templates are like a snapshot in time of a site, and they often can’t take into account when content changes or entirely new sections are created.

Since the project is so out in the open and encourages collaboration from the community, the code had to be documented well too.

We wanted to create a solid foundation that they could build upon, so we built them a system so they could build their own pages, the main deliverable for this being the Pattern Portfolio.

It encouraged a much more modular approach to development, the idea being that any pattern could be used anywhere on a template. Each pattern has its own .scss file, and the file name for that and the pattern’s markup are the same.

Designs for templates were still created to demonstrate how patterns could work together. After the Code for America team said they were thinking of using Jekyll for their site, I started using it (for the first time) to help me prototype these templates. It made code collaboration really easy because there was no database or required knowledge of PHP, so it’s now being used in production.

The site’s still being put together, and you can follow its progress on Github.

More pattern libraries

Some of my favorite examples of pattern libraries in the wild include those of Mailchimp and Starbucks. They’re comprehensive and well documented, they feel like the perfect deliverable because they help maintain code and design standards. They acknowledge that websites change over time and make it easier to make those changes without breaking stuff.

If you’re inspired to learn more, I have a bookmark collection of pattern libraries, and I’ve also written a pocket guide about them. Please chime in with your own favorite pattern library examples or resources in the comments as well.

  • By The fine folks at A List Apart
  • Posted in Uncategorized
  • Tagged Mat Wilto Marquis, Pattern Library, Pattern Portfolio, PHP
  • Translator

  • Recent Articles

    • LG L5 Dual and F60 price listings for India and specs
    • iPad Air 2 teardown confirms 2 GB RAM, smaller battery, lousy repairability
    • Verizon may get the Samsung Galaxy Note 4 Developer Edition
    • The new Philips I966 Aurora is a Quad-HD powerhouse
    • A Wave in the Mind: Virginia Woolf on Emotion and Writing
    • Microsoft’s Xbox Music Free Streaming Shutting Down
    • For Brazil’s Sateré-Mawé, Wearing These Gloves Will Turn You into a Real Man
    • LG G Watch R Appears On Amazon
    • Verizon To Soon Sell Galaxy Note 4 Developer Edition
    • ‘Avengers: Age Of Ultron’ Official Teaser Trailer
    • Mark Zuckerberg talks about Xiaomi Smartphones, says ‘it will grow very quickly’
    • iPad Air 2 Gets Taken Apart By iFixit (Video)
    • Sony lowers sales target once again
    • Bank of America account holders charged double with Apple Pay
    • Titanfall gets a new co-op game mode
    • Verizon HTC One M8 Gets Android 4.4.4 KitKat Update With Eye Experience
    • Android 5.0 Lollipop release date revealed
    • Google updates email with the launch of Inbox (video)
    • LG launches their flexible OLED smartwatch in Korea, you can buy it in the US for $398
    • Daimler sells its stake in Tesla