TanStack Highlight is a tiny, synchronous syntax highlighter designed specifically for blogs and documentation.
It occupies the space between minimal JavaScript-only scanners and full grammar engines:
A documentation site may need TypeScript, markup, shell commands, and configuration files in the same page. TanStack Highlight lets you register that mix of languages, render code during SSR, and highlight new samples in the browser with the same synchronous API.
Its tokenizers target common, valid documentation samples. They do not provide automatic language detection, editor state, semantic language-service tokens, or TextMate compatibility. See Comparison if you need those capabilities.
The @tanstack/highlight/core entry contains no shipped languages. Every language is an isolated LanguageDefinition under @tanstack/highlight/languages/*.
There is no WebAssembly, worker, filesystem dependency, or asynchronous initialization. A highlighter created from the same registrations and options returns the same result in Node.js and the browser.
Highlighting emits stable th-* classes instead of token colors. Light and dark themes are CSS variable sets applied to the same markup.
Most languages use small priority patterns. JavaScript templates, JSX, markup embeddings, shell heredocs, and similar cases use focused stateful scanners. The library does not contain a general grammar interpreter.
import { highlight } from '@tanstack/highlight'
const result = highlight(`const answer = 42`, { lang: 'ts' })
result.code
result.lang
result.tokens
result.htmlThe HTML contract is one escaped <pre><code> tree:
<pre class="th-code th-code--ts" data-language="ts">
<code>...</code>
</pre>