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:
/* 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.
| Variable | Default | Dark | Editor |
|---|---|---|---|
--knit-font-sans | system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif | Editor | |
--knit-font-mono | ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace | Editor |
Surfaces and text
Background, secondary background, text, muted text and border colors. Change these first to match your site.
| Variable | Default | Dark | Editor |
|---|---|---|---|
--knit-bg | #ffffff | #14171f | Editor |
--knit-bg-subtle | #f9fafb | #1c212c | Editor |
--knit-fg | #111827 | #e5e7eb | Editor |
--knit-muted | #6b7280 | #9ca3af | Editor |
--knit-border | #e5e7eb | #2a3140 | Editor |
Accent and links
Fill and text colors of primary buttons, and the link color.
| Variable | Default | Dark | Editor |
|---|---|---|---|
--knit-accent | #111827 | #e5e7eb | |
--knit-accent-fg | #ffffff | #111827 | |
--knit-link | #2563eb | #60a5fa | Editor |
Errors and destructive actions
Error messages, delete buttons and moderation reasons.
| Variable | Default | Dark | Editor |
|---|---|---|---|
--knit-danger | #dc2626 | #f87171 | Editor |
--knit-danger-bg | #fef2f2 | rgba(239, 68, 68, 0.14) | Editor |
--knit-danger-border | #fecaca | rgba(248, 113, 113, 0.35) | Editor |
Highlights
Selected collections, automatic tags, and the image drop zone while a file is dragged over it.
| Variable | Default | Dark | Editor |
|---|---|---|---|
--knit-info-bg | #eff6ff | rgba(59, 130, 246, 0.16) | Editor |
--knit-info-border | #bfdbfe | rgba(96, 165, 250, 0.35) | |
--knit-info-fg | #1d4ed8 | #93c5fd | |
--knit-info-badge-bg | #dbeafe | rgba(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.
| Variable | Default | Dark | Editor |
|---|---|---|---|
--knit-owner-bg | #dcfce7 | rgba(34, 197, 94, 0.16) | |
--knit-owner-fg | #166534 | #86efac | |
--knit-locked-bg | #eef2ff | rgba(99, 102, 241, 0.18) | |
--knit-locked-border | #c7d2fe | rgba(129, 140, 248, 0.38) | |
--knit-locked-fg | #3730a3 | #c7d2fe | |
--knit-draft-bg | #fffbeb | rgba(245, 158, 11, 0.15) | |
--knit-draft-card-bg | #fffdf5 | #1b1915 | |
--knit-draft-border | #fcd34d | rgba(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.
| Variable | Default | Dark | Editor |
|---|---|---|---|
--knit-code-bg | #111827 | #0b0e14 | Editor |
--knit-code-fg | #f9fafb | #e5e7eb | Editor |
Shape and overlays
Corner radius, the hover tint of icon buttons, and the backdrop behind dialogs.
| Variable | Default | Dark | Editor |
|---|---|---|---|
--knit-radius | 10px | Editor | |
--knit-hover-overlay | rgba(17, 24, 39, 0.05) | rgba(255, 255, 255, 0.08) | Editor |
--knit-backdrop | rgba(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:
: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"ordata-knit-theme="dark"on<html>or on any wrapper around Knit. - Light:
class="light",data-theme="light"ordata-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:
.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:
componentsreplaces parts of the default UI:PostCard,PostEditor,MarkdownEditor,EmptyStateandCommentItem.markdownComponentsreplaces single Markdown elements (such asa,imgorpre) inside posts and comments.
"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
KnitProviderthe same nonce as your CSP withstyleNonce. - Load the stylesheet as a file. Import
@knit/react/styles.cssonce and turn injection off withinjectStyles={false}:
// 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.