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

Building Micro Layouts

7m:59s

Micro layouts can be thought of as the layouts for a component. They are somewhat synonymous, but the word micro fits into the whole macro-micro system, so it’s easier to remember them that way.

For example, if you have a two-column macro layout, then everything within each of these two columns is a micro layout.

The grid is the macro layout
Micro layouts control the styles here
Micro layouts control the styles here

There are lots of variations of micro layouts — most components you create will live within this category. Examples of these include: Accordions, Cards, Login components, and others.

accordion example
Example of an accordion
login component example
Example of a login component

Building real examples

Let’s take a look at how to build some components so you have an idea how to use the micro layout utilities.

A hero component

One of the most common layout patterns is the content for a hero. Here, you have a header, some text, and a couple of buttons.

Hero content

The easiest way to do this is to use the vertical utility we talked about in macro layouts to build the vertical portion. Then I have a horizontal utility to build the horizontal portion.

<div class="vertical gap-2">
<h2>Header</h2>
<p>Text</p>
<div class="horizontal gap-2">
<a href="#">Button 1</a>
<a href="#">Button 2</a>
</div>
</div>

Here’s an example of this working:

Never miss the cache again

Cache every single thing your app could ever do ahead of time, so your code never even has to run at all.

A responsive card

Many micro layouts — even responsive ones — can be built just with vertical and horizontal utilities.

The Product Hunt card below is a good example:

Here we have three major parts.

  1. The app icon
  2. The content
  3. Comment and Upvote buttons

The general layout is a horizontal one, but the content needs a vertical layout.

Product Hunt card layout annotated with horizontal and vertical directions

We can scaffold this quite quickly with the following HTML.

<div class="horizontal">
<img src="app_icon" alt="icon_alt" />
<div class="vertical flex-grow">
<!-- Card content -->
</div>
<!-- Comment and upvote buttons -->
<button class="vertical">
<svg> Icon </svg>
<span> 10 </span>
</div>
<button class="vertical">
<svg> Icon </svg>
<span> 100 </span>
</div>
</div>

The content needs a vertical to house the title and text. Then another horizontal to house the tags.

<div class="vertical flex-grow">
<strong> title </strong>
<p>Text</p>
<div class="horizontal">
<svg>Tag icon</svg>
<a> API </a>
&middot;
<a> Artificial Intelligence </a>
&middot;
<a> Development </a>
</div>
</div>

Without any spacing treatment, the component looks a little bit horrendous because the gap is set to four spacing units (gap-4) by default in both horizontal and vertical utilities.

App icon
Mistral OCR 3

Accurate OCR for notes, forms, tables and handwriting

Then we can adjust a few gap properties here and there to make the component look right:

<div class="horizontal gap-3">
<img ... />
<div class="vertical gap-0 ...">
<strong> ... </strong>
<p>...</p>
<div class="horizontal gap-y-0 gap-x-1">
<svg>Icon</svg>
<div class="flow gap-[inherit]">...</div>
</div>
</div>
<button class="... gap-0">
<svg>Icon</svg>
<span> 10 </span>
</button>
<button class="... gap-0">
<svg>Icon</svg>
<span> 100 </span>
</button>
</div>
App icon
Mistral OCR 3

Accurate OCR for notes, forms, tables and handwriting

To make this responsive according to Product Hunt’s original card, we can use Tailwind’s responsive variants and hidden utility to hide stuff on smaller containers.

<div class="horizontal gap-3 !text-6">
<img ... />
<div class="vertical flex-grow gap-0">
<strong> ... </strong>
<p>...</p>
<div class="hidden @bp7:horizontal !gap-0 !gap-x-1">
<svg>Tag icon</svg>
<div class="flow gap-[inherit]">...</div>
</div>
</div>
<button class="hidden @bp7:vertical aspect-square self-start !gap-0">
<Icon class="w-4 h-4" icon="tabler:message-circle" client:idle />
<span> 10 </span>
</button>
<button class="vertical aspect-square self-start gap-0">
<Icon class="w-4 h-4" icon="tabler:caret-up" client:idle />
<span> 100 </span>
</button>
</div>

And the outcome is a responsive card!

App icon
Mistral OCR 3

Accurate OCR for notes, forms, tables and handwriting

Fancy Backgrounds

There are many cases where a background is added to a section to increase visual interest. Here’s an example where I added an SVG background on Learn JavaScript’s website.

Stacked background image on Learn JavaScript

Doing this is simple with stack — it “stacks” items up with CSS Grid, positioning everything on top of each other. (Imagine 1 column, 1 row, and everything just piled on each other).

<div class="stack">
<div>Layer 1</div>
<div>Layer 2</div>
<div>Layer 3</div>
</div>

To create a background image, all we need to do is to wrap the background and content inside the stack.

<div class="stack">
<div class="background"><!-- Your background here --></div>
<div class="content">Content</div>
</div>

Interactive Cards

Imagine an overlay that shows up when you hover over a component. You’ve probably seen this in the wild a lot!

stack makes this somewhat easy to create, but it doesn’t support transitions out of the box.

Since this is a common pattern, I made a stack-interactive variant that shows the overlay on hover, focus-visible, and focus-within. Then all you need to do is to adjust the transition or animation properties on the overlay.

<div class="stack-interactive">
<div>Hover over me!</div>
<div class="overlay transition">This is the overlay content</div>
</div>
Hover over me!

This is the overlay content

Login Screen

login component example
Example of a login component

Earlier, I showed you a login component.

This is easy to build — we just need vertical to stack the buttons and fields. The only tricky part is the divider that contains OR.

For cases like this, I have created a divider component that lets you make this rather easily. You just have to include the text within the component.

<div class="vertical">
<!-- Buttons up here -->
<div class="divider-x">OR</div>
<!-- Form down here -->
</div>
OR

Scrollbars made easy

We don’t use horizontal scrollbars much, but when you need it, you can use the Scrollable component. It makes a container scrollable + enables scroll-snap functionality at the same time.

<div class="scrollable-horizontal">...</div>
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14

Documentation and other utilities

At the time of writing, Splendid Layouts has 9 micro-layout utilities in it. And just these 9 utilities allow me to build almost any component I want.

I’ve shown you 5 of them so far (the most useful ones).

  • horizontal
  • vertical
  • stack
  • divider
  • scrollable

There are a couple more that are used contextually:

  • flow
  • breakout
  • container
  • new-stacking-context

You can find out more about each of them in the documentation.