Highlight.js colors code in the browser or on Node.js servers. It supports many languages, optional themes, and runs without framework dependencies.
Overview
Highlight.js is a JavaScript syntax highlighter that can run in web pages or in Node.js. It highlights fenced or marked-up code blocks, can guess the language automatically, and also accepts an explicit language when detection is wrong.
In the browser you link a build and theme, then call highlightAll to process code elements. You can skip blocks, treat content as plaintext styling only, or drive highlighting manually with highlightElement and configure options.
On the server the same highlighting API works through CommonJS or ES modules. You may load every language, a smaller common set, or only the grammars you register yourself to control bundle size.
Distribution options include npm packages, CDN-hosted builds, downloadable bundles with a chosen language subset, and prebuilt assets you can host yourself. Web workers can run highlighting off the main thread for large snippets, and integrations exist for Vue and other setups.
Key features
- Automatic language detection
- Browser and Node.js usage
- Many bundled language grammars
- Theme stylesheets for code blocks
- Zero external framework dependencies
- Selective language loading
- CDN and self-hosted bundles
- Web worker highlighting option
Use cases
- Documentation sites with code samples
- Blog or CMS syntax coloring
- Server-side rendered highlighted snippets
- Technical forums and read-only viewers
- Apps that need a small custom language set