UI Best Practices
- Apply professional UI best practices to build scalable and accessible web interfaces.
Why UI Best Practices Matter More Than Effects Themselves
Borders, shadows, rings, blur, and dividers are tools, not goals.
Poor usage leads to:
Visual noise
Confusing hierarchy
Inconsistent interaction feedback
Accessibility failures
Good usage leads to:
Clear structure
Predictable interactions
Comfortable reading
Trustworthy UI
In Tailwind CSS, you’re given many low-level utilities - best practices are what turn them into a system.
Consistent UI Effects - What “Consistency” Really Means
Consistency is not about using the same class everywhere.
It’s about using the same logic everywhere.Consistency answers questions like:
When do we use borders vs shadows ?
Which shadow level means “clickable” ?
How do focus states look across components ?
How do dividers behave in lists ?
If users can predict behavior, the UI feels professional.
Establishing an Effects Hierarchy
Professional UIs follow a visual hierarchy of effects.
Example hierarchy:
Page background → no border, no shadow
Sections → background color only
Cards → light border or shadow-sm
Interactive cards → shadow-md on hover
Modals → shadow-xl
Focused inputs → ring utilities
If everything uses the same effect, nothing stands out.
Consistent Use of Borders
Best Practices
Use borders for structure, not decoration
Keep border width consistent (usually 1px)
Prefer neutral colors
Use semantic colors only for states
Rounded Border Box
Creates a container with a light border and rounded corners.
<div class="border border-gray-200 rounded-lg">
</div>
Avoid:
Different border widths everywhere
Dark borders for normal containers
Borders + shadows everywhere at once
Consistent Use of Shadows
Best Practices
Use shadows to indicate elevation
Define 2–3 shadow levels max
Increase shadow on hover for interaction
Avoid mixing many shadow sizes randomly
Consistent Shadow
Uses a small shadow that increases on hover for elevation.
<div class="shadow-sm hover:shadow-md transition-shadow">
</div>
Shadows should feel:
Predictable
Subtle
Purpose-driven
Consistent Focus & Interaction Effects
Focus styles must:
Be visible
Be consistent
Work across components
Work in light and dark mode
Recommended approach:
Use ring utilities for focus
Use the same ring color and width everywhere
Focus Ring Input
Applies a consistent blue focus ring to an input element.
<input
class="focus:ring-2 focus:ring-blue-500 focus:outline-none"
/>
Avoid:
Removing focus styles
Using different focus styles per component
Consistent Use of Dividers & Separation
Dividers should:
Separate repeated content
Be subtle
Never replace spacing
Dividers
Adds subtle vertical dividers between child elements.
<div class="divide-y divide-gray-200">
</div>
Avoid:
Heavy dividers everywhere
Dividers without padding
Using borders on every child manually
Consistent Use of Visual Effects (Blur, Opacity, Filters)
Rules to follow:
Use blur only for overlays or loading states
Use opacity for states, not hierarchy
Use brightness instead of opacity for images
Avoid stacking multiple heavy effects
If effects draw attention to themselves → they’re overused.
Accessibility is Not Optional
Accessibility is not a “nice to have”.
It is a baseline requirement.Borders & effects affect accessibility by:
Showing focus
Indicating state
Separating content
Clarifying interaction
Bad effects can make UI unusable for:
Keyboard users
Screen reader users
Low-vision users
Focus Visibility
Every interactive element must:
Show focus when tabbed to
Have sufficient contrast
Be visible in light & dark mode
Bad:
<button class="outline-none">
Correct:
<button class="focus:ring-2 focus:ring-blue-500 focus:outline-none">
Never remove focus without replacement.
Contrast & Readability
Ensure:
Borders are visible against backgrounds
Focus rings stand out
Text is never obscured by effects
Dividers don’t disappear in dark mode
Avoid:
Low-opacity text
Gray-on-gray borders
Pure black backgrounds with pure white text
Motion & Effects for Accessibility
If you use transitions or effects:
Keep them short
Avoid excessive motion
Ensure content remains readable
Effects should:
Support understanding
Not distract
Not cause discomfort
Testing for Accessibility
Before shipping:
Navigate using keyboard only
Check focus visibility everywhere
Test light & dark mode
Zoom text to 200%
View UI with effects disabled (mentally)
If UI breaks → effects are too tightly coupled to meaning.
Common Mistakes
Designing visually but not testing interaction
Overusing effects for “polish”
Removing focus outlines
Using opacity instead of color contrast
Inconsistent shadows and borders
If UI feels impressive but hard to use → accessibility was ignored.