On this page
Overview
Highlight.js is a JavaScript syntax-highlighting library that runs in browsers and on servers without depending on a framework. It supports both explicit language selection and automatic language detection from source text.
Features and best fit
Based on official documentation; not hands-on tested · Content checked:
Key features
Highlight pre/code blocks across a page in the browser
Load the stylesheet and library and call hljs.highlightAll() to process code inside <pre><code> elements. Known languages can be declared with classes such as language-html.
Sources: [1]
Choose explicit or automatic language detection in Node.js
Server-side code can call highlight() with a language name or highlightAuto() to infer the language from the input. The generated highlighted HTML is available from the result's value field.
Sources: [1]
Load fewer grammars to reduce the bundle
The top-level package can load all bundled languages, while highlight.js/lib/common provides a smaller common subset. Applications can also register only the grammars they need.
Sources: [1]
Best fit
Fits documentation, code viewers, and article code blocks that need consistent syntax highlighting
It works well for technical documentation, Markdown-generated code blocks, and server-rendered code snippets that should share one highlighting implementation.
Sources: [1]
Before adoption
Prefer an explicit language when the language is already known
Automatic detection infers a language from the source text, so short snippets or similar syntaxes can be ambiguous. A class or the highlight() language option can pin known input.
Sources: [1]
Official sources
- [1]Highlight.js 11.12.0 README(2026-10-05)
- [2]Highlight.js 11.12.0 package metadata(2026-10-05)
- [3]Highlight.js 11.12.0 release(2026-10-05)
- [4]Highlight.js BSD-3-Clause license(2026-10-05)
Supplemental curator note
A practical strength is choosing between explicit language selection and automatic detection through the same library. When a page does not need every grammar, lib/common or explicitly registered languages can keep the shipped bundle smaller.
Try it in 3 steps
- 1
Check Node.js and install Highlight.js 11.12.0
Pin the reviewed stable release in a temporary directory without changing an existing project.
node -e 'if (Number(process.versions.node.split(".")[0]) < 12) throw new Error("Highlight.js 11.12.0 requires Node.js >= 12")' && demo=$(mktemp -d "${TMPDIR:-/tmp}/highlightjs.XXXXXX") && cd "$demo" && npm init -y >/dev/null && npm install --save-exact highlight.js@11.12.0 - 2
Create a script that highlights XML explicitly
Follow the README's Node.js pattern while pinning the language to XML instead of relying on auto-detection.
printf "%s\n" "const hljs = require('highlight.js/lib/common');" "const result = hljs.highlight('<h1>Hello</h1>', { language: 'xml' });" "console.log(result.value);" "if (!result.value.includes('hljs-tag')) throw new Error('highlight output missing');" > demo.cjs - 3
Run the script and verify highlighted output
Print the highlighted HTML and let the script verify that the output contains the
hljs-tagclass.node demo.cjs
Growth
Growth trends · Last 30 days
25,005 Stars
Trend data is still being collected.
Development activity
Last 90 days · weekly
- Commits (last 30 days)
- 0
- Open PRs
- 54
Development activity is still being collected.
Built with
Categories and tags
Categories
GitHub data
GitHub dataView detailed GitHub data
GitHub Topics
- syntax-highlighting
- language-grammars
- highlighting
- syntax-highlighter
- javascript
- Stars
- 25,005
- Forks
- 3,752
- Watchers
- 296
- Open issues
- 65
- Contributors
- 415
- Owner type
- Organization
- Primary language
- JavaScript
- License
- BSD-3-Clause
- Repository last updated
- Sep 6, 2026
Related information
Write a related articleShare a guide or use case for this OSS in Markdown. Articles are published after administrator approval.
Explore next
- Video.js39,907 Stars
3 shared tag(s) · Same language
add a shared player UI and API to HTML5 video, including web streaming formats such as HLS and DASH
JavaScript - SortableJS31,186 Stars
3 shared tag(s) · Same language
reorder list items with drag and drop within or across lists while supporting touch input
JavaScript - localForage25,809 Stars
3 shared tag(s) · Same language
use IndexedDB and other browser persistence through an asynchronous localStorage-like API
JavaScript - PhotoSwipe25,270 Stars
3 shared tag(s) · Same language
open image galleries in a lightbox with swipe, zoom, and dynamic loading across mobile and desktop
JavaScript - SweetAlert218,098 Stars
3 shared tag(s) · Same language
replace alert, confirm, and prompt dialogs with WAI-ARIA-aware popups that resolve through Promises
JavaScript - Tippy.js12,240 Stars
3 shared tag(s) · Same language
position tooltips, popovers, and dropdowns with Popper and attach them to hover, focus, or click interactions
JavaScript
Report incorrect information
Tell us if any listing information is incorrect or outdated.