Browse documentation

Reference / Variants & accessibility

First, last, and alternating children

Style items according to their DOM position or type. Odd and even select alternating siblings starting at the first child.

Working example

Place the positional class on each repeated item in your template. The browser recalculates the stripe when items are inserted or reordered.

HTML
<ul class="overflow-hidden border">
  <li class="p-2 odd:bg-neutral-100">Cover</li>
  <li class="p-2 odd:bg-neutral-100">Contents</li>
  <li class="p-2 odd:bg-neutral-100">Colophon</li>
</ul>

Class reference

ClassCSS declarations
first:rounded-tborder-top-left-radius: .375rem; border-top-right-radius: .375rem;
last:rounded-bborder-bottom-right-radius: .375rem; border-bottom-left-radius: .375rem;
odd:bg-neutral-100background-color: oklch(0.95 0 0);
even:bg-whitebackground-color: #fff;
only:font-boldfont-weight: 700;
first-of-type:mt-0margin-top: 0px;
empty:hiddendisplay: none;
View full generated CSS
Compiled CSS
.first\:rounded-t:first-child {
  border-top-left-radius: .375rem;
  border-top-right-radius: .375rem;
}
.last\:rounded-b:last-child {
  border-bottom-right-radius: .375rem;
  border-bottom-left-radius: .375rem;
}
.only\:font-bold:only-child {
  font-weight: 700;
}
.odd\:bg-neutral-100:nth-child(odd) {
  background-color: oklch(0.95 0 0);
}
.even\:bg-white:nth-child(even) {
  background-color: #fff;
}
.first-of-type\:mt-0:first-of-type {
  margin-top: 0px;
}
.empty\:hidden:empty {
  display: none;
}