I come from the dark days of CSS when browser support was so-so and you had to have fallbacks for your fallbacks for good ol' IE9.
*cringe*
When I discovered SASS, it was a breath of fresh air. There were abstractions in place so that you could use fancy features without breaking cross-browser styles and without adding every vendor-prefix under the sun. It also handled nesting and variables. Awesome.
For the most part SASS has been great - but - I still found my typical application development cycles taking longer than I wanted. They went something like this:
This was a reasonable workflow but I kept running into a couple of problems:
I know there are systems out there that are meant to help these issues - and I've used some of them - but I never quite shook these issues off.
There are certainly benefits to styled-components and other CSS-in-JS libs. The biggest one seems to be modularity and re-use scoped to a component. I've used styled components for a couple of projects with an overall positive response, but it still felt slower than it could be.
Somehow I stumbled on Tachyons and by extension, "functional CSS".
Functional CSS focuses on style classes that have a single responsibility that can be composed.
For example:
.w1{
width: 10px; /* Not actual Tachyons values */
}
.w2{
width: 30px;
}
This helps in a number of ways:
Tachyons does a great job of providing a small number of good options for sizing.
For example, you get 5 choices for width: w1, w2, w3, w4, w5
. This frees up mental space that was otherwise occupied by pixel count or SASS variables. I know if I'm specifying width, it's going to be between w1 and w5 and that w5 is bigger.
Does this produce pixel perfect replicas of the design? Maybe not, but for most spacing cases, it is close enough. When an element needs to be perfect, you can always add additional styles to get it just right.
Tachyons ships with some modifiers for each class:
-ns
: Not small-m
: Medium-l
: LargeBy adding these modifiers to your classes, you can limit the class application to the screens you care about.
An example I use a lot:
<div className="pa3 pa5-ns">
Some Stuff
</div>
The div has level 3 padding on small screens and level 5 on non-small screens. With a couple of keystrokes I have added responsive behavior to this element. Very nice!
I have built a number of applications with Tachyons (this site included!). I have found I'm able to move much faster. Not only that I have been happier with the result - both the look and maintainability.
And since shipping is all that matters™, I've found a new style-y partner for the foreseeable future.
P.S. Go check out Tachyons for yourself here.