prism
Lightweight, robust, elegant syntax highlighting.
Prism is a lightweight JavaScript library that adds color-coded syntax highlighting to code blocks on web pages, supporting dozens of programming languages and running entirely in the browser with no server needed.
Prism is a JavaScript library that adds color-coded syntax highlighting to code samples shown on web pages. When you visit a site where programming code appears with different colors for keywords, strings, and comments, there is a reasonable chance Prism is doing that work. The library is small by design and runs entirely in the browser without requiring anything on the server side.
It supports a wide range of programming languages, from HTML and CSS to Python, Java, Bash, and dozens of others. To use it, a developer includes the Prism script and a CSS theme file on their page, then marks code blocks with a class that names the language. Prism finds those blocks and applies the highlighting automatically. Themes control the visual appearance, and a separate repository called prism-themes holds additional options beyond the built-in defaults.
The project started as a spin-off from a web tool called Dabblet. It has since been adopted broadly across documentation sites, developer blogs, and web-based tools. Because it was designed to be extensible, contributors can add support for new programming languages and build plugins that add features like line numbers, copy buttons, and file labels.
The README notes that the project team is currently building a new major version called Prism v2 and is only accepting security-related contributions to the existing version until that work is complete. The current release is stable and available on npm under the package name prismjs. It works across virtually all modern browsers.
Where it fits
- Add color-coded syntax highlighting to code samples on a documentation site or developer blog by including two files and marking code blocks with a CSS class.
- Extend Prism with a plugin to show line numbers, a copy-to-clipboard button, or file name labels above code blocks.
- Contribute support for a new programming language to Prism by writing a grammar definition file.