UI Element Gallery

Copy-paste Tailwind elements: buttons, loaders, cards, toggles. Live preview, one click to copy.

Brand Pricing

New: Component library v2

120 new blocks, dark mode included.

Explore
Navigation

Adapting Snippets to React, Next.js, and Vue

From `class` to `className`

The snippets use plain HTML class attributes. In React and Next.js, rename class to className, because class is a reserved word in JavaScript and JSX will not accept it. Self-closing tags need a trailing slash, so <input> becomes <input />, and inline event handlers move from HTML attributes to JSX props such as onClick. In Vue single-file components, class stays as it is, since Vue templates are HTML; bind dynamic classes with :class and dynamic styles with :style. The utility classes themselves need no changes in any framework, as long as the files are covered by Tailwind's content scanning.

Extract reusable props instead of hardcoding

A snippet with hardcoded colors and padding serves exactly one case. Turn the decisions that vary into props: variant for the color scheme, size for padding and type scale. Keep the shared layout classes constant, and store each variant's classes as a complete string in a lookup object, then compose the final class list from the base classes plus the lookup entries. Write every class as a full literal string. Building classes with interpolation, such as `bg-${color}-500`, defeats Tailwind's scanner: the full class name never appears literally in the source, so it is missing from the built CSS and the style silently fails. A lookup table of literal strings keeps every class detectable.

From a static snippet to a component with variants

The same pattern scales to cards, badges, alerts, and modals: constant layout classes, parameterized choices. A modal additionally needs state: accept open and onClose props, render conditionally or toggle visibility, and return focus to the trigger element when it closes. The sample below shows the full transformation for a button.

<!-- Before: raw gallery snippet in plain HTML --> <button class="rounded-lg bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700"> Save changes </button>
// After: a reusable React component with variant and size props const VARIANTS = {primary: "bg-indigo-600 text-white hover:bg-indigo-700", secondary: "bg-white text-gray-900 ring-1 ring-gray-300 hover:bg-gray-50",}; const SIZES = {sm: "px-3 py-1.5 text-sm", lg: "px-5 py-3 text-base",}; function Button({ variant = "primary", size = "sm", children, ...rest }) {return ( <button className={`rounded-lg font-medium ${VARIANTS[variant]} ${SIZES[size]}`}{...rest}>{children}</button> );}

Accessibility Wiring for Interactive Components

Show focus for keyboard users

Keyboard users navigate without a mouse, so the focus indicator is their only map of where they are on the page. Apply focus styles with the focus-visible: variant, which the browser triggers for keyboard focus but not for mouse clicks, so mouse users never see a stray ring. When replacing the browser's default outline, add the replacement in the same rule. Never remove the outline without one.

<button className="rounded-lg bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 focus-visible:ring-offset-2"> Save changes </button>

Name icon-only buttons

A button that contains only an SVG has no text for assistive technology to announce. Add an aria-label that describes the action, not the icon: Close dialog rather than X. Mark the icon itself aria-hidden="true" so it is skipped, and make sure the label matches the button's visible purpose. An alternative is visually hidden text inside the button, which serves the same role.

Toggles need switch semantics

A toggle built from a button or div carries no state information by default. Add role="switch" and mirror the current state in aria-checked, updating both attributes together on every change, so the announced state can never drift from the visual state. Where the design allows it, prefer a native checkbox styled with peer classes: the browser then manages state, keyboard interaction, and announcements with no ARIA at all. Custom switch roles are the fallback for designs a checkbox cannot express.

Respect reduced-motion preferences

Continuous spinners can cause discomfort for people with vestibular disorders, and operating systems expose a reduced-motion setting for exactly this reason. Use the motion-reduce: variant to stop or slow the animation when the preference is set. Keep the loading state itself; only the motion changes. Pair the spinner with a text alternative, such as visually hidden loading text inside a role="status" container, so the state is announced either way.

<div class="h-8 w-8 animate-spin rounded-full border-2 border-indigo-600 border-t-transparent motion-reduce:animate-none" role="status"> <span class="sr-only">Loading</span> </div>

Theming Color Tokens for Dark Mode

The `dark:` variant strategy

Two strategies exist. Media-based dark mode follows the operating system setting with no JavaScript. Class-based dark mode adds a dark class to the <html> element, which a toggle can switch at runtime. In Tailwind v3, class-based mode needs darkMode: 'class' in the configuration. In Tailwind v4, the dark: variant follows prefers-color-scheme by default, so class-based themes require a custom variant declared in CSS. Either way, the component markup stays the same; only the theme source changes. Add dark values alongside the light ones: bg-white dark:bg-gray-900, text-gray-900 dark:text-gray-100.

/* Tailwind v4: class-based dark mode needs a custom variant */ @custom-variant dark (&:where(.dark, .dark *));

One variable for the brand color

Brand colors appear across dozens of components, so define them once as CSS variables and override the values under .dark. Reference them with arbitrary values such as bg-[var(--brand)], or declare them in Tailwind v4's @theme block so the framework generates utilities from them. With the declaration below, bg-brand, text-brand, and border-brand behave like built-in color utilities and follow the active theme automatically. Changing one variable then recolors every component, with no per-class edits and no duplicated values.

:root { --brand: #4f46e5; }.dark { --brand: #818cf8; }@theme inline {--color-brand: var(--brand);}