Getting Started

Comparison

Comparison

Syntax highlighters solve different problems. The smallest correct choice is the one whose architecture matches your output requirements.

Decision table

ChooseBest fitMain tradeoff
TanStack HighlightBlogs and docs that know their languages, need SSR/client parity, and value small HTML and selective importsFocused heuristics instead of editor-grade grammars
Sugar HighThe smallest practical JavaScript/TypeScript/JSX experienceNarrower language set and much more generated markup in our fixture comparison
ShikiVS Code-like accuracy, TextMate grammars, and broad language/theme compatibilityMuch larger runtime and asynchronous setup
highlight.jsBroad language coverage and optional automatic detectionLarger modular core and detection/parser work not needed by known-language docs
PrismMature grammar ecosystem and plugin integrationsGrammar composition and plugin architecture add more surface than this use case needs
speed-highlightSmall, modular, class-based highlighting across browser and terminal use casesDifferent grammar/output model and fewer docs-specific adapters
Starry NightGitHub-like TextMate scopes and very broad grammar coverageLarge grammar/WASM footprint

Capability matrix

CapabilityTanStack HighlightSugar HighShikihighlight.jsPrism
Synchronous highlightingYesYesAfter initializationYesYes
Explicit per-language importsYesPartialYesYesYes
Known-language docs focusYesJS/TS focusNoNoNo
Class-based token colorsYesCSS variables and inline token dataInline colors by defaultYesYes
One markup tree for light/darkYesTheme through CSS variablesDual-theme output supportedTheme CSSTheme CSS
Built-in line decorationsYesLine class callbackTransformersNoPlugins
Built-in character-range decorationsYesNoTransformersNoPlugins
HTML script/style delegationRegistered languagesNo general embeddingGrammar-drivenGrammar-drivenGrammar-driven
Markdown fence delegationRegistered languagesNoGrammar-drivenGrammar-drivenGrammar-driven
Remark, rehype, and Octane MDX adaptersYesNoEcosystemEcosystemEcosystem
Automatic language detectionNoNoNoYesNo
TextMate/VS Code compatibilityNoNoYesNoNo
Hundreds of languagesNoNoYesYesYes

"Partial" means the package offers separate presets or registrations, but not the same one-definition-per-language import model.

Measured overlap with Sugar High

The repository pins Sugar High and compares the overlapping JavaScript, TypeScript, JSX, and TSX fixture set.

Bundle gzip5,040-block runtimeGenerated HTML
TanStack Highlight3.93 KB162 ms6.7 MiB
Sugar High 1.2.13.28 KB395 ms44.7 MiB

Sugar High wins raw JavaScript bundle size. TanStack Highlight spends about 650 additional gzip bytes on its registry, class-based output, decorations, and broader context handling, then produces substantially less HTML in this corpus.

Measured overlap with Shiki

Across 333 committed documentation fixtures:

InitializationHighlightingGenerated HTML
TanStack HighlightNone~20 ms364 KiB
Shiki 4.3.1~20 ms~1.2 s1,252 KiB

Timings vary by machine. This is not equivalent work: Shiki provides much deeper grammar accuracy and compatibility. The benchmark describes the cost difference when both are used to render this package's targeted docs corpus.

When not to use TanStack Highlight

Choose another tool when you need:

  • Exact editor or compiler tokenization
  • VS Code theme imports
  • TextMate grammar compatibility
  • Language auto-detection
  • Hundreds of languages
  • Incremental editor state
  • Semantic tokens from a language service

Run pnpm run compare:sugar-high and pnpm run compare:shiki to reproduce the repository's comparisons.