Overview
Thelum-loading utility creates a smooth, animated loading spinner using pure CSS.
CSS Implementation
Usage
Applied Classes
Thelum-loading utility applies the following Tailwind classes:
animate-spin- Rotates the element 360 degrees continuouslyborder-transparent- Makes all borders transparent by defaultborder-l-current- Left border uses current text colorborder-t-current- Top border uses current text colorborder-3- 3px border widthrounded-full- Circular shape
How It Works
The spinner works by:- Creating a circular element with
rounded-full - Setting all borders to transparent
- Making the left and top borders visible using the current text color
- Continuously rotating the element with
animate-spin
Customization
Size
Control the spinner size with width and height utilities:Color
Change the spinner color using text color utilities (since it usescurrentColor):
Border Width
Adjust the thickness of the spinner:Animation Speed
Customize the rotation speed:Usage Examples
Loading States in Components
Conditional Rendering
Example pattern for showing/hiding the spinner based on loading state:Accessibility
When using loading spinners, always consider accessibility:
- Add
aria-labeloraria-labelledbyto describe what’s loading - Use
role="status"oraria-live="polite"for screen reader announcements - Disable interactive elements during loading
- Provide text alternatives for the loading state
Best Practices
- Always disable interactive elements (buttons, inputs) while loading
- Provide text feedback alongside the spinner when possible
- Use appropriate sizes: small spinners (w-4/w-5) for buttons, larger (w-8+) for page loading
- Match the spinner color to your action (blue for primary, red for destructive, etc.)
- Consider using
backdrop-blurfor overlay loading states - Add
aria-labelor alternative text for screen readers - Use
motion-safe:variants if you want to respect reduced-motion preferences - Don’t use multiple large spinners on the same page
- Provide loading progress percentage when possible
- Show estimated time for long-running operations