CSS Animation Pattern
Create performant CSS animations with Tailwind transitions, keyframe utilities, and motion-safe considerations
When to Use
- Adding hover/focus transitions to interactive elements
- Animating element entrance (fade in, slide up)
- Building loading spinners and skeleton screens
- Creating micro-interactions that improve UX
Instructions
- Use
transition-* utilities for property transitions (hover, focus, state changes).
- Use
animate-* utilities for keyframe animations (continuous motion, entrance effects).
- Only animate
transform and opacity for 60fps performance — avoid animating width, height, margin, or top.
- Respect user preferences: use
motion-safe: prefix so animations only play when the user has not enabled "reduce motion".
- Keep animations short (150-300ms for transitions, 500-1000ms for entrances).
- Define custom keyframes in
tailwind.config.ts for project-specific animations.
// Transitions — state-based property changes
function Button({ children }: { children: React.ReactNode }) {
return (
<button className="
bg-blue-600 text-white px-4 py-2 rounded-md
transition-all duration-200 ease-in-out
hover:bg-blue-700 hover:shadow-lg hover:-translate-y-0.5
active:translate-y-0 active:shadow-md
focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2
">
{children}
</button>
);
}
// Entrance animation with motion-safe
function FadeIn({ children }: { children: React.ReactNode }) {
return (
<div className="motion-safe:animate-fade-in motion-reduce:opacity-100">
{children}
</div>
);
}
// Built-in Tailwind animations
<div className="animate-spin h-8 w-8 border-4 border-blue-600 border-t-transparent rounded-full" />
<div className="animate-pulse bg-gray-200 h-4 rounded" />
<div className="animate-bounce text-2xl">👇</div>
// tailwind.config.ts — custom animations
const config: Config = {
theme: {
extend: {
keyframes: {
'fade-in': {
'0%': { opacity: '0', transform: 'translateY(10px)' },
'100%': { opacity: '1', transform: 'translateY(0)' },
},
'slide-in-right': {
'0%': { transform: 'translateX(100%)' },
'100%': { transform: 'translateX(0)' },
},
'scale-in': {
'0%': { opacity: '0', transform: 'scale(0.95)' },
'100%': { opacity: '1', transform: 'scale(1)' },
},
},
animation: {
'fade-in': 'fade-in 0.5s ease-out forwards',
'slide-in-right': 'slide-in-right 0.3s ease-out',
'scale-in': 'scale-in 0.2s ease-out',
},
},
},
};
Details
Performance-safe properties: The browser can animate transform and opacity on the GPU (compositor layer) without triggering layout recalculation. Animating other properties causes reflow:
| Safe (GPU) |
Unsafe (reflow) |
transform (translate, scale, rotate) |
width, height |
opacity |
margin, padding |
filter |
top, left, right, bottom |
|
border-width, font-size |
Transition utilities:
transition — all properties (color, background, border, shadow, transform, opacity)
transition-colors — only color-related properties
transition-transform — only transform
transition-opacity — only opacity
duration-* — 75, 100, 150, 200, 300, 500, 700, 1000
ease-* — linear, in, out, in-out
Motion accessibility: Always use motion-safe: for decorative animations. Users with vestibular disorders can enable "reduce motion" in their OS settings:
<div className="motion-safe:animate-fade-in motion-reduce:opacity-100">
Content appears instantly for motion-sensitive users
</div>
Staggered animations (with custom properties):
{
items.map((item, i) => (
<div
key={item.id}
className="motion-safe:animate-fade-in"
style={{ animationDelay: `${i * 100}ms` }}
>
{item.name}
</div>
));
}
Source
https://tailwindcss.com/docs/animation
Process
- Read the instructions and examples in this document.
- Apply the patterns to your implementation, adapting to your specific context.
- Verify your implementation against the details and edge cases listed above.
Harness Integration
- Type: knowledge — this skill is a reference document, not a procedural workflow.
- No tools or state — consumed as context by other skills and agents.
Success Criteria
- The patterns described in this document are applied correctly in the implementation.
- Edge cases and anti-patterns listed in this document are avoided.
1---2name: css-animation-pattern3description: CSS Animation Pattern4metadata:5 source: https://skillmd.com/skills/intense-visions/css-animation-pattern6---7# CSS Animation Pattern89> Create performant CSS animations with Tailwind transitions, keyframe utilities, and motion-safe considerations1011## When to Use1213- Adding hover/focus transitions to interactive elements14- Animating element entrance (fade in, slide up)15- Building loading spinners and skeleton screens16- Creating micro-interactions that improve UX1718## Instructions19201. Use `transition-*` utilities for property transitions (hover, focus, state changes).212. Use `animate-*` utilities for keyframe animations (continuous motion, entrance effects).223. Only animate `transform` and `opacity` for 60fps performance — avoid animating `width`, `height`, `margin`, or `top`.234. Respect user preferences: use `motion-safe:` prefix so animations only play when the user has not enabled "reduce motion".245. Keep animations short (150-300ms for transitions, 500-1000ms for entrances).256. Define custom keyframes in `tailwind.config.ts` for project-specific animations.2627```tsx28// Transitions — state-based property changes29function Button({ children }: { children: React.ReactNode }) {30 return (31 <button className="32 bg-blue-600 text-white px-4 py-2 rounded-md33 transition-all duration-200 ease-in-out34 hover:bg-blue-700 hover:shadow-lg hover:-translate-y-0.535 active:translate-y-0 active:shadow-md36 focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-237 ">38 {children}39 </button>40 );41}4243// Entrance animation with motion-safe44function FadeIn({ children }: { children: React.ReactNode }) {45 return (46 <div className="motion-safe:animate-fade-in motion-reduce:opacity-100">47 {children}48 </div>49 );50}5152// Built-in Tailwind animations53<div className="animate-spin h-8 w-8 border-4 border-blue-600 border-t-transparent rounded-full" />54<div className="animate-pulse bg-gray-200 h-4 rounded" />55<div className="animate-bounce text-2xl">👇</div>56```5758```typescript59// tailwind.config.ts — custom animations60const config: Config = {61 theme: {62 extend: {63 keyframes: {64 'fade-in': {65 '0%': { opacity: '0', transform: 'translateY(10px)' },66 '100%': { opacity: '1', transform: 'translateY(0)' },67 },68 'slide-in-right': {69 '0%': { transform: 'translateX(100%)' },70 '100%': { transform: 'translateX(0)' },71 },72 'scale-in': {73 '0%': { opacity: '0', transform: 'scale(0.95)' },74 '100%': { opacity: '1', transform: 'scale(1)' },75 },76 },77 animation: {78 'fade-in': 'fade-in 0.5s ease-out forwards',79 'slide-in-right': 'slide-in-right 0.3s ease-out',80 'scale-in': 'scale-in 0.2s ease-out',81 },82 },83 },84};85```8687## Details8889**Performance-safe properties:** The browser can animate `transform` and `opacity` on the GPU (compositor layer) without triggering layout recalculation. Animating other properties causes reflow:9091| Safe (GPU) | Unsafe (reflow) |92| -------------------------------------- | -------------------------------- |93| `transform` (translate, scale, rotate) | `width`, `height` |94| `opacity` | `margin`, `padding` |95| `filter` | `top`, `left`, `right`, `bottom` |96| | `border-width`, `font-size` |9798**Transition utilities:**99100- `transition` — all properties (color, background, border, shadow, transform, opacity)101- `transition-colors` — only color-related properties102- `transition-transform` — only transform103- `transition-opacity` — only opacity104- `duration-*` — 75, 100, 150, 200, 300, 500, 700, 1000105- `ease-*` — linear, in, out, in-out106107**Motion accessibility:** Always use `motion-safe:` for decorative animations. Users with vestibular disorders can enable "reduce motion" in their OS settings:108109```tsx110<div className="motion-safe:animate-fade-in motion-reduce:opacity-100">111 Content appears instantly for motion-sensitive users112</div>113```114115**Staggered animations** (with custom properties):116117```tsx118{119 items.map((item, i) => (120 <div121 key={item.id}122 className="motion-safe:animate-fade-in"123 style={{ animationDelay: `${i * 100}ms` }}124 >125 {item.name}126 </div>127 ));128}129```130131## Source132133https://tailwindcss.com/docs/animation134135## Process1361371. Read the instructions and examples in this document.1382. Apply the patterns to your implementation, adapting to your specific context.1393. Verify your implementation against the details and edge cases listed above.140141## Harness Integration142143- **Type:** knowledge — this skill is a reference document, not a procedural workflow.144- **No tools or state** — consumed as context by other skills and agents.145146## Success Criteria147148- The patterns described in this document are applied correctly in the implementation.149- Edge cases and anti-patterns listed in this document are avoided.