Essential CSS
JavaScript Roadmap
Learn JavaScript
Mastering Web Typography
Practical Astro
Understanding Async JS
Unorthodox Tailwind
API Masterclass
Build and Deploy
The Beginner Freelancer
Real World Node
Profile Billing Logout
Unorthodox Tailwind
Lesson Plan
  1. Introduction
    1. Introduction
    2. What Tailwind brings to the table
    3. Tailwind: The Good and The Bad
    4. The First and Most Important Step
    5. Simple Unorthodox System
    6. The System I Use
  2. Tailwind Fundamentals
    1. Introduction
    2. Installing Tailwind
    3. Using Tailwind utilities
    4. Understanding Tailwind’s utility system
    5. Understanding Tailwind values
    6. Understanding Tailwind variants
  3. Unorthodox Fundamentals
    1. Introduction
    2. Making Simple Tailwind Utilities
    3. Components vs Utilities
    4. Specificity, Cascade, and CSS Layers
    5. Debugging Tailwind Styles
    6. Composable Utility System
    7. Create lots of components
  4. Layouts System
    1. Tailwind is great for layouts
    2. Four Types of Layouts
    3. Building Shell Layouts
    4. Building Macro Layouts
    5. Better Responsive Variants
    6. A collection of maximum widths
    7. A note on grid wrappers
    8. Working with sections
    9. Building Micro Layouts
    10. Positioning Layouts
  5. Typography System
    1. Introduction
    2. A system for using multiple typefaces
    3. Tailwind's font-size system
    4. Finding your font-size system
    5. My font-size system
    6. A simple responsive typography system
    7. The main body
    8. Vertical rhythm
  6. Theming System
    1. Introduction
    2. Tailwind's colour system
    3. The pigment system
    4. Tailwind's gradient system
    5. A friendlier gradient system
    6. Handling SVG fill and stroke
    7. Improving Tailwind's colour palette
    8. A simple way to theme
  7. Useful Tools
    1. Introduction
    2. Making functional utilities
    3. Custom variants
    4. Scaffolding tools
    5. Extending Tailwind
  8. Effects System
    1. Introduction
    2. Vertical text
    3. Strikethrough text
    4. Text stroke
    5. Highlighting text
    6. Nicer shadows
    7. Transitioning shadows
    8. Drop shadows
    9. Dark mode tricks
    10. Gradient borders
    11. More effects to explore
  9. Putting Everything Together
    1. The Unorthodox Tailwind process
    2. The 4 systems combined
    3. Create components liberally
    4. Advanced tips
    5. My CSS Structure
    6. A Cheatsheet
    7. Consolidating your thoughts
    8. Parting words

A simple responsive typography system

4m:15s

A long time ago, while I was still using Modular Scale, I created a library called Typi that helps me with responsive typography.

It uses Sass. You can create a map of all the different sizes that you want to use and it works — brilliantly.

$typi: (
base: (
null: (16px, 1.4),
small: (18px),
large: (20px)
),
h1: (
null: (24px, 1.3),
small: (2.369rem, 1.2),
)
// Other font maps here
);

Once you have created a map, you can include the font-size you created by using the typi mixin.

h1 {
@include typi('h1');
}

And typi will create the following CSS for you:

/* css output */
h1 {
font-size: 1.5rem;
line-height: 1.3;
}
@media all and (min-width: 600px) {
h1 {
font-size: 2.369rem;
line-height: 1.2;
}
}

I will be honest with you, I still love this approach, and I highly encourage you to check it out if you are still using Modular Scale. (There’s a ms function that calculates Modular Scale values for you. But fair warning, this hasn’t been maintained for many years.)

I’ve loved it so much that I ported the entire map system into a Tailwind config which works with Tailwind 3.

const scales = {
h1: {
base: ['24px', 1.3],
bp8: `36px`,
},
}

But as I migrated to Tailwind 4, I realized that this system doesn’t work anymore. It creates problems because it’s very difficult to define a map with the way Tailwind utilities work in this version.

So, with great pains, I ditched all of that and went for a very simple system instead.

My simple responsive typography system

You will laugh at this because there is no other system that is as simple as this.

I simply create a utility for each pattern I like to use, and then I include the font-sizes and the responsive values and the different breakpoints within. This is nothing more than CSS with a utility wrapper.

It’s so simple that I’m ashamed to blog about it, even though there’s nothing special about it.

Here’s what it looks like.

/* example of a h1 utility */
@utility h1 {
@apply marvin;
@apply text-12;
line-height: 1.2;
@media screen and (width >= 800px) {
@apply text-14;
line-height: 1.15;
}
}

I put all of this into a type.css file so they can be accessed and changed easily in one location.

type.css
@utility marvin { /*...*/ }
@utility jetbrains { /*...*/ }
@utility h1 { /*...*/ }
@utility h2 { /*...*/ }
@utility h3 { /*...*/ }
@utility h4 { /*...*/ }

As I’m writing this, I have this feeling that you might be disappointed after reading that I have such a simple system…

But isn’t that good news too? This means responsive typography doesn’t have to be complicated. It doesn’t have to be tedious, and it doesn’t have to be some awesome CSS that’s hard to handle. (Pointing to fluid typography here).

No need to make everything responsive

It is tempting to make everything responsive, but there is no need to do so. The smaller type doesn’t need to be responsive because it can just keep its size throughout.

To find the right font-sizes, I look at each component at different viewports and make my decisions from there. It can be tedious that way, but there’s no other way than this manual check if you want to have sizes that look perfect.

But my general rule of thumb is this:

  • Anything below 16px? Not much change needed.
  • Anything above? Give it a deeper look.

Don’t change global font-size

When I first started out, I had this habit of changing the global font size at different viewports.

/* What I did in the past */
html {
font-size: 100%;
@media screen and (width > 600px) {
font-size: 112.5%;
}
@media screen and (width > 800px) {
font-size: 125%;
}
}

My rationale for doing this is:

  • All of the other font sizes should be relative to body size.
  • When we change the body size, the other font sizes will naturally change as well, which makes responsive typography easier.

But there are two major flaws in the argument.

  1. If the user zooms in or out, the font size will change accordingly because the viewport width has changed, so there are cases where I can’t reach the font size that I actually want to use — I found out about this when I was debugging, and for a long time it irritated the heck out of me.
  2. Bumping up the body size (and expecting everything to change accordingly) only works for marketing sites. When I started designing applications, I realized that you can’t do that because certain text needs to stay small.

So I treat the body text like any other element now — I give it a class (called prose) that I can resize easily.

.prose {
@apply text-7;
@media screen and (width >= 600px) {
@apply text-8;
}
}