Sub topic 3
Dividing Sibling Elements
Assume you know basic HTML and CSS and have a working Tailwind CSS project. Tailwind utilities let you style related elements without writing separate selectors.
Dividing sibling elements
The divide-* utilities add borders between direct sibling elements. They do not add a border around the group.
<ul class="divide-y divide-slate-200 rounded-lg border border-slate-200">
<li class="p-3">Profile</li>
<li class="p-3">Billing</li>
<li class="p-3">Security</li>
</ul>divide-y creates horizontal dividers. Use divide-x for vertical dividers. Add a direction such as divide-y-reverse when the visual order requires it.
Colored shadows
Choose a shadow size with shadow-sm, shadow-md, or shadow-lg. Add a color and opacity with a slash modifier:
<div class="rounded-xl bg-white p-6 shadow-lg shadow-indigo-500/30">
Highlighted panel
</div>The colored shadow is useful for emphasis, but a strong shadow can reduce visual clarity. Use it consistently across similar components.
Adding your own colors to the theme
In Tailwind CSS v3, extend the palette without removing its defaults:
// tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
brand: {
500: "#6366f1",
600: "#4f46e5",
},
},
},
},
};You can then use bg-brand-500 or border-brand-600. Tailwind CSS v4 uses @theme variables instead.
Arbitrary values for one-off styles
Square brackets support values that do not belong in the shared theme:
<div class="border border-[#1da1f2] bg-[#1da1f2]/10 shadow-[0_4px_12px_rgba(0,0,0,0.15)]">
One-off panel
</div>Prefer theme colors for repeated values. Arbitrary values are best for isolated designs.
Dark mode variants
Prefix utilities with dark: to change them in dark mode:
<div class="border border-slate-200 bg-white text-slate-900 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-100">
<h2 class="font-semibold">Project status</h2>
<p class="text-slate-600 dark:text-slate-300">All checks passed.</p>
</div>Choose a complete dark-mode set. A dark background with unchanged dark text creates poor contrast.
Contrast and accessible focus indicators
Check text against its background and keep interactive controls visibly focused. A ring replaces the browser outline only when you provide another indicator:
<input class="rounded-md border border-slate-300 px-3 py-2 focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500" />Putting it together: a card component
A consistent card might combine rounded-xl, border, shadow-md, divide-y, and dark: color variants. Test both color schemes and keyboard navigation before shipping.
Exercise
Which utility adds horizontal lines between direct child elements without adding an outer line?
Show answer
divide-y, usually combined with a utility such as divide-slate-200.