Why I built a Svelte component library
Every time I started a new Svelte project, I went looking for a component library, and every time I ran into the same problem. Almost all of the good options are built around Tailwind. That’s fine if Tailwind is how you like to work. I write a lot of my design systems in plain CSS, though, and with those libraries I spent more time working around the styling than using it.
So I built my own. Distill UI is an open-source Svelte component library, now also available for Vue, where every component is styled with plain, scoped CSS. This post is the story of why, and what I decided along the way.
The problem with Tailwind-first libraries
Svelte gives you something lovely out of the box: a <style> block inside each component, scoped to that component. You write normal CSS, it only applies where you wrote it, and you never have to think about class names clashing.
Most Svelte UI libraries skip that entirely. Their components ship with long strings of utility classes, and the expectation is that you’ll override them with more utility classes. If your project doesn’t use Tailwind, you’re left with two bad options. You can reach for :global() and style the library’s internals from the outside, which breaks the scoping that made Svelte nice in the first place. Or you can wrap everything in extra markup and selectors until it looks the way you want, which is a lot of boilerplate for a button.
I’ve written about Tailwind’s trade-offs before, and I still use it on some projects. I wanted a library for the projects where I don’t.
Copy the code, own the code
The idea I borrowed is the one shadcn/ui made popular: instead of installing a package you can’t touch, you copy each component’s source into your own project. Distill UI follows the same structure as shadcn-svelte and shadcn-vue, so if you’ve used those, it will feel familiar.
A small CLI does the copying:
npx distill-ui init
npx distill-ui add button dialoginit adds the design tokens and imports them in your root layout, and add drops the component files into your project. From then on they’re yours. If you want a button to behave differently, you open the file and change it. The CLI also won’t replace a file you’ve already edited, which matters once you’ve started making a component your own.
Plain CSS you can read
Each component has one class name and a short block of CSS in its own <style> block. Here’s a shortened version of the button:
.button {
height: var(--dui-button-height, 2.25rem);
border-radius: var(--dui-button-radius, var(--dui-radius-md));
background: var(--dui-button-bg, var(--dui-color-primary));
color: var(--dui-button-fg, var(--dui-color-primary-foreground));
&:hover {
background: var(--dui-button-hover-bg, var(--dui-color-primary-hover));
}
}Variants and sizes are data attributes, like data-variant="outline" or data-size="sm", rather than piles of classes. Hover and disabled states sit right where you’d expect to find them. Anyone on a team who knows CSS can open this file and change it without learning a new vocabulary first.
Tokens and theming
Colours, spacing and corner radius all run on CSS custom properties, prefixed with --dui-. There are two layers. Global tokens like --dui-color-primary and --dui-radius-md set the look of the whole library, and each component has its own variables, like --dui-button-bg, that fall back to those globals.
That gives you two ways to theme. Change a handful of global values and the whole library matches your brand. Or set a component variable on a single button, or on any parent element, when one part of the page needs to look different. There are no overrides to write and no specificity fights.
Dark mode follows the system setting by default, and you can force it with one attribute on the page.
Accessible by default
This is where I didn’t want to cut corners, and also where I didn’t want to reinvent anything. Getting keyboard support, focus handling and screen reader behaviour right for a dialog or a dropdown menu is hard, and other people have already done it well.
So Distill UI uses native HTML elements wherever the browser already does the job, and builds on headless primitives for the hard parts: Melt UI for Svelte and Reka UI for Vue. They handle the behaviour, and Distill UI handles the styling. Every component was also checked with axe in both light and dark mode, because contrast that passes in one theme can easily fail in the other.
Svelte first, then Vue
I built it for Svelte 5 first, because that’s what I use most. Once the Svelte version settled, bringing it to Vue 3 was mostly a matter of matching the API. The component names, options and styles are the same in both, so one design system can cover projects in either framework.
What I learned
The biggest lesson was how much a design system depends on decisions you make before writing a single component. How the tokens are named, and which values belong to the whole library versus a single component, shaped every file that came after. Getting that right early made the later components quick to build.
I also learned that a big share of the work in a component library is the docs. Each component has its own page with a live preview, the code to copy and notes on customising it. Without that, the components are just files.
That’s the same thinking I bring to client work. I design the interface and build it myself, so the design system and the code come from the same place and nothing gets lost in a handoff.
Try it
Distill UI is free and MIT licensed. The docs, live previews and install guide for both Svelte and Vue are at distill-ui.vercel.app, and the source is on GitHub. If you try it and something’s missing, I’d like to hear about it.