Customization

The default UI is built to blend into your site. Start with CSS variables, add your own class names where you need more, and replace whole components when the markup itself has to change.

CSS variables

Every color, font and corner radius of the default UI comes from a --knit-* CSS variable. Override them in your own stylesheet:

customization-variables.css
/* globals.css — Knit's styles live in @layer knit, so these plain rules always win */
:root {
  --knit-font-sans: "Inter", system-ui, sans-serif;
  --knit-accent: #7c3aed;
  --knit-link: #7c3aed;
  --knit-radius: 6px;
}

/* Scope a change to one area by setting the variables on a wrapper */
.sidebar-comments {
  --knit-bg: transparent;
  --knit-border: #d4d4d8;
}

Knit puts all of its styles in the @layer knit cascade layer. Styles outside a layer always win over styles inside one, so your rules apply without raising specificity or adding !important.

Variables marked Editor are also read by the post editor (@knit/editor), so one change covers both.

Fonts

Font stacks for body text and for code, IDs and other monospaced text. Knit only names the fonts; load font files (with @font-face, Google Fonts or next/font) on your own site.

VariableDefaultDarkEditor
--knit-font-sanssystem-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serifEditor
--knit-font-monoui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospaceEditor

Surfaces and text

Background, secondary background, text, muted text and border colors. Change these first to match your site.

VariableDefaultDarkEditor
--knit-bg#ffffff#14171fEditor
--knit-bg-subtle#f9fafb#1c212cEditor
--knit-fg#111827#e5e7ebEditor
--knit-muted#6b7280#9ca3afEditor
--knit-border#e5e7eb#2a3140Editor

Accent and links

Fill and text colors of primary buttons, and the link color.

VariableDefaultDarkEditor
--knit-accent#111827#e5e7eb
--knit-accent-fg#ffffff#111827
--knit-link#2563eb#60a5faEditor

Errors and destructive actions

Error messages, delete buttons and moderation reasons.

VariableDefaultDarkEditor
--knit-danger#dc2626#f87171Editor
--knit-danger-bg#fef2f2rgba(239, 68, 68, 0.14)Editor
--knit-danger-border#fecacargba(248, 113, 113, 0.35)Editor

Highlights

Selected collections, automatic tags, and the image drop zone while a file is dragged over it.

VariableDefaultDarkEditor
--knit-info-bg#eff6ffrgba(59, 130, 246, 0.16)Editor
--knit-info-border#bfdbfergba(96, 165, 250, 0.35)
--knit-info-fg#1d4ed8#93c5fd
--knit-info-badge-bg#dbeafergba(59, 130, 246, 0.25)
--knit-info-badge-fg#1e40af#bfdbfe

Badges

The owner badge, draft badges and cards, collection badges, and the fixed part of a collection path in the editor.

VariableDefaultDarkEditor
--knit-owner-bg#dcfce7rgba(34, 197, 94, 0.16)
--knit-owner-fg#166534#86efac
--knit-locked-bg#eef2ffrgba(99, 102, 241, 0.18)
--knit-locked-border#c7d2fergba(129, 140, 248, 0.38)
--knit-locked-fg#3730a3#c7d2fe
--knit-draft-bg#fffbebrgba(245, 158, 11, 0.15)
--knit-draft-card-bg#fffdf5#1b1915
--knit-draft-border#fcd34drgba(251, 191, 36, 0.4)
--knit-draft-fg#92400e#fcd34d
--knit-badge-collection-bg#f3f4f6#232936
--knit-badge-collection-fg#374151#d1d5db

Code

Background and text colors of code blocks and inline code in posts.

VariableDefaultDarkEditor
--knit-code-bg#111827#0b0e14Editor
--knit-code-fg#f9fafb#e5e7ebEditor

Shape and overlays

Corner radius, the hover tint of icon buttons, and the backdrop behind dialogs.

VariableDefaultDarkEditor
--knit-radius10pxEditor
--knit-hover-overlayrgba(17, 24, 39, 0.05)rgba(255, 255, 255, 0.08)Editor
--knit-backdroprgba(17, 24, 39, 0.55)rgba(0, 0, 0, 0.72)

Fonts

Set --knit-font-sans and --knit-font-mono to your site's font stacks. Knit only refers to fonts by name: load the font files on your site as you normally would (with @font-face, Google Fonts or next/font). With next/font, pass the CSS variable it generates:

css
:root {
  --knit-font-sans: var(--font-inter), system-ui, sans-serif;
}

Posts don't store fonts. Writers choose meaning (headings, code, quotes), and your site decides how it looks, so changing a variable restyles every post at once.

Dark mode

Knit follows the reader's system setting by default. If your site has its own theme switch, Knit picks it up from the same markers:

  • Dark: class="dark", data-theme="dark" or data-knit-theme="dark" on <html> or on any wrapper around Knit.
  • Light: class="light", data-theme="light" or data-knit-theme="light" on <html> keeps Knit light even when the system is dark.

Use the data-knit-theme attribute when you want to switch only Knit.

The table above lists the dark values that differ from the light ones. Override them inside the same selector your site uses for its dark theme, or inside @media (prefers-color-scheme: dark) if your site follows the system setting only.

Class names

PostList, PostDetail, CommentSection and CollectionPicker accept className, which is added to the root element next to Knit's own knit-* classes. Use it for layout (width, spacing) or to target children:

css
.my-post-list .knit-post-card {
  border-radius: 0;
}

Treat the inner knit-* class names as convenient hooks rather than a stable API: they can change between minor versions. For changes that must survive upgrades, use variables or replace the component.

Replacing components

Pass your own components to KnitProvider to change markup while keeping Knit's data handling:

  • components replaces parts of the default UI: PostCard, PostEditor, MarkdownEditor, EmptyState and CommentItem.
  • markdownComponents replaces single Markdown elements (such as a, img or pre) inside posts and comments.
customization-components.tsx
"use client";

import { type KnitPostCardProps, KnitProvider } from "@knit/react";
import { PostList } from "@knit/react/ui";
import type { ComponentProps, ReactNode } from "react";

function MyPostCard({ post, postHref }: KnitPostCardProps) {
  return (
    <article className="my-post-card">
      <a href={postHref}>{post.title ?? "Untitled"}</a>
      <time dateTime={post.publishedAt ?? post.createdAt}>
        {new Date(post.publishedAt ?? post.createdAt).toLocaleDateString()}
      </time>
    </article>
  );
}

function MyLink(props: ComponentProps<"a">) {
  return <a {...props} className="my-link" target="_blank" rel="noreferrer" />;
}

export function Blog({ children }: { children?: ReactNode }) {
  return (
    <KnitProvider
      publishableKey={process.env.NEXT_PUBLIC_KNIT_PUBLISHABLE_KEY ?? ""}
      apiUrl={process.env.NEXT_PUBLIC_KNIT_API_URL ?? ""}
      // Replace whole parts of the default UI
      components={{ PostCard: MyPostCard }}
      // Replace single Markdown elements inside posts and comments
      markdownComponents={{ a: MyLink }}
    >
      <PostList space="default" className="my-post-list" />
      {children}
    </KnitProvider>
  );
}

To build the whole interface yourself, use the primitives and hooks instead of the default UI.

Strict Content Security Policy

The default UI injects a <style data-knit-styles> tag on first render. If your CSP blocks inline styles, choose one of these:

  • Pass a nonce. Give KnitProvider the same nonce as your CSP with styleNonce.
  • Load the stylesheet as a file. Import @knit/react/styles.css once and turn injection off with injectStyles={false}:
customization-csp.tsx
// app/layout.tsx — load the styles as a file instead of an injected <style> tag
import "@knit/react/styles.css";
import { KnitProvider } from "@knit/react";
import type { ReactNode } from "react";

export default function RootLayout({ children }: { children: ReactNode }) {
  return (
    <html lang="en">
      <body>
        <KnitProvider
          publishableKey={process.env.NEXT_PUBLIC_KNIT_PUBLISHABLE_KEY ?? ""}
          apiUrl={process.env.NEXT_PUBLIC_KNIT_API_URL ?? ""}
          injectStyles={false}
        >
          {children}
        </KnitProvider>
      </body>
    </html>
  );
}

Set injectStyles={false} as well when you style Knit entirely with your own CSS.