Skip to content

Themes ​

Themes are semantic design tokens — colors, fonts, font sizes, and spacing scales — that can be referenced from your style rules via the $category.key syntax. They decouple what styles you define from what colors and fonts you use. Theme typography also supplies native Word defaults, so unstyled text and plugins inherit the document font automatically.

What is a Theme? ​

A DocxTheme is a bag of design tokens:

ts
interface DocxTheme {
  id?: string
  name?: string
  colors?: Record<string, string> // palette
  fonts?: Record<string, string> // font stacks
  fontSize?: Record<string, number> // scale (pt)
  spacing?: Record<string, number> // scale (pt)
}

Why use a theme?

  • Switch the entire look of a document by changing one field
  • Keep colors consistent across many documents
  • Reuse token names like primary, accent, success semantically
  • Pair with presets for a complete starting config

Built-in Themes ​

docx-kit ships with 3 built-in themes:

ThemeIDPaletteBest ForFonts
minimalThememinimalClean grayscale + blue accentGeneral business docsCalibri
oceanThemeoceanNavy / teal with pale gray surfacesReports, articlesCambria / Calibri
warmThemewarmWarm gray / brownCorrespondence, essaysGeorgia

Helpers:

ts
import {
  useTheme,
  THEME_LIST,
  minimalTheme,
  oceanTheme,
  warmTheme,
} from 'docx-kit'

// All three are exported by name:
const ocean = oceanTheme
const minimal = minimalTheme
const warm = warmTheme

// Or look up by ID:
const found = useTheme('ocean') // returns DocxTheme | undefined

// Or iterate all built-ins:
for (const t of THEME_LIST) {
  console.log(t.id, t.name)
}
// minimal  ocean  warm

Using a Theme ​

Pass the theme into createDocx():

ts
import { createDocx, defineStyles, useTheme } from 'docx-kit'

const doc = createDocx({
  theme: useTheme('ocean'),
  styles: defineStyles({
    title: {
      color: '$colors.primary',
      fontFamily: '$fonts.heading',
      fontSize: '$fontSize.xl',
      marginBottom: '$spacing.lg',
    },
  }),
})

doc.h1('Annual Report 2026', { className: 'title' })

Any literal string starting with $ in a style rule is treated as a token reference and resolved at compile time.

Token Categories ​

$colors.* — Palette ​

Each built-in theme provides 12 semantic color tokens:

TokenPurposeminimaloceanwarm
primaryHeadings, primary text#111827#0f172a#44403c
secondarySecondary text#374151#1e293b#57534e
accentHighlight / link color#2563eb#0d9488#8b5e34
successSuccess state#2e7d32#14765c#15803d
warningWarning state#9a6700#946200#a34c13
dangerError state#b91c1c#e11d48#b91c1c
infoInfo state#245a96#24758a#6b6578
mutedMuted text#6b7280#64748b#78716c
backgroundPage background#ffffff#ffffff#ffffff
surfaceCard / panel surface#f9fafb#f0f5f7#f6f3ee
textBody text#1f2937#1e293b#292524
borderBorder color#e5e7eb#cbd9df#ddd6ca

$fonts.* — Font Stacks ​

Each built-in theme provides body, heading, and code fonts, plus separate bodyEastAsia and headingEastAsia fonts for Chinese, Japanese, and Korean text. Word accepts one font per script; CSS fallback stacks are reduced to their first family.

Tokenminimaloceanwarm
headingCalibriCambriaGeorgia
bodyCalibriCalibriGeorgia
codeConsolasConsolasConsolas

bodyEastAsia and headingEastAsia use Microsoft YaHei in Minimal and Ocean. Warm pairs SimSun body text with SimHei headings. These are Word font names; the application opening the document chooses a substitute when a font is absent.

$fontSize.* — Type Scale ​

Each built-in theme provides a 5-step scale (values in pt):

Tokenminimaloceanwarm
xs888
sm91010
base111212
lg141615
xl242624

$spacing.* — Spacing Scale ​

Values in pt. Use with margin*, padding*, borderWidth etc.:

Tokenminimaloceanwarm
xs454
sm8109
md161816
lg242826
xl323634

Custom Theme ​

Define your own theme by passing a DocxTheme object to createDocx():

ts
import { createDocx, defineStyles, type DocxTheme } from 'docx-kit'

const brand: DocxTheme = {
  id: 'brand-2026',
  name: 'Brand 2026',
  colors: {
    primary: '#1a56db',
    accent: '#f59e0b',
    danger: '#dc2626',
    success: '#16a34a',
    text: '#1f2937',
    muted: '#6b7280',
    background: '#ffffff',
    surface: '#f3f4f6',
    border: '#e5e7eb',
  },
  fonts: {
    heading: 'Poppins, Arial, sans-serif',
    body: 'Inter, Arial, sans-serif',
    code: 'JetBrains Mono, monospace',
  },
  fontSize: {
    xs: 8,
    sm: 10,
    base: 11,
    lg: 14,
    xl: 18,
  },
  spacing: {
    xs: 4,
    sm: 8,
    md: 16,
    lg: 24,
    xl: 32,
  },
}

const doc = createDocx({
  theme: brand,
  styles: defineStyles({
    title: {
      color: '$colors.primary',
      fontFamily: '$fonts.heading',
      fontSize: '$fontSize.xl',
      marginBottom: '$spacing.lg',
    },
    body: {
      color: '$colors.text',
      fontFamily: '$fonts.body',
      fontSize: '$fontSize.base',
    },
  }),
})

Token Reference Syntax ​

Reference any token in any style-rule field:

ts
defineStyles({
  card: {
    color: '$colors.text', // → '#1f2937'
    backgroundColor: '$colors.surface',
    fontFamily: '$fonts.body',
    fontSize: '$fontSize.base',
    margin: '$spacing.md', // shorthand — sets all sides
    border: {
      color: '$colors.border',
      style: 'single',
      width: 1,
    },
  },
  calloutSuccess: {
    color: '$colors.success',
    backgroundColor: '$colors.surface',
    borderColor: '$colors.success',
  },
})

Combining with Presets ​

Presets define concrete style rules; themes define tokens. Pair them when you want a preset's typography combined with a theme's palette. The modern preset uses primary and accent color tokens; classic and academic headings stay black. Preset font sizes, body fonts, and spacing take precedence over theme defaults.

ts
import { createDocx, modernPreset, useTheme, defineStyles } from 'docx-kit'

const doc = createDocx({
  ...modernPreset.config,
  theme: useTheme('ocean'),
  styles: {
    ...modernPreset.config.styles,
    // Use theme tokens for an extra layer
    highlight: {
      color: '$colors.accent',
      backgroundColor: '$colors.surface',
    },
  },
})

Preview common Word layouts ​

Theme Studio offers business report, Chinese formal, and academic layouts. Each layout includes representative content and styled tables. The studio explicitly binds the layout's fonts, main type sizes, and heading spacing to the editable theme tokens; the Export theme drawer includes that configuration. Use Download Word to save the same file shown in the preview. The preview preserves the exported page margins; installed fonts and the Word layout engine may still differ from browser rendering.

Next Steps ​

Released under the MIT License.