Syntax Video
Our CSS Tooling Stack Explained - Syntax.fm Dev Log
Transcript
Hey, what's up? This is Scott from Syntax, and we're hard at work building our new website. Now, this is more of a reworking of the old website with a totally new design, but it involves ripping out a lot of CSS. We're essentially doing a full remodel, even though some of the structure is going to stay the same, not all of the structure.
That said, I wanted to take this video to talk a little bit about some tooling setup, specifically with style lint and the types of things that you can do with both VS Code as well as style lint to make sure that your CSS authoring experience is that of one that other tools might have in various ways. Ways that can make your CSS authoring experience really nice and self-documenting in many ways. So let's get into the first one which is going to be our VS Code setup. Now for VS Code, we're actually using a CSS extension for autocomplete. So if we filter for enabled for things that I have enabled and look at CSS, you'll see that we have a couple of things. One of which is going to be IntelliSense for CSS class names. So the first one here is IntelliSense for CSS class names in HTML. This plugin has 8.8 8 million downloads and it allows you to quickly
and easily get autocomplete for classes that have been defined in your CSS, making it so that when you write them in your HTML, you know it's there. That tracks, right? That's uh something that is really nice to have and therefore you're not going to be adding a bunch of classes that may not exist. Now, that doesn't mean Copilot might not hallucinate some class names for you. So you'll need to make sure that uh you know if this is actually autocomplete or if this is trying to be some sort of AI assistant helper. Now the next one here is CSS var complete. Now this one has less downloads right only 76,000 but that doesn't mean that this one is any less important in the stack. We use a CSS variableheavy workflow over here.
And because of that, anytime you want to author CSS and use a CSS variable, you might not know what actually exists out there. And so we took an approach that utilizes both a system of variable names as well as CSS varlete in VS Code to have a really nice system. Now, let me show you what I mean. If I'm just typing my CSS, of course, you have to give a real property name. As long as I do hyphen hyphen here, all of our CSS variables come up. Now, you're going to see some old ones like hyphen accent, but all of the new ones in the system follow a very specific pattern. Now, that pattern is if it's a color, whether that is even like the intention of the color, whether that's like primary, background, or even like shaded or tinted colors, it always starts with hyphen C. So even like foreground hyphen C foreground that means we're going to be using a foreground color or hyphen C bg for background or like I said for
hyphen C primary. This gives you an idea about what CSS variables are there. And after I remove the old CSS variables from the system all you're going to see is the ones that exist. Whether that is for borders, border radius, shadows with an S, and so on and so forth. This gives us the nice ability to be able to really follow a nice system, but also know what's out there. Uh that way when you're working in your text editor, you're not having to look up and let's head to the variables.css file and scroll and find the one that I want. you kind of know generally, you know, FV for font variation, F for font or FS for font size, etc., etc. Um, and on top of that, I've also put together this CSS variables cheat sheet within our documentation in our story book. We are using storybook to build an isolation,
and I made this little cheat sheet to show you all of the different variables that we have working. Now, the color system is still in flux. So, some of these colors you'll notice are not right yet. Uh, but for the most part here, you'll see that all of this stuff fits a very specific workflow. And it's really great for font size and variations. You can see exactly what exists out there within this new system. Anytime you want to use anything, you can come here if you want a visual confirmation. But for the most part, if you want to just check out what it is at any given point, you can just do that. Hyphen C, whatever. We also have some interesting variables with shade or tint, shade or tint light, and shade or tint hard. This is a CSS variable style that I really like because what it does is it gives you the ability to have a light or dark mode, shade or tint. Now, what I mean by that is we're using the light dark function here. And of course, this this obnoxious
uh you know CSS color property that's changing the colors. Either way, in light mode, this is going to be a transparent black. In dark mode, it is going to be a transparent white. So, basically making it so it's always a transparent gray that looks nice in any system, whether that is light mode or dark mode because this site is being built from the ground up to support both of those. So, that is our VS Code setup for CSS. Now, in addition to that, we're also using style lint pretty hard. And styl is a really great system for like what it says linting your CSS. So we are using the stylint plugin for VS Code.
But in terms of what our setup is, we're doing something somewhat interesting in a various ways. So what settings are we using for stylint? Well, we are using a number of plugins. Stylant declaration strict value. Stylant media use custom media. I'll tell you about those in a second. Stylant no undefined classes.
Stylant value, no unknown custom properties. So these are all really great. Now we can start with some of these ones that make a little bit more obvious sense. So basically no unknown custom properties. What it's going to do is through this config here, it's looking at any of these files to see where our custom properties are defined.
And if those custom properties are not defined and we're trying to use it in our CSS, it's going to give you an error. which means that hey anytime that you're trying to use a CSS variable that is not defined within the system that we're expecting to be there it errors right that's great we don't want we don't want uh people to just toss in potentially unknown CSS variables that's a good one now style and no undefined classes this is actually a plugin that I wrote and I wrote this because when we're moving from one system to another system ripping a lot of the CSS what you might end up having is a bunch of classes that are no longer defined. Um, you know, maybe they were defined in the old system and you could do a find and replace to remove all those, but it would be better to have a system that will error out. Now, this is an atypical styl plugin because it's actually looking at HTML files and if the HTML is using a class that is not defined within
the system, then this will error out. So very similar to no unknown custom properties. No undefined classes does the same thing. Now the next one here is styand media use custom media. In the last file you may have seen these custom media. These are being processed through a post CSS plugin. And that means anytime we're using a breakpoint for a media query, the idea is it should be one of these variables rather than an actual custom definition within the CSS to keep things nice and tidy. So, anytime you want to use a media query, you're using this custom media syntax.
Now, this is a real syntax. It's just not supported yet. I don't even know if it's in any of the browsers, but we are using post CSS for that. And that's a good use case for post CSS. It doesn't need to be dynamic. Now, next one here is stylant declaration strict value. And I'll show you a little bit about that just down below here with the config.
So, stylant declare declaration strict value means that for font size or colors, we want to make sure that you are using a CSS variable every single time for that. What we don't want is to be in a situation where I'm in an HTML file. Oo, look at this. I found an old CSS variable. Again, this is an older component. Stuff like this is still being ripped out. This is in flow. But you can see how this errors. Either way, what we don't want to have is a situation where I'm able to come in here and say color red. This will error out and say that, hey, you're supposed to be using a CSS variable. So, in that case, I can come in here and do C and maybe do look for red. All right, there it is. C red. Perfect. Right, that way it's not going to error. So, there are certain values that we expect to always be CSS variables of which that list will modify over time. Currently, it's just font size and color, but eventually it's
going to be border radius. It's going to be many other things. We want to be able to ignore certain values like inherent, initial, transparent, unset. So, we want to give the user the ability to give these as nonCSS variables without error because they're not colors. I don't I just don't I don't see the need for it. Import notation. This is something that's only because we're using CSS importing via post CSS. Not really something too crazy. Uh font family, no missing generic family keyword. I had to turn this rule off since we kind of do something funny with how we're declaring font family names. So, nothing big there. And again CSS media use no custom media. This is media use custom media.
This is the media query one. We just have it set to uh always. And this is alpha value notation. Now you might be wondering about this one. And you may have seen when you were looking at some of our CSS here when I was talking about the light and dark mode. You may have seen this shorthand right here. And it's not even a shortand it's just how this function works. So there is the RGB function and the RGBA function. And in the RGBA function, you're used to doing uh value, value, comma, value, comma, alpha, right? Uh R, comma, G comm, B or RG, yeah, alpha. You get it? The newer version of doing that same syntax is this one right here, where you do RGB with spaces and then a forward slash and then the alpha value. So what I'm saying is hey don't you try to come in here and do something like oh this is going to be bad do
something like this don't you do this uh we want to m not for well one the reason being there's nothing wrong with this syntax what I wanted to do is to use the modern color function notation because it is consistent across other color notations and it makes a lot of sense but also I just want everybody to be using the same darn thing and I don't want to, you know, see a bunch of different styles for doing the same thing given that there is more than one way to do this here. Now, the last thing I want to show you really quick is our post CSS config. Post CSS is not something we're going crazy with this time around. We want to keep it to as minimal of additional CSS uh transformation as possible. But some things that we're using is the at import to allow us to import CSS. This is something that makes a lot of sense to do during build time considering you don't want any sort of runtime uh going off and fetching additional files when you're loading your CSS. So having this
happen at build time to just take all of your CSS files that you can still keep organized and then scoop them all into one file super duper helpful. You saw that in our our base see our styles.css. Um in addition we're also using post CSS preset env. We're saying stage three and then some of the features that we're saying true to just out of the box here. And by all means, some of these might not, you know, this this is kind of an older config. So, some of these things might not be need to be defined here still. But, uh, cascade layers giving us option to use the at layer that you saw. Media ranges allowing us to say width is greater than number like you saw. Uh, custom media queries allowing us to use those custom media queries like we often showed. And then nesting rules as well. So, this is going to allow us to use CSS nesting without having to worry about which browser support it or not. That said, CSS nesting is a great thing that you can be using today in your CSS. So, that is our post CSS config. Not a ton of
stuff there, but it is nice to have when you need to have it. A part of our CSS system within this site is going to be one making a smooth editor experience. We need IntelliSense. We need autocomplete. We need warnings. We need errors. We need those kind of flashing red lights to say, "Hey, you're using this thing that doesn't exist." We also want it to be very well documented and easy to follow given this type of documentation page, but also how you access it within your editor. We also wanted to have very consistent everything as in uh not one person using a color and one person using a variable, one person using pixels, another person using a variable. We want to force people into that happy path which is always using a variable when there is that variable available. This whole thing is being done inside of spelt with storybook we where we are doing a component-based development flow where everything is being built out as a single component whether that is
something like this something like our icons something like these ranked items here these are all being developed within isolation in a way that gives us the ability to make sure that things do work in isolation or together and storybook has been a bit of a challenge In some regards, there's some kind of annoying things about Storybook that are not my favorite, but I think this is the best way to build a documentation system that also works and you can see everything working, light, dark mode, all of the above. You can see how all of these components fit together and everything just works nice and you can document your entire system. So when I get a little bit more further along on this, I'm going to talk a little bit about how we used Storybook with Spelt and Spelt Kit and our overall system to build this entire thing. Now the last little bit before we move off of the CSS is I want to show you how this is all organized because we have one main
style.css file that looks like this and we have determined a set of layers. Now layers uh allow you to better choose the stacking order of your CSS. So that way it's not where it's defined but uh which layer it's defined in. So the first thing we do is we have a reset. This reset is given inside of our styles file. This is the josh ku uh the josh ku css re reset. It is nice and simple uh hyper modern CSS reset. I have our base CSS that I I intentionally spelled a bass. It's just for fun. Um the the bass CSS. It's our base CSS. Um that's our next layer. Then a utilities layer. Then a layout layer. And then the theme layer. Uh the theme layer and all these things. It just kind of sits on top. And then any CSS that we write in individual components just kind of sits on top of all of that. So we have the reset, then the base CSS. The rules for base CSS is
that it's only CSS that is defined by actual elements here. And you can see the layer name and everything. So this is CSS defined that on every single time we use an a list item, a th a TD, an anchor tag, any of that stuff. This is CSS that's defined on an individual element itself. And then again after that we are loading up our variables.
And then after that, we're loading up our utilities, which I've already shown you, our typography, and then the layout. Now, the layout stuff is still in flux. These are a handful of utility classes. Uh you can see a giant to-do here. You can see some red squigglies. And then lastly, we just have buttons, which I feel like I always have a button CSS. Um we're kind of taking the approach on this site to not make things like buttons an individual component. I don't want to be importing capital B button onto the site just to use something that has CSS. So, just being able to make a class and a button uh CSS line that styles all buttons, it's good enough for me. Cool. So, let me know what you think about this system. Are there any style lint plugins that we are not using that you think we should be using? Is there any VS Code setup that we are not using that we should be using? Do you have any questions, comments, concerns, any ideas, or things
that you foresee as being terrible? Or do you just have some uh general thoughts on how we're approaching this? Either way, I will have more of these devlogs as the site gets built so we can talk through some of the choices we're making and why. As always, this is Scott with Syntax, and I will see you in the next
Quote it with credit and a link. Quoting Syntax