Skip to content

Sortable List Header

A copy-paste css-only interactions component in pure HTML & CSS. Zero dependencies, framework-agnostic, MIT-licensed.

CSS-Only InteractionsHTMLCSSany framework

Copy into your project

HTML
<!-- Sortable List Header — a hidden checkbox flips the flex "order"
     of each fixed row via sibling selectors, zero JS. -->
<div class="nuda-co2-sort-headers">
  <input class="nuda-co2-sort-headers__input" type="checkbox" id="co2-sort-dir"
         aria-label="Toggle sort direction for Score" />
  <label class="nuda-co2-sort-headers__head" for="co2-sort-dir">
    <span>Score</span>
    <span class="nuda-co2-sort-headers__arrow" aria-hidden="true">&#9650;</span>
  </label>
  <ul class="nuda-co2-sort-headers__rows">
    <li class="nuda-co2-sort-headers__row" data-rank="1">Nova <b>98</b></li>
    <li class="nuda-co2-sort-headers__row" data-rank="2">Atlas <b>87</b></li>
    <li class="nuda-co2-sort-headers__row" data-rank="3">Vega <b>76</b></li>
    <li class="nuda-co2-sort-headers__row" data-rank="4">Orion <b>65</b></li>
  </ul>
</div>
CSS
.nuda-co2-sort-headers {
  --nuda-co2-sh-accent: #e4ff54;
  width: 100%;
  max-width: 280px;
  font-family: inherit;
}

.nuda-co2-sort-headers__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.nuda-co2-sort-headers__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 44px;
  padding: .4rem .7rem;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: #ccc;
  background: rgba(255,255,255,.05);
  border-radius: 9px 9px 0 0;
  cursor: pointer;
}

.nuda-co2-sort-headers__head:hover {
  color: #fff;
}

.nuda-co2-sort-headers__arrow {
  display: inline-block;
  color: var(--nuda-co2-sh-accent);
  transition: transform .25s ease;
}

.nuda-co2-sort-headers__input:focus-visible~.nuda-co2-sort-headers__head {
  outline: 2px solid var(--nuda-co2-sh-accent);
  outline-offset: -2px;
}

.nuda-co2-sort-headers__rows {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid rgba(255,255,255,.08);
  border-top: none;
  border-radius: 0 0 9px 9px;
  overflow: hidden;
}

.nuda-co2-sort-headers__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  padding: .4rem .7rem;
  font-size: .74rem;
  color: #bbb;
  border-top: 1px solid rgba(255,255,255,.06);
}

.nuda-co2-sort-headers__row:first-child {
  border-top: none;
}

.nuda-co2-sort-headers__row b {
  color: #fff;
  font-weight: 700;
}

.nuda-co2-sort-headers__row[data-rank="1"] {
  order: 1;
}

.nuda-co2-sort-headers__row[data-rank="2"] {
  order: 2;
}

.nuda-co2-sort-headers__row[data-rank="3"] {
  order: 3;
}

.nuda-co2-sort-headers__row[data-rank="4"] {
  order: 4;
}

#co2-sort-dir:checked~.nuda-co2-sort-headers__head .nuda-co2-sort-headers__arrow {
  transform: rotate(180deg);
}

#co2-sort-dir:checked~.nuda-co2-sort-headers__rows .nuda-co2-sort-headers__row[data-rank="1"] {
  order: 4;
}

#co2-sort-dir:checked~.nuda-co2-sort-headers__rows .nuda-co2-sort-headers__row[data-rank="2"] {
  order: 3;
}

#co2-sort-dir:checked~.nuda-co2-sort-headers__rows .nuda-co2-sort-headers__row[data-rank="3"] {
  order: 2;
}

#co2-sort-dir:checked~.nuda-co2-sort-headers__rows .nuda-co2-sort-headers__row[data-rank="4"] {
  order: 1;
}

@media (prefers-reduced-motion:reduce) {
  .nuda-co2-sort-headers__arrow {
    transition: none;
  }
}

How to use Sortable List Header

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More css-only interactions components

← Browse all NudaUI components