Animation
Motion for React and Next.js: Framer Motion (motion/react), CSS transitions, layout animations and accessible animated UI.
- Uptime Status Bars in React and Tailwind (90-Day Status Page Strip)Render one bar per day from an array of { date, uptime } where uptime can be null for days with no data. Color by threshold, give every bar an aria-label and a keyboard-reachable tooltip, show 30 days on phones and 90 on desktop, stagger the bars in with one CSS variable, and compute the headline percentage only over days that have data.Oct 22, 2026 · 4 min
- React Order Book Component with Tailwind: Depth Bars, Spread and Flashing UpdatesKeep bids and asks as maps of price to size, group them by tick size, sort and slice the top levels, and compute cumulative totals for the depth bars. Draw each bar as an absolutely positioned span scaled with transform, show the spread between the two sides, flash a row when its size changes, and buffer WebSocket messages so React renders at most once per animation frame.Oct 22, 2026 · 3 min
- Animated Pricing Cards in Tailwind Without Framer MotionMost pricing card motion needs no library. Use @property to animate a conic gradient border on the featured plan, transform and shadow transitions for hover, a CSS keyframe with a per-card delay for the reveal (started by one IntersectionObserver or by animation-timeline: view() where supported), and stroke-dashoffset for the checkmarks. Reach for Motion when cards change layout or need exit animations.Oct 22, 2026 · 4 min
- How to Animate the shadcn Login Form Block (Next.js + Tailwind)Keep the shadcn login block as it is and add four small motions: a staggered rise on load with a Tailwind v4 keyframe and a per-row delay, a shake keyed to each failed attempt from useActionState, a pending button driven by useFormStatus, and a check that draws in on success. Put every animation behind motion-safe so reduced motion gets a static form.Oct 22, 2026 · 4 min
- Animated Toggle Switch in React and Tailwind (Accessible, No Library)Use a button with role=switch and aria-checked, style both states with Tailwind's aria-checked variants, and move the thumb with a transform and a slightly overshooting cubic-bezier. Add a hidden input so the value posts with a form, give it a visible label, and turn the motion off under prefers-reduced-motion.Oct 22, 2026 · 4 min
- Liquid Glass Tab Bar in Next.js and TailwindRender the bar once in the layout, read the route with usePathname and pass the active index to CSS as --index. Build the glass from a translucent background, backdrop-filter blur and saturate, a thin border and an inset highlight, with an opaque fallback. Slide the indicator by its own width times the index, and remount an inner span with key={index} to play a squish.Oct 21, 2026 · 5 min
- Monthly/Yearly Pricing Toggle in React and TailwindUse two sr-only radio inputs in a fieldset for Monthly and Yearly and slide a pill behind the labels. Stack both prices in one grid cell with tabular-nums and cross-fade them so the layout never moves. Work out the savings badge from your real prices, show what gets billed yearly, keep ?billing= in the URL, and pick the Stripe price on the server from a plan id and period.Oct 21, 2026 · 6 min
- Circular Progress Ring in React and TailwindDraw a faint track circle and a progress circle, set strokeDasharray to the circumference and strokeDashoffset to circumference times (1 minus value/100), and rotate the SVG -90 degrees so it starts at the top. Start the value at 0 and set it on the next frame so a CSS transition fills it. Hide the round cap at zero, put role progressbar on a wrapper and turn the transition off under reduced motion.Oct 21, 2026 · 6 min
- 3D Tilt Card With Glare in React and TailwindPut perspective on a wrapper, then on pointer move write rotateX and rotateY angles to CSS variables with style.setProperty inside requestAnimationFrame, never React state. A Tailwind class reads them, a radial gradient at the pointer adds the glare, and pointer leave resets the angles so a CSS transition eases the card flat. Skip touch input and keep the card flat under reduced motion.Oct 21, 2026 · 6 min
- Animated SVG Checkmark in React and TailwindSet pathLength={100} on an SVG path or circle, give it stroke-dasharray 100 and stroke-dashoffset 100, then transition the offset to 0 and it draws itself. Spin a quarter arc with animate-spin and transform-box: fill-box while a server action runs, then close the ring and draw the check. Put the words in a role="status" span that is always rendered, and turn the motion off under reduced motion.Oct 21, 2026 · 6 min
- Slide-Out Cart Drawer in React With Native dialogOpen a native <dialog> with showModal() from a useEffect (never pass open as a prop). You get the top layer, an inert page, Escape, and focus that comes back to the cart button. Slide it in with @starting-style. To animate the close, set data-closing, wait for getAnimations() to finish, then call close(). Close on backdrop click when e.target is the dialog, and lock page scroll with html:has().Oct 21, 2026 · 5 min
- Circular Reveal Theme Toggle in Next.js (View Transitions)Call document.startViewTransition(), toggle the dark class on <html> inside the callback (with flushSync for React state), then in transition.ready animate clipPath on ::view-transition-new(root) from circle(0px) to the farthest corner. Turn off the default fade in CSS, start from the button's center, and skip it when the API is missing or reduced motion is on.Oct 21, 2026 · 5 min
- Hide Navbar on Scroll Down in React and TailwindStore the last scrollY. In a passive scroll listener throttled with requestAnimationFrame, hide the header with -translate-y-full when the page moves down more than about 10px and show it when it moves up. Clamp scrollY for Safari's bounce, always show it near the top, keep it visible while anything inside has focus, and add scroll-padding-top so anchor links land below it.Oct 21, 2026 · 6 min
- Credit Card Input in React: Spacing, Brand and LuhnUse type="text" with inputMode="numeric" and autoComplete="cc-number". Strip non-digits, detect the brand from the first digits (Mastercard includes 2221 to 2720), group 4 4 4 4 or 4 6 5 for Amex, and keep the caret by counting digits before it, not characters. Run Luhn and the MM/YY check on blur. For real payments, let Stripe Elements collect the number.Oct 21, 2026 · 7 min
- Draggable Pull Cord Toggle in React and TailwindMake the bead a button with role="switch", grab it with setPointerCapture, and keep the pull distance in a ref written to a CSS variable each frame. On release, flip only past a threshold, then snap back with a damped spring: velocity first, then position, dt capped at 1/30 s. Add touch-action: none for phones and a click and keyboard path, because WCAG 2.5.7 says dragging can't be the only way.Oct 21, 2026 · 7 min
- Eyes That Follow the Cursor in React and TailwindCompute Math.atan2 from each eye's own centre to the cursor, clamp the pupil to a few pixels, and write the offset to CSS variables with style.setProperty once per requestAnimationFrame instead of React state. To follow the text caret, measure the text before it with canvas measureText, and fall back to value.length because selectionStart is null on type=email inputs.Oct 21, 2026 · 7 min
- Spotlight Effect in React and Tailwind With CSS MasksPut a dark overlay over your content and mask it with a radial-gradient that is transparent at var(--spot-x) var(--spot-y). Register the three variables with @property so they can transition, write them with style.setProperty inside requestAnimationFrame instead of React state, and move the spot on mouse moves and on focus so keyboard and touch users get the light too.Oct 21, 2026 · 6 min
- Skeleton Loader With Shimmer in Next.js and TailwindExport a skeleton from loading.tsx and Next.js shows it while the page streams in. Wrap each slow panel in its own Suspense so one slow query doesn't hold back the rest. Make every block the same size as the real content so nothing jumps, hide the blocks with aria-hidden, announce loading once, and turn the shimmer off with motion-reduce.Oct 21, 2026 · 6 min
- Hold to Delete Button in React and Tailwind CSSA hold to delete button needs a progress value that fills while the pointer or Space key is held and drains on release, a callback when it reaches 100%, and an undo window before the real delete. This post builds one in React and Tailwind CSS with requestAnimationFrame and no animation library, fixes touch, long-press menus and key repeat, and runs the final delete through a Next.js Server Action.Oct 21, 2026 · 7 min
- How to Animate Height Auto in React and Tailwind CSSHeight can't transition to auto because auto isn't a number. Wrap the content in a grid and transition grid-template-rows from 0fr to 1fr, with min-h-0 on the child and inert when closed. For content that grows while open, measure it with a ResizeObserver and transition a pixel height. interpolate-size: allow-keywords makes auto work directly, but not in every browser yet.Oct 21, 2026 · 6 min
- Accessible Animated Tabs in React and Tailwind CSS Without a LibraryUse role="tablist" with tab buttons, aria-selected, and panels linked by aria-controls and aria-labelledby. Only the active tab is in the tab order; arrow keys, Home and End move between tabs. Measure the active tab in useLayoutEffect to slide the indicator, and turn the transition on after the first measure. For filters like Week/Month, use buttons with aria-pressed instead.Oct 21, 2026 · 6 min
- Accessible Tooltip in React and Tailwind CSS Without a LibraryGive the bubble role="tooltip", point the trigger at it with aria-describedby, and open it on keyboard focus as well as hover. Close it on Escape without moving focus, keep a padded bridge so the mouse can move onto it, skip touch taps, and never put links inside. For icon rails, a CSS-only version with group-hover and group-focus-visible is enough.Oct 21, 2026 · 6 min
- 3D Flip Card Animation in React and Tailwind CSS (No Library)Use three layers. The parent sets perspective, the middle element rotates with transform-style: preserve-3d, and both faces stack with backface-visibility: hidden, the back pre-rotated 180deg. In Tailwind v4 that's perspective-distant, transform-3d, rotate-y-180 and backface-hidden. Add inert to the hidden face, keep overflow-hidden off the rotating element, and add motion-reduce:transition-none.Oct 21, 2026 · 6 min
- Animated SVG Line Chart in React Without a Chart Library (Draw-On Effect)Map your values into a 1000 by 300 SVG viewBox, draw one path, and set pathLength={1} so a stroke-dasharray of 1 covers the whole line. Animate stroke-dashoffset from 1 to 0 in CSS and it draws itself. Add vector-effect non-scaling-stroke, key the path on its d string to redraw on new data, a reduced motion fallback and a hidden data table for screen readers.Oct 21, 2026 · 6 min
- Animated Number Counter in React Without a Library (Count-Up and Odometer Roll)Two patterns, no library. For a count-up, ease from the old value to the new one in a requestAnimationFrame loop and return the target on first render so SSR matches. For an odometer roll, give each digit a 1em window with a 0 to 9 column and slide it with a CSS transform. Key digits from the right, use tabular-nums, pass a locale to Intl.NumberFormat, hide the strips with aria-hidden and respect reduced motion.Oct 21, 2026 · 6 min
- Liquid Glass in React and Tailwind: What Works in Chrome, Safari and FirefoxUse bg-white/10, a light border and backdrop-blur + backdrop-saturate for the frosted layer in every browser. backdrop-filter: url(#svg-filter) refraction renders only in Chromium, yet Firefox and WebKit report it as supported, so gate it with a Chromium check via useSyncExternalStore, keep blur in its own rule, and add a prefers-reduced-transparency fallback.Oct 21, 2026 · 7 min
- Cursor Rules for Consistent UI Animations: Tokens, a Rule File and a CheckPut durations and easings in CSS variables and one lib/motion.ts hook, write a .cursor/rules/motion.mdc rule with globs that names the exact classes to use, link a real example component, and run a small check script that fails on raw durations, inline curves, transition-all and animated height.Oct 21, 2026 · 6 min
- shadcn/ui Animated Components: Add Motion Without Breaking AccessibilityIn a fresh shadcn project, Dialog and Accordion kept animating with Reduce Motion on, because tw-animate-css has no reduced-motion rule. A data-slot CSS rule turns them off without breaking the focus trap. Gate Framer Motion hover props with useReducedMotion, and draw focus with outline when you animate box-shadow.Oct 21, 2026 · 6 min
- Three.js Particles That Morph Between Shapes in ReactGeometry vertices make bad particles: a 32x16 SphereGeometry has 561 vertices with one pole repeated 33 times, and a torus knot has 5,025. Sample every shape to the same count (Fibonacci sphere, MeshSurfaceSampler, canvas text), then spring each particle to the same index in the next list. Pause the loop off screen and stop it for Reduce Motion.Oct 21, 2026 · 6 min
- WebGL Shader Background in Next.js Without three.jsYou don't need three.js for a shader background. Create the canvas inside useEffect, run the animation loop only while it's on screen and the tab is visible, draw one still frame for Reduce Motion, cap devicePixelRatio, and call loseContext in cleanup. That cleanup took the Too many active WebGL contexts warning from 19 to 0 over 40 remounts.Oct 21, 2026 · 5 min
- Next.js App Router Page Transitions: Why Exit Animations Don't RunIn the App Router, the exiting copy of a page reads the new route, so AnimatePresence fades out the page you're going to. Freeze the router context for the exiting page to keep Motion, or wrap pages in React's ViewTransition on Next.js 16 and animate with CSS. template.tsx only animates pages in.Oct 21, 2026 · 6 min
- prefers-reduced-motion in React: a Hook, Tailwind and MotionHandle prefers-reduced-motion with CSS first: a media query or Tailwind's motion-safe and motion-reduce variants. Use a useSyncExternalStore hook only when JavaScript drives the animation, and wrap Motion in MotionConfig with reducedMotion set to user. Swap slides for fades instead of removing feedback.Oct 20, 2026 · 5 min
- Accessible Login Form in React: Labels, Errors, MotionAn accessible login form in React uses a visible label on every input, links each error to its field with aria-describedby, announces sign-in failures from an always-mounted live region, moves focus to the first broken field, and turns its shake animation off under prefers-reduced-motion.Oct 10, 2026 · 8 min
- Framer Motion vs CSS Animation for Micro-InteractionsUse CSS for micro-interactions between two fixed states, like hover, press and toggles; it costs no JavaScript. Use Motion (formerly Framer Motion) for exit animations, layout changes, interruptible springs and gestures. In my Next.js test the Motion route shipped 69 kB more first-load JS than the CSS one.Oct 8, 2026 · 8 min
- Animated Tabs with Framer Motion in Next.js App RouterTo animate tabs with Framer Motion (now the motion package), render only the active tab's highlight as a motion element with a shared layoutId, and Motion slides it to whichever tab mounts it next. In the Next.js App Router, keep the bar in a layout, read the route with usePathname, and mark the active link with aria-current.Oct 3, 2026 · 8 min