Alloy GitHub

Why I believe in Alloy

People ask me why another CSS kit when there's Tailwind. It's a fair question. I've carried the same stylesheet between client projects for close to ten years, and this is the long answer.

The decisions have to live somewhere

A page is a pile of small decisions. This gap, that grey, how wide this column is. They get written down somewhere, and there are only two places for them: in the HTML or in the CSS.

Put them in the CSS and you start with a nice name like .post. Then the sidebar wants a smaller one and the homepage a bigger one, and soon there's .post-small, .post-featured and .post-in-sidebar, each with its own idea of padding. The names were supposed to hide the details. Now you remember the names and the details.

Tailwind showed that most people are fine with classes in the HTML. I agree with that part.

Where I part ways with Tailwind

Tailwind lets you write any value you like:

<div class="mt-[13px] p-[18px] text-[#3a3a3a] w-[347px]">

That's a lot of freedom, and freedom drifts. One page takes 13px, the next one 14px, and a year later nobody knows which grey is the real grey.

You can lock it down with a config, and good teams do. In a company the values have to be standard anyway. But at that point you're building your own design system, on top of a build step that scans your files for the classes you used.

The values, picked once

Alloy is that design system with the values already chosen. Spacing comes in 16 steps from 0 to 140px, corners in 6, and there are two page widths. I didn't pick them on a whiteboard. I locked them after they'd built 82 real pages: a shop and its back office, dashboards, a news site, checkout, settings.

It's one file, 23 KB compressed. No build, no config. One line in your <head> and it works in Django, Rails, Laravel or a plain HTML file:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@alloyhtml/css@1/dist/alloy.min.css">

Small things that bugged me for years

A photo behind content. In every project I had a card or a header with text on a picture, and the picture either stretched or left an empty strip. Same photo, three ways:

An <img> made to fit: squashed
At its own size: an empty strip

Jazz night, Friday

Doors at 8, two sets

With .has-bg-img: it fills any size, and the text sits on top
<div class="has-bg-img rounded-8 padding-20" style="height: 200px">
  <div class="bg-img" style="background-image: url('/photo.jpg')"></div>
  <p class="h5 text-white">Jazz night, Friday</p>
</div>

For a lone <img> with nothing on it, object-fit: cover does the same job, and that's fine. .bg-img is for when content sits on the picture.

Loading skeletons. Usually you build the card, then a second skeleton version of it with grey bars at guessed widths, plus the CSS for the bars, and you keep the two in step every time the card changes:

<!-- card.html -->
<div class="card">
  <div class="card-name">Alex Morgan</div>
  <div class="card-meta">3 items, 2 hours ago</div>
</div>

<!-- card-skeleton.html: a second copy, kept in step by hand -->
<div class="card">
  <div class="bone" style="width: 110px; height: 14px"></div>
  <div class="bone" style="width: 150px; height: 12px"></div>
</div>

/* and the bars */
.bone { background: #e5e7eb; border-radius: 4px; animation: pulse 1.5s infinite; }
@keyframes pulse { 50% { opacity: .5; } }

Here the loading card is the real card with one class on it. Every line inside becomes a bar at its own size, and nothing moves when the content arrives:

<!-- While it loads: the real card, with .skeleton -->
<div class="skeleton bg-raised border border-subtle rounded-8 padding-16" aria-busy="true" inert>
  <div class="text-body-2 font-weight-600"><span>Alex Morgan</span></div>
  <div class="text-body-3 text-muted"><span>3 items, 2 hours ago</span></div>
</div>
<!-- When the data arrives: remove the class. Nothing moves. -->
AM
Alex Morgan
3 items, 2 hours ago
Loaded
AM
Alex Morgan
3 items, 2 hours ago
The same card, with .skeleton

Dark mode. Colours are named by their job, like bg-raised for a card and text-secondary for quieter text. So dark mode is one more stylesheet link, and the markup stays the same.

Menus, dialogs and tabs are plain HTML (popover, <dialog>, radio buttons), so they work with JavaScript off. I wrote that one up in A dropdown, a dialog and tabs with no JavaScript.

Using it with AI

Ask an AI for a UI and it writes Tailwind, because that's what it has seen most. I'm not going to argue with that. I give it llms.txt instead, every class in one text file. Paste this into any chat or agent:

Build a settings page for my app with Alloy CSS. Read alloyhtml.com/llms.txt first.

With a fixed set of values it has no 13px to invent. And when it does make something up, the checker lists it, with the file and the line, and fails:

$ npx @alloyhtml/css check templates/
templates/settings.html:14  .mt-4
templates/settings.html:31  .btn-primary

2 classes Alloy CSS doesn't define. Use a kit class instead (see alloyhtml.com/docs), or pass --css for your own stylesheet.

That's how the remakes were built. I gave Claude the same rules and two real sites to rebuild, a Hacker News front page and a Wikipedia article, and went back and forth until they looked right. Neither has a stylesheet of its own. Their look is a few brand values on the <html> tag, plus one rule each for visited links, which a tag can't reach. Everything else is kit classes.

Someone always asks where the plugins and the community components are. I think that matters less now. If I need a pricing table, the AI writes it from the same classes, and it matches the rest.

When it's not for you

If you're happy with Tailwind, stay with it. If your team is on React with its own component library, you already have your answer. And the dialogs need recent browsers: Chrome 135, Firefox 144 or Safari 26.2.

Otherwise, it's free and MIT. The whole idea is in one file, example.html. Open it, view the source, or give your AI the llms.txt and ask for a page.

Get an email when Alloy ships something new

New Alloy CSS releases and new templates. Only when something ships.