CSS Zero
An opinionated CSS starter kit for your Ruby on Rails application. You can think of it like a “no build” Tailwind CSS.
Installation
Add this gem to your project.
bundle add css-zero
Add the base.css file to your application.
bin/rails generate css_zero:install
Add only the components you need. (Optional)
bin/rails generate css_zero:add accordion alert avatar badge breadcrumb button card collapsible dialog input progress switch table
Requirements
If you are using Propshaft (recommended) make sure to load all the CSS files in your layout.html.erb.
Click here to see how
<%= stylesheet_link_tag :all, "data-turbo-track": "reload" %>
If you are using Sprockets make sure to load all the CSS files in your application.css.
Click here to see how
/* *= require _reset *= require animations *= require borders *= require colors *= require effects *= require filters *= require grid *= require sizes *= require transform *= require transition *= require typography *= require_tree . *= require_self *= require zutilities */
Some icons in the examples are not copied to the project. If you are looking for good ones, I recommend Lucide.
Usage
<h1 class="text-xl font-bold mb-4"> Write most page content using utility classes. </h1> <div class="custom-component"> Create components using CSS variables. </div> <div class="card"> Optionally, copy pre-built components into your application. </div>
.custom-component { background-color: var(--red-500); border-radius: var(--rounded); block-size: var(--size-4); }
Check the CSS files in the repository to see the available variables and utility classes.
Components
Accordion
Show me the code
<div class="accordion"> Is it accessible? <p class="text-sm">Yes. It adheres to the WAI-ARIA design pattern.</p> Is it styled? <p class="text-sm">Yes. It comes with default styles that matches the other components' aesthetic.</p> Is it animated? <p class="text-sm">Yes. It's animated by default, but you can disable it if you prefer.</p> </div>
Alert
Show me the code
<div class="alert alert--negative flex items-start gap"> <%= image_tag("circle-alert.svg", role: "presentation", size: 16) %> <div class="flex flex-col"> <h1 class="font-medium leading-none mbe-1">Error</h1> <p class="text-sm">Your session has expired. Please log in again.</p> </div> </div>
Avatar
Show me the code
<div class="flex item-center gap"> <div class="avatar"> <%= image_tag "cartoon.jpg", role: "presentation", size: 48 %> </div> <div class="avatar"> <span class="avatar__fallback">CN</span> </div> </div>
Badge
Show me the code
<div class="flex justify-start gap"> <div class="badge">Badge</div> <div class="badge badge--secondary">Secondary</div> <div class="badge badge--outline">Outline</div> <div class="badge badge--positive">Positive</div> <div class="badge badge--negative">Negative</div> </div>
Breadcrumb
Show me the code
<a href="#">Home</a> <%= image_tag "chevron-right.svg", size: 14 %> <a href="#"><%= image_tag "ellipsis.svg", size: 14 %></a> <%= image_tag "chevron-right.svg", size: 14 %> <a href="#">Components</a> <%= image_tag "chevron-right.svg", size: 14 %> <a href="#" class="text-primary">Breadcrumb</a>
Button
Show me the code
<div class="flex flex-wrap items-center gap"> Primary Secondary Outline Plain Positive Negative <%= image_tag "circle-plus.svg", role: "presentation", size: 16 %> <span>With icon</span> <span>Please wait</span> </div>
Card
Show me the code
<div class="card flex flex-col gap"> <div class="flex flex-col gap-sm"> <h1 class="text-2xl font-semibold leading-none">Create project</h1> <p class="text-sm text-subtle">Deploy your new project in one-click.</p> </div> <div class="flex flex-col gap"> <div class="flex flex-col gap-sm"> Name </div> <div class="flex flex-col gap-sm"> Framework Select Ruby on Rails Laravel Next </div> </div> <div class="flex justify-between"> Cancel Destroy </div> </div>
Collapsible
Show me the code
<div> <div class="flex items-center justify-between gap pi-4 pb-3"> <h4 class="text-sm font-semibold"> @lazaronixon starred 3 repositories </h4> <%= image_tag "chevrons-up-down.svg", size: 16 %> <span class="sr-only">Toggle</span> </div> <div class="rounded-md border pi-4 pb-3 mbs-2 text-sm"> @rails/rails </div> <div class="rounded-md border pi-4 pb-3 mbs-2 text-sm"> @rails/jbuilder </div> <div class="rounded-md border pi-4 pb-3 mbs-2 text-sm"> @rails/jsbundling-rails </div> </div>
Dialog
Alert Dialog
Show me the code
<div> <h1 class="text-lg font-semibold">Are you absolutely sure?</h1> <p class="text-sm text-subtle mbs-2">This action cannot be undone. This will permanently delete your account and remove your data from our servers.</p> <div class="flex justify-end gap-sm mbs-4"> Cancel Continue </div> Show dialog </div>
Dismissible Dialog
Show me the code
<div> <%= image_tag "x.svg", aria: { hidden: "true" }, size: 16 %> <span class="sr-only">Close</span> <div class="flex flex-col gap"> <div class="flex flex-col gap-sm"> <h1 class="text-lg leading-none font-semibold">Edit profile</h1> <p class="text-sm text-subtle">Make changes to your profile here. Click save when you're done.</p> </div> <div class="flex flex-col mb-4 gap"> <div class="grid grid-cols-4 items-center gap"> Name </div> <div class="grid grid-cols-4 items-center gap"> Username </div> </div> <div class="flex items-center justify-end"> </div> </div> Show dialog </div>
Input
Show me the code
<%= form_with url: "/users", class: "flex flex-col gap" do |form| %> <div class="flex flex-col gap-sm"> <%= form.label :name, class: "text-sm font-medium" %> <%= form.text_field :name, class: "input" %> </div> <div class="flex flex-col gap-sm"> <%= form.label :pick_a_date, class: "text-sm font-medium" %> <%= form.date_field :pick_a_date, class: "input" %> </div> <div class="flex flex-col gap-sm"> <%= form.label :age_range, class: "text-sm font-medium" %> <%= form.select :age_range, ["0-13", "14-17", "18-23"], {}, class: "input" %> </div> <div class="flex flex-col gap-sm"> <%= form.label :comment, class: "text-sm font-medium" %> <%= form.text_area :comment, rows: 3, class: "input" %> </div> <div class="flex items-center gap-sm"> <%= form.check_box :status, class: "checkbox" %> <%= form.label :status, "Send a copy to yourself", class: "text-sm font-medium" %> </div> <% end %>
Progress
Show me the code
<span class="sr-only">Loading progress</span>
Switch
Show me the code
<div class="flex items-center gap-sm"> Airplane Mode </div>
Table
Show me the code
Invoice Status Method Amount INV001 Paid Credit Card $250.00 INV002 Pending PayPal $150.00 INV003 Unpaid Transfer $350.00 INV004 Paid Credit Card $450.00 Paid $2,500.00
More components soon…
Development
To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/lazaronixon/css-zero. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the CSS Zero project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.