Getting Started

Installation

Installation

Install the package with your package manager:

shell
pnpm add @tanstack/highlight
shell
npm install @tanstack/highlight
shell
yarn add @tanstack/highlight
shell
bun add @tanstack/highlight

Requirements

  • Node.js 18 or newer for server-side rendering and build tooling
  • An ESM-capable runtime or bundler
  • No framework peer dependency

The package is ESM-only and has no runtime dependencies.

Entry points

ImportPurposePulls all languages?
@tanstack/highlightConvenient preconfigured APIYes
@tanstack/highlight/coreRegistry and renderer primitivesNo
@tanstack/highlight/languages/<name>One language definitionNo
@tanstack/highlight/languagesAggregate language exportsRelies on tree shaking
@tanstack/highlight/themeTheme CSS helpersNo
@tanstack/highlight/themes/<name>One theme objectNo
@tanstack/highlight/markdownFence metadata and HAST helpersNo
@tanstack/highlight/remarkRemark adapterNo
@tanstack/highlight/rehypeRehype adapterNo
@tanstack/highlight/reactReact-oriented data helperNo React dependency
@tanstack/highlight/octaneOctane component and MDX helpersNo Octane dependency

Documentation sites should normally use the selective core:

ts
import { createHighlighter } from '@tanstack/highlight/core'
import { css } from '@tanstack/highlight/languages/css'
import { tsx } from '@tanstack/highlight/languages/tsx'

export const highlighter = createHighlighter({
  languages: [css, tsx],
})

The root entry is useful for prototypes, server-only scripts, or sites where the roughly 8 KB gzip all-language build is acceptable:

ts
import { highlight } from '@tanstack/highlight'

TypeScript

Declarations ship with every public entry. No @types package is required.

Content Security Policy

The renderer does not inject scripts or inline color styles. Theme CSS can be generated at build time and placed in your normal stylesheet. Code text and decoration attribute values are escaped before rendering.