Skip to content
Agents tracked: 440 Downloads (7d): 202M down 19.5% GitHub stars: 10.4M Releases (7d): 607 Agent status: 1 with issuesSince last limit reset: Claude 28d · Codex 0d Updated Oct 21, 2026

Exit animations with data-state in tw-animate-css

Exit animations play when an element is hidden. With data-state variants one element can carry both its enter and exit classes and switch between them.

All tw-animate-css examples tw-animate-css: usage and stats

Exit animations with data-state in tw-animate-css: screenshot of the example below running
The code below, running in Chromium on our server (Oct 17, 2026). Press Run to see it live and change it.

How it works

  1. Pick the base class by state. data-[state=show]:animate-in and data-[state=hide]:animate-out choose the base class from the data-state attribute. React sets that attribute from the show state. [1]
  2. Describe the exit. fade-out and slide-out-to-top-8 describe how the panel leaves, while fade-in and slide-in-from-top-8 describe how it comes back. [1]
  3. Keep the last frame. fill-mode-forwards sets animation-fill-mode to forwards, so the panel stays at the end of the exit animation instead of popping back. [1]

Run and edit it

It runs in your browser, in a sandboxed frame that cannot see this site; the packages load from esm.sh only after you press Run.

import { useState } from 'react';

export default function App() {
  const [show, setShow] = useState(true);

  return (
    <div className='flex h-[380px] flex-col items-center justify-center gap-6 bg-slate-100'>
      <button
        onClick={() => setShow(!show)}
        className='rounded-md bg-slate-900 px-4 py-2 text-sm font-medium text-white'
      >
        {show ? 'Hide panel' : 'Show panel'}
      </button>
      {/* data-state picks animate-in or animate-out */}
      <div
        data-state={show ? 'show' : 'hide'}
        className='data-[state=show]:animate-in data-[state=hide]:animate-out fade-in slide-in-from-top-8 fade-out slide-out-to-top-8 duration-500 fill-mode-forwards w-80 rounded-xl bg-white p-5 shadow-lg'
      >
        <p className='font-semibold text-slate-800'>Changes saved</p>
        <p className='mt-1 text-sm text-slate-500'>
          data-state is now <code className='font-mono'>{show ? 'show' : 'hide'}</code>.
        </p>
      </div>
    </div>
  );
}
Ctrl/⌘ + Enter runs

Free for signed-in members, with a daily limit. Describe the change in plain words; the new code runs only in your browser.

Press the button to switch data-state between show and hide. Code written by AgentGid [1].

Checked Oct 17, 2026: it starts without errors in Chromium with tw-animate-css 1.4.0, react 19.3.1, react-dom 19.3.1, tailwindcss 4.3.3. Needs WebGL.

More tw-animate-css examples

Slide-in animations in tw-animate-css Staggered delays in tw-animate-css Looping animations in tw-animate-css Enter animations in tw-animate-css

Sources

  1. tw-animate-css README (GitHub)

Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.

Building something with tw-animate-css? Ask AgentGid →