ZL
About Articles Contact
Published on Oct 10, 2023
Filed under:
#astro,
#splendidlabz,
#tailwind

Splendid Astro Spacing — A Tailwind Utility for Astro

When using Tailwind with Astro, you’ll notice that Tailwind’s space utilities stop working when you use it with Astro Components or Slots .

<!-- Doesn't work when using with Astro components and slots -->
<div class="space-y-4">
<Component client:load />
<Component client:load />
</div>

The reason is simple. I’ve wrote about the cause in a previous article and how to fix it.

You can read that article for more information, but the gist is:

  1. Astro components and slots wrap it’s contents in a div that has display: contents
  2. The * + * selector, which Tailwind uses for its space utilities, cannot target the elements within these Astro components and slots

A simple fix

Fixing this is simple. We just have to modify Tailwind’s space utilities with a plugin — so they can dive one level beyond Astro’s components and slots.

I’ve created this plugin and added it as part of Splendid UI. You can install it Splendid UI like this.

Terminal window
npm install splendidlabz

Then you can use the plugin in your Tailwind config file like this:

module.exports = {
plugins: [require('splendidlabz/tailwind/plugins/astro-space.cjs')],
}

(I know the path looks long and complicated right now. It’s something I’ll simplify in the future as Splendid UI becomes more mature. For now, just enjoy something that works! 🙃).

That’s it!

Further Reading

  • Splendid UI
  • Astro Space Utility
Previous 3 Techniques to learn JavaScript effectively Next Splendid Layouts

Join My Newsletter

I share what I’m learning on this newsletter: code, building businesses, and living well.

Sometimes I write about technical deep-dives, product updates, musings on how to live, and sometimes my struggles and how I’m breaking through.

Regardless of the type of content, I do my best to send you an update every week.

If you’re into making things and growing as a person, you’ll probably feel at home here.

“

Zell is the rare sort of developer who both knows his stuff and can explain even the most technical jargon in approachable — and even fun — ways!

I’ve taken his courses and always look forward to his writing because I know I’ll walk away with something that makes me a better front-ender.

Geoff Graham
Geoff Graham — Chief Editor @ CSS Tricks
The Footer

General

Home About Contact Testimonials Tools I Use

Projects

Magical Dev School Splendid Labz

Socials

Youtube Instagram Tiktok Github Bluesky X

Follow Along

Email RSS
© 2013 - 2025 Zell Liew / All rights reserved / Terms