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
- Cover
- Contents
- Colophon
Place the positional class on each repeated item in your template. The browser recalculates the stripe when items are inserted or reordered.
<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
| Class | CSS declarations |
|---|---|
first:rounded-t | border-top-left-radius: .375rem;
border-top-right-radius: .375rem; |
last:rounded-b | border-bottom-right-radius: .375rem;
border-bottom-left-radius: .375rem; |
odd:bg-neutral-100 | background-color: oklch(0.95 0 0); |
even:bg-white | background-color: #fff; |
only:font-bold | font-weight: 700; |
first-of-type:mt-0 | margin-top: 0px; |
empty:hidden | display: none; |
View full generated 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;
}