A slide deck by John Polacek
...or just scroll
↓
Key Press or Swipe
( Obligatory disclaimer )
.clearfix
.grid-*
.hidden
Atomic CSS is the approach to CSS architecture that favors small, single-purpose classes with names based on visual function.
Source: Let’s Define Exactly What Atomic CSS is (CSS Tricks)Signing up for an account is quick and easy.
<div class="box-640 flex pad-3 bgr-white shadow rounded">
<div class="col-6 s-col-12 pad-3-right s-pad-1-right s-border-bottom s-pad-3-bottom s-marg-3-bottom">
<h5 class="text-light text-blue-lt pad-2-bottom">Sign In</h5>
<form id="loginForm" class="pad-1-right">
<input class="marg-1-bottom" type="text" placeholder="User Name" required="required">
<input class="marg-3-bottom" type="text" placeholder="Password" required="required">
<input type="submit" class="btn float-right marg-1-top" value="Log In">
</form>
</div>
<div class="col-6 s-col-12 pad-3-left border-left s-border-0 s-pad-0">
<h5 class="text-light text-blue-lt pad-2-bottom pad-1-left s-pad-0-left">Join</h5>
<p class="pad-3-bottom pad-1-left s-pad-0-left">Signing up for an account is quick and easy.</p>
<div class="wide pad-3-top pad-1-left">
<button id="createAccount" class="float-right">Create Account</button>
</div>
</div>
</div>
"box-640 flex pad-3 bgr-white shadow rounded"
.box-640 {
width:100%;
max-width: 640px;
}
.flex {
display: flex;
flex-wrap: wrap;
}
.shadow {
box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.1);
}
.bgr-white {
background-color: #fff;
}
.rounded {
border-radius: 4px;
}
.pad-3 {
padding: 3.2rem;
}
“Functional CSS is just shifting complexity out of stylesheets and into templates.”
Vince Speelman
Front End Engineer at TED
.f1 { font-size: 3rem; }
.ma0 { margin: 0; }
.fontsize-xxl { font-size: 3rem; }
.marg-0 { margin: 0; }
.margin-0 { margin: 0; }
As heard on the
Front End Happy Hour Podcast
“Unfortunately you have to use CSS.”
Front End Engineer at Netflix
“I’m really bad at CSS.”
Front End Engineer at Evernote
“You try to write something clean, but then it turns into something shitty.”
Front End Engineer at LinkedIn
“At LinkedIn we have a massive CSS file that is 3.5MB.”
Front End Engineer at LinkedIn
“Naming CSS Stuff Is Really Hard”
Ethan Muller
Front End Developer at Sparkbox
Naming CSS Stuff Is Really Hard
<div class="inner">
<div class="pad-2">
.text-black { color:navy; }
.text-navy { color:navy; }
.text-primary { color:navy; }
“Simple, obvious styles are quicker to internalize,
Brent Jackson
easier to use, and more widely adopted.”
Basscss Design Principles
.bgr-blue
.bgr-blue-dk
.bgr-green
.bgr-green-dk
.bgr-pink
.bgr-purple
.bgr-grey
.bgr-red
.pad-0
.pad-1
.pad-2
.pad-3
h1, .text-120
h2, .text-96
h3, .text-64
h4, .text-48
h5, .text-36
h6, .text-24
body, .text-18
small, .text-14
“Working with functional CSS, you’re spending 99% of your time in HTML. Your productivity is incredibly high because your brain doesn’t need to context switch between markup and stylesheet.”
Simon Vrachliotis
Full re-write in 10 days with tachyons and functional CSS: A case study
“Small tweaks like margin can be adjusted with a single class change in your HTML. It allows you to fix bugs without writing any additional CSS. I can’t even tell you how amazing this feels.”
Marcelo Somers
Rationalizing Functional CSS
* Except for that pulsing button at the top. That was pretty cool.
** Built with the Expressive CSS Starter Kit and Simple Flex Grid
A few days before I started
My first task: implement responsive web design
Next task: Combine 41 stylesheets into 1
One year later...
Continued growth...
First optimization attempt
(removed unused styles, separate admin stylesheet)
Refactor to Functional CSS
“If we put Gzip into the picture, things look even better. That’s because a lot of repetitions means a better compression ratio.”
Atomic CSS FAQ
“HTML is much less difficult to reason about than layers of CSS inheritance.”
Sean Washington
CSS is hard — Thoughts on managing the cascade
Excerpts from
How is tachyons different from inline styles?
“The most important difference is specificity.
Mark Otto
Inline styles trump classes.”
Creator of Bootstrap
“Inline styles do not support media queries or pseudo elements.”
“Inline styles are 1 to 1 for the browser.
While a class has a 1 to many relationship.”“In the world of inline styles,
Adam Morse
I have to memorize padding and margin values.
A codified system can have named sizes like S, M, L.
Creator of Tachyons CSS
Excerpts from
Cooking with Design Systems
“If you’re using class names instead of inline styles, you won’t ever have a situation where one headline has 16px padding and another has 17px. You’re using your design system!”
“Using your already established conventions through class names gives you a beneficial constraint.”
Dan Mall
Founder and Director of SuperFriendly
Creative Director at Studio Zeldman
“The theory that an entire site can or should be redesigned by just changing the CSS isn’t practical and doesn’t reflect how real designers and developers approach new projects.”
Philip Walton
“Defending Presentational Class Names”
( e.g., There are 4 versions of Bootstrap )
“SORRY. I disagree.
Jeffrey Zeldman
Nonsemantic classnames that refer to
visual styles will always be a bad idea.”
Web Pioneer
Kiss My Classname
“For individuals weaned on an ideology where ‘Semantic HTML’ means using content-derived class names, it usually requires you to work on a large application before you become aware of the impractical nature of that approach.”
“You have to be prepared to disgard old ideas, look at alternatives, and even revisit ways that you may have previously dismissed.”
Nicolas Gallagher
About HTML semantics and front-end architecture
March 15, 2012
“If you use templates, then giving a meaningful name to the file should be enough. In my opinion, limiting yourself to style things through semantic class names is counter-productive.”
Thierry Koblentz
Challenging CSS Best Practices
October 21, 2013
“We have tags and attributes (ARIA, etc.) to describe content.”
“Our philosophy is that visual styling should be decoupled from content.”
John Polacek
Kiss My Classname: A Counterpoint
(Fun Fact: Medium is built with Atomic CSS)
“We should favor both approaches to achieve our goals. A ‘semantic’ name makes sense as a needed hook, not as a general rule.”
Thierry Koblentz
Challenging CSS Best Practices
October 21, 2013
<button class="btn bgr-red">
( Do what works for you )
Find the most common style declarations in your CSS.
Pick a theme
(e.g. typography, colors, spacing)
Replace with Atomic classes.
Go for big wins first.
Repeat Step 2 until satisfied.
Add Tachyons*
to the end of your CSS.
*or another Atomic library
Do a first pass.
Methodically remove legacy classes, replace with Atomic classes.
Kill all legacy CSS. Assess the damage.
Refactor to Tachyons, extend as needed.
Use other tools or restore legacy CSS only when necessary
Full re-write in 10 days with Tachyons and Functional CSS: A case study
Read the full case study
The switch to Tachyons resulted in a 50% file size reduction and 75% fewer style declarations.
Go to TweenDeck on Github