I categorized most styles necessary for a website into 4 simple categories:
- Layouts
- Typography
- Theming
- Effects
Here’s how I generally write styles for each system.
Layouts
At this point, I build most of my layouts with Splendid Layouts. It contains all of the utilities I need to make 95% of the sites I build.
I almost always write these directly in the HTML because each layout depends on the section themselves. There’s not much use trying to consolidate things together.
<section class="section"> <div class="wrap vertical"> <div class="vertical"> <h2 class="text-center max-w-[12em]">Title</h2> <p class="text-center max-w-[12em]">Subtitle</p> </div>
<div class="prose max-w-narrow mx-auto"> <!-- Text goes here --> </div>
<div class="grid-simple [--cols:2] max-w-standard mx-auto"> <!-- Grid items go here --> </div> </div></section>However, if I need to reuse a layout consistently — like a global content-sidebar layout, I might create a class for it.
.grid-content-sidebar { @apply grid-simple;
@media screen (width >= 800px) { --cols: 3;
.content { --span: 2; } }}Typography
Typography is always defined in a type.css file. These typography utilities are used directly in the HTML according to the required element.
I rarely use typography utilities in CSS.
<div class="wrap vertical"> <div class="vertical"> <h2 class="h2 ...">Title</h2> <p class="h2-subhead ...">Subtitle</p> </div>
<div class="prose ..."> <!-- Text goes here --> </div></div>The only time I use typography utilities in CSS is when writing them in CSS saves more keystrokes than writing them directly in HTML. This is rare, because most of these situations can be alleviated with framework component files.
Colour and Theming
For colours, I generally save them in two files:
colours.csspigments.css
These are named so I know what they contain exactly — and I can reach into them to adjust values easily.
For usage: I tend to use the colour directly with Tailwind when the requirements are simple. Then I switch over to pigments for interactive elements.
<h2 class="text-yellow-500">...</h2><button class="button pigment-yellow-heavy">...</button>Certain interactive elements are styled in the CSS because determining a pigment for them is too much work. For these, I use the pigment utility and adjust the values within them.
.tabs { @apply pigment; --selected-color: var(--colour-yellow-500);}Effects
I tend to place effects in the HTML whenever I can — so they become obvious when I look at the HTML.
<h2 class="text-stroke spl-stroke-yellow-500">...</h2>I have a higher tendency to put complex effects — like gradient borders — into their own CSS file, because they tend to be used together with the components they’re created for.
.card { @apply bezel-frosted outer-gradient; --gradient-shape: circle; --gradient-position: 0% 50%; --gradient: blue 50%, pink 75%, red;}Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson