Skip to content

Next.js

Set up a Next.js project by hand, then add components one at a time: each component's page lists the packages to install and the files to copy into your project, under Manual installation.

The CK-UI CLI does this setup for you (with Tailwind CSS v3 or v4) and adds components with one command. Use one method or the other in a project: the CLI keeps its components in components/ck-ui, this guide in components/ui.

# Prerequisites

  • Node.js 18.18 or later (required by Next.js 15)
  • A Next.js 15 project with the App Router, React 19 and TypeScript. These steps were tested with Next.js 15.2.8 and React 19.
  • Tailwind CSS 3.4. The configuration below is for Tailwind CSS v3 and does not work with Tailwind CSS v4.

# Create New Project

If you don't have a project yet, create one with a src directory and the @/* import alias, which the components use. It is created without Tailwind CSS because the next step adds Tailwind CSS v3:

Terminal
npx create-next-app@15.2.8 my-app --ts --app --src-dir --eslint --no-tailwind --import-alias "@/*"
cd my-app

For other options, see the official Next.js documentation(opens in a new tab).

# Setup UI Config

1

Install Dependencies

clsx and tailwind-merge power the cn() helper, next-themes switches between light and dark mode, and react-icons provides the Remix icons that many components and examples use:

Terminal
npm install clsx@2 tailwind-merge@2 next-themes@0.4 react-icons@5

Tailwind CSS v3, PostCSS and the two Tailwind plugins the components rely on:

Terminal
npm install -D tailwindcss@3 postcss@8 autoprefixer@10 @tailwindcss/forms@0.5 tailwindcss-animate@1

Components can need more packages (for example Radix UI primitives). Each component's page lists them.

2

Configure PostCSS

Create postcss.config.mjs in the project root:

postcss.config.mjs
const config = {
    plugins: {
        tailwindcss: {},
        autoprefixer: {},
    },
};

export default config;
3

Configure Tailwind CSS

Create tailwind.config.ts in the project root. It adds CK-UI's colour tokens, type scale, radii, shadows, layers and dark mode:

tailwind.config.ts
import type { Config } from "tailwindcss";
import forms from "@tailwindcss/forms";
import animate from "tailwindcss-animate";
import plugin from "tailwindcss/plugin";

// Colours are CSS variables holding RGB channels (see globals.css), so opacity modifiers such as bg-primary/10 work.
const token = (name: string) => `rgb(var(--${name}) / <alpha-value>)`;

const config: Config = {
    // `dark:` applies under a `.dark` ancestor unless a `.light` boundary (ThemeScope) sits in between. Needs Tailwind CSS 3.4.1 or later.
    darkMode: ["variant", ":is(.dark &):not(:where(.dark .light *))"],
    content: ["./src/**/*.{js,ts,jsx,tsx,mdx}"],
    theme: {
        extend: {
            colors: {
                background: token("background"),
                foreground: token("foreground"),
                surface: { DEFAULT: token("surface"), foreground: token("surface-foreground") },
                muted: { DEFAULT: token("muted"), foreground: token("muted-foreground") },
                accent: { DEFAULT: token("accent"), foreground: token("accent-foreground") },
                border: token("border"),
                input: token("input"),
                ring: token("ring"),
                overlay: "rgb(var(--overlay) / var(--overlay-opacity))",
                primary: {
                    DEFAULT: token("primary"),
                    hover: token("primary-hover"),
                    foreground: token("primary-foreground"),
                    subtle: token("primary-subtle"),
                    border: token("primary-border"),
                    strong: token("primary-strong"),
                },
                secondary: { DEFAULT: token("secondary"), hover: token("secondary-hover"), foreground: token("secondary-foreground") },
                destructive: {
                    DEFAULT: token("destructive"),
                    hover: token("destructive-hover"),
                    foreground: token("destructive-foreground"),
                    subtle: token("destructive-subtle"),
                    border: token("destructive-border"),
                    strong: token("destructive-strong"),
                },
                success: {
                    DEFAULT: token("success"),
                    hover: token("success-hover"),
                    foreground: token("success-foreground"),
                    subtle: token("success-subtle"),
                    border: token("success-border"),
                    strong: token("success-strong"),
                },
                warning: {
                    DEFAULT: token("warning"),
                    foreground: token("warning-foreground"),
                    subtle: token("warning-subtle"),
                    border: token("warning-border"),
                    strong: token("warning-strong"),
                },
                info: { DEFAULT: token("info"), foreground: token("info-foreground"), subtle: token("info-subtle"), border: token("info-border"), strong: token("info-strong") },
            },
            ringColor: { DEFAULT: token("ring") },
            ringOffsetColor: { DEFAULT: "rgb(var(--background))" },
            zIndex: { sticky: "40", drawer: "50", modal: "50", command: "50", dropdown: "60", popover: "60", tooltip: "70", toast: "80" },
            transitionDuration: { fast: "150ms", base: "200ms", slow: "300ms" },
            transitionTimingFunction: { standard: "cubic-bezier(0.2, 0, 0, 1)" },
            fontFamily: { sans: ["var(--font-inter)", "sans-serif"] },
            borderRadius: { 10: "10px", 20: "20px" },
            boxShadow: {
                "x-small": "0px 1px 2px 0px rgba(10, 13, 20, 0.03)",
                regular: "0px 2px 4px 0px rgba(27, 28, 29, 0.04)",
                medium: "0px 16px 32px -12px rgba(14, 18, 27, 0.10)",
            },
            keyframes: {
                "accordion-down": { from: { height: "0" }, to: { height: "var(--radix-accordion-content-height)" } },
                "accordion-up": { from: { height: "var(--radix-accordion-content-height)" }, to: { height: "0" } },
                "progress-indeterminate": { from: { transform: "translateX(-100%)" }, to: { transform: "translateX(250%)" } },
            },
            animation: {
                "accordion-down": "accordion-down 0.2s ease-out",
                "accordion-up": "accordion-up 0.2s ease-out",
                "progress-indeterminate": "progress-indeterminate 1.4s cubic-bezier(0.65, 0, 0.35, 1) infinite",
            },
            padding: { 2.5: "10px" },
        },
    },
    plugins: [
        forms,
        animate,
        // CK-UI type scale: size-h1 … size-h6, size-p-*, size-label-*, size-subheading-*.
        plugin(({ addUtilities }) => {
            addUtilities({
                ".size-h1": { fontSize: "56px", lineHeight: "64px", letterSpacing: "-0.01em", fontWeight: "600" },
                ".size-h2": { fontSize: "48px", lineHeight: "56px", letterSpacing: "-0.01em", fontWeight: "500" },
                ".size-h3": { fontSize: "40px", lineHeight: "48px", letterSpacing: "-0.01em", fontWeight: "500" },
                ".size-h4": { fontSize: "32px", lineHeight: "40px", letterSpacing: "-0.005em", fontWeight: "500" },
                ".size-h5": { fontSize: "24px", lineHeight: "32px", letterSpacing: "0", fontWeight: "500" },
                ".size-h6": { fontSize: "20px", lineHeight: "28px", letterSpacing: "-0.005em", fontWeight: "500" },
                ".size-p-xl": { fontSize: "24px", lineHeight: "32px", letterSpacing: "-0.015em", fontWeight: "400" },
                ".size-p-lg": { fontSize: "18px", lineHeight: "24px", letterSpacing: "-0.015em", fontWeight: "400" },
                ".size-p-md": { fontSize: "16px", lineHeight: "24px", letterSpacing: "-0.011em", fontWeight: "400" },
                ".size-p-sm": { fontSize: "14px", lineHeight: "20px", letterSpacing: "-0.006em", fontWeight: "400" },
                ".size-p-xs": { fontSize: "12px", lineHeight: "16px", letterSpacing: "0", fontWeight: "400" },
                ".size-label-xl": { fontSize: "24px", lineHeight: "32px", letterSpacing: "-0.015em", fontWeight: "500" },
                ".size-label-lg": { fontSize: "18px", lineHeight: "24px", letterSpacing: "-0.015em", fontWeight: "500" },
                ".size-label-md": { fontSize: "16px", lineHeight: "24px", letterSpacing: "-0.011em", fontWeight: "500" },
                ".size-label-sm": { fontSize: "14px", lineHeight: "20px", letterSpacing: "-0.006em", fontWeight: "500" },
                ".size-label-xs": { fontSize: "12px", lineHeight: "16px", letterSpacing: "0", fontWeight: "500" },
                ".size-subheading-xl": { fontSize: "16px", lineHeight: "24px", letterSpacing: "0.06em", fontWeight: "500" },
                ".size-subheading-lg": { fontSize: "14px", lineHeight: "20px", letterSpacing: "0.06em", fontWeight: "500" },
                ".size-subheading-md": { fontSize: "14px", lineHeight: "20px", letterSpacing: "0.06em", fontWeight: "500" },
                ".size-subheading-sm": { fontSize: "12px", lineHeight: "16px", letterSpacing: "0.04em", fontWeight: "500" },
                ".size-subheading-xs": { fontSize: "12px", lineHeight: "16px", letterSpacing: "0.04em", fontWeight: "500" },
                ".size-subheading-2xs": { fontSize: "11px", lineHeight: "12px", letterSpacing: "0.02em", fontWeight: "500" },
                ".size-docs-label": { fontSize: "18px", lineHeight: "32px", letterSpacing: "-0.015em", fontWeight: "500" },
                ".size-docs-p": { fontSize: "18px", lineHeight: "32px", letterSpacing: "-0.015em", fontWeight: "400" },
            });
        }),
    ],
};

export default config;
4

Add Global Styles

Replace the contents of src/app/globals.css. It defines the colour tokens for light and dark mode and the focus styles:

src/app/globals.css
@tailwind base;
@tailwind components;
@tailwind utilities;

/* CK-UI design tokens. Values are RGB channels so Tailwind opacity modifiers work (e.g. bg-primary/10). */
@layer base {
    /* `.light` and `.dark` also work below <html>: a ThemeScope boundary redefines the tokens for its subtree. */
    .light,
    :root {
        color-scheme: light;
        --background: 255 255 255;
        --foreground: 10 10 10;
        --surface: 255 255 255;
        --surface-foreground: 10 10 10;
        --muted: 245 245 245;
        /* Slightly darker than neutral-500 so muted text meets WCAG AA (4.5:1) on both background and muted. */
        --muted-foreground: 107 107 107;
        /* Highlight for hovered/selected items inside surfaces (menus, listboxes, palettes). */
        --accent: 245 245 245;
        --accent-foreground: 10 10 10;
        --border: 229 229 229;
        --input: 229 229 229;
        /* Keyboard focus ring: neutral, like CK-UI's original focus halos (not the brand blue). neutral-500 keeps
           at least 3:1 against the background, muted and subtle surfaces (WCAG 1.4.11). */
        --ring: 115 115 115;

        /* blue-600: white text on it is 5.17:1 (blue-500 was 3.68:1). */
        --primary: 37 99 235;
        --primary-hover: 29 78 216;
        --primary-foreground: 255 255 255;
        --primary-subtle: 239 246 255;
        --primary-border: 191 219 254;
        --primary-strong: 37 99 235;

        --secondary: 23 23 23;
        --secondary-hover: 38 38 38;
        --secondary-foreground: 255 255 255;

        --destructive: 220 38 38;
        --destructive-hover: 185 28 28;
        --destructive-foreground: 255 255 255;
        --destructive-subtle: 254 242 242;
        --destructive-border: 254 202 202;
        --destructive-strong: 185 28 28;

        /* green-700: white text on it is 5.02:1 (green-500 was 2.28:1). */
        --success: 21 128 61;
        --success-hover: 22 101 52;
        --success-foreground: 255 255 255;
        --success-subtle: 240 253 244;
        --success-border: 187 247 208;
        --success-strong: 21 128 61;

        --warning: 234 179 8;
        --warning-foreground: 10 10 10;
        --warning-subtle: 254 252 232;
        --warning-border: 254 240 138;
        --warning-strong: 161 98 7;

        --info: 37 99 235;
        --info-foreground: 255 255 255;
        --info-subtle: 239 246 255;
        --info-border: 191 219 254;
        --info-strong: 29 78 216;

        /* Backdrop behind modal layers (Modal, AlertDialog, Drawer, CommandPalette). */
        --overlay: 163 163 163;
        --overlay-opacity: 0.5;
    }

    .dark {
        color-scheme: dark;
        --background: 10 10 10;
        --foreground: 250 250 250;
        --surface: 23 23 23;
        --surface-foreground: 250 250 250;
        --muted: 23 23 23;
        --muted-foreground: 163 163 163;
        --accent: 38 38 38;
        --accent-foreground: 250 250 250;
        --border: 64 64 64;
        --input: 64 64 64;
        --ring: 163 163 163;

        --primary: 37 99 235;
        --primary-hover: 29 78 216;
        --primary-foreground: 255 255 255;
        --primary-subtle: 23 37 84;
        --primary-border: 29 78 216;
        --primary-strong: 96 165 250;

        --secondary: 23 23 23;
        --secondary-hover: 38 38 38;
        --secondary-foreground: 250 250 250;

        --destructive: 220 38 38;
        --destructive-hover: 185 28 28;
        --destructive-foreground: 255 255 255;
        --destructive-subtle: 69 10 10;
        --destructive-border: 185 28 28;
        --destructive-strong: 248 113 113;

        --success: 21 128 61;
        --success-hover: 22 101 52;
        --success-foreground: 255 255 255;
        --success-subtle: 5 46 22;
        --success-border: 21 128 61;
        --success-strong: 74 222 128;

        --warning: 234 179 8;
        --warning-foreground: 10 10 10;
        --warning-subtle: 66 32 6;
        --warning-border: 161 98 7;
        --warning-strong: 250 204 21;

        --info: 37 99 235;
        --info-foreground: 255 255 255;
        --info-subtle: 23 37 84;
        --info-border: 29 78 216;
        --info-strong: 96 165 250;

        --overlay: 38 38 38;
        --overlay-opacity: 0.8;
    }

    body {
        @apply bg-background text-foreground;
    }

    /* Reduced motion: keep state changes, drop movement. */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
            scroll-behavior: auto !important;
        }
    }
}

/* CK-UI focus styles: keyboard focus rings for controls, and the field focus halo for inputs. */
@layer utilities {
    .focus-ring {
        @apply focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background;
    }

    /* For controls inside clipped containers (tabs, menus, list items). */
    .focus-ring-inset {
        @apply focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring;
    }

    /*
     * Field focus (Input, Textarea, Select, Combobox, DatePicker, OTP slots): the component turns its border strong
     * on focus and sets the halo colour; these add the soft 2px halo 2px outside the border.
     */
    .field-focus {
        @apply outline outline-0 outline-offset-2 focus:outline-2;
    }

    /* The same treatment on a composite field's root (Input.Root) while its input has focus. */
    .field-focus-within {
        @apply outline outline-0 outline-offset-2 has-[input:focus]:outline-2;
    }
}
5

Setup Utility Functions

Create src/lib/utils.ts. Every component imports cn() from it to merge class names:

src/lib/utils.ts
import { type ClassValue, clsx } from "clsx";
import { extendTailwindMerge } from "tailwind-merge";

// CK-UI typography utilities (tailwind.config.ts plugin). Registered as one class group so a
// consumer's `size-h1` replaces a component's `size-h4` instead of both being kept.
const TYPOGRAPHY_STEPS = [
    "h1",
    "h2",
    "h3",
    "h4",
    "h5",
    "h6",
    "p-xl",
    "p-lg",
    "p-md",
    "p-sm",
    "p-xs",
    "label-xl",
    "label-lg",
    "label-md",
    "label-sm",
    "label-xs",
    "subheading-xl",
    "subheading-lg",
    "subheading-md",
    "subheading-sm",
    "subheading-xs",
    "subheading-2xs",
    "docs-label",
    "docs-p",
];

const twMerge = extendTailwindMerge<"ck-typography">({
    extend: {
        // rounded-10 / rounded-20 (tailwind.config.ts) are radii, so a later rounded-lg replaces them and vice versa.
        theme: { borderRadius: ["10", "20"] },
        classGroups: {
            "ck-typography": [{ size: TYPOGRAPHY_STEPS }],
        },
    },
});

export function cn(...inputs: ClassValue[]) {
    return twMerge(clsx(inputs));
}
6

Theme Provider and Layout

1. Create the theme provider:

src/components/theme-provider.tsx
"use client";

import { ThemeProvider as NextThemesProvider, type ThemeProviderProps } from "next-themes";

export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
    return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
}

2. Use it in your root layout, with the Inter font the components are designed with:

src/app/layout.tsx
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import { ThemeProvider } from "@/components/theme-provider";
import "./globals.css";

const inter = Inter({ subsets: ["latin"], variable: "--font-inter" });

export const metadata: Metadata = {
    title: "My app",
};

export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
    return (
        <html lang="en" suppressHydrationWarning>
            <body className={`${inter.variable} font-sans antialiased`}>
                <ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
                    {children}
                </ThemeProvider>
            </body>
        </html>
    );
}

# Verification

Add your first component: follow the steps on the Button page (install its packages and copy src/components/ui/Button.tsx), then use it in a page:

src/app/page.tsx
import * as Button from "@/components/ui/Button";

export default function Home() {
    return (
        <main className="flex min-h-screen items-center justify-center gap-3 p-8">
            <Button.Root>Primary</Button.Root>
            <Button.Root variant="stroke" color="neutral">
                Secondary
            </Button.Root>
        </main>
    );
}

Run npm run dev. If the blue and outlined buttons render with rounded corners and a visible focus ring when you tab to them, the setup is complete.

# What's Next?

  • Browse the component library and add components from their pages. Each page's Manual installation lists its packages, the CK-UI files it needs and the component source.
  • Examples on a component page can use other components, such as a Button that opens a Modal. Add those from their own pages.
  • Some examples (Avatar, Tag and Navbar) show sample photos from this site's /assets folder. Replace those image paths with your own; the components themselves need no images.
  • Adjust the colour tokens in globals.css to change the palette.
Need Help?

If a step doesn't work for you, contact us.