Dipping my toe in the Open Props water
Feb 22, 2022 • About 3 minutes to read
Open Props? What's that, you say? In the words of Adam Argyle, they're Supercharged CSS variables. I've got to assume that you know what CSS variables are as this post would be way too long for me to describe them and what they're capable of. So, if they're variables, why does he call them props? It's can be a little confusing, but according to the spec, they are variables, but custom properties are used to define them; also, the value of the property is referenced with the
var() function. Many others way smarter than me have covered that ground.
Before I get into my initial attempt at using Open Props, this intro video by Kevin Powell did a great job of jumpstarting my understanding. Prior to that, Kevin had done a Twitch stream with Adam and they played around with Open Props; a longer video, but also incredibly helpful.
I just recently built this site and I had defined around 15 custom properties. I was wondering if I could use Open Props to help deliver a more consistent experience for further developing the site.
Before I started using Open Props, I organized my variables like this:
// Fonts sizes
As you can see, they are organized more my function, i.e., colors, fonts, and font sizes. As this list grew in size (not that it's terribly large), I started to consider other ways to organize them, perhaps more driven by where they are used in the structure of the site.
Combining this thinking along with the use of Open Props, I revised the list to look more like this:
--brand-name-font: "Caveat", cursive;
Here is where we begin to see the use of Open Props. For example, the
--brand-color is now defined using one of the Open Props colors, i.e.,
--green-9. With the exception of the
-brand-name-font, all of the other variables are now defined using the Open Props variables.
I particularly like the fluid font sizes, of which there are four to choose from. This eliminates the need to do all of that font-size tweaking that often accompanies the use of media queries in responsive designs.
That's the extent of my Open Props experience so far. I plan also take a look at postcss-jit-props as it does this amazing thing of creating a CSS file of only the props you actually use...and not the entire set of props.
If any of this looks useful as a result of you stumbling across this post, I suggest that you head over to the Open Props website and take it for a spin.