CSS Zero

An opinionated CSS starter kit for your 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 badge button card 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

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

alert

Show me the code

<div class="alert alert--negative flex items-start gap">
  &lt;%= image_tag("circle-alert.svg", role: "presentation", size: 16) %&gt;
  <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>

Badge

image

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>

Button

button

Show me the code

<div class="flex flex-wrap items-center gap">
  Primary
  Secondary
  Outline
  Plain
  Positive
  Negative


    &lt;%= image_tag "circle-plus.svg", role: "presentation", size: 16 %&gt;
    <span>With icon</span>



    <span>Please wait</span>

</div>

Card

image

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>

Dialog

Alert 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

dismissible_dialog

Show me the code

<div>



        &lt;%= image_tag "x.svg", aria: { hidden: "true" }, size: 16 %&gt;
        <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

input

Show me the code

&lt;%= form_with url: "/users", class: "flex flex-col gap" do |form| %&gt;
  <div class="flex flex-col gap-sm">
    &lt;%= form.label :name, class: "text-sm font-medium" %&gt;
    &lt;%= form.text_field :name, class: "input" %&gt;
  </div>

  <div class="flex flex-col gap-sm">
    &lt;%= form.label :pick_a_date, class: "text-sm font-medium" %&gt;
    &lt;%= form.date_field :pick_a_date, class: "input" %&gt;
  </div>

  <div class="flex flex-col gap-sm">
    &lt;%= form.label :age_range, class: "text-sm font-medium" %&gt;
    &lt;%= form.select :age_range, ["0-13", "14-17", "18-23"], {}, class: "input" %&gt;
  </div>

  <div class="flex flex-col gap-sm">
    &lt;%= form.label :comment, class: "text-sm font-medium" %&gt;
    &lt;%= form.text_area :comment, rows: 3, class: "input" %&gt;
  </div>

  <div class="flex items-center gap-sm">
    &lt;%= form.check_box :status, class: "checkbox" %&gt;
    &lt;%= form.label :status, "Send a copy to yourself", class: "text-sm font-medium" %&gt;
  </div>
&lt;% end %&gt;

Progress

progress

Show me the code

  <span class="sr-only">Loading progress</span>


Switch

image

Show me the code

<div class="flex items-center gap-sm">

  Airplane Mode
</div>

Table

image

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



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.