Prism highlights code in the browser or on Node.js using language-xxxx classes on code elements, with many optional language packs.
Overview
Prism is a syntax highlighting library spun off from the Dabblet project. It emphasizes small core size, semantic markup with code inside pre elements, and language identification through language-xxxx or lang-xxxx classes as recommended for HTML5.
The core is designed to stay around 2KB minified and gzipped, with each additional language definition adding a few hundred bytes. Prism works with automatic highlighting on page load or manual highlighting through its JavaScript API when Prism.manual is set. An Autoloader plugin can fetch languages from CDNs such as cdnjs, jsDelivr, or UNPKG.
Developers can install Prism via npm for bundlers or require it in Node.js to produce highlighted HTML strings for static generation. The loadLanguages utility loads extra grammars on the server, while babel-plugin-prismjs is recommended for bundlers to include only selected languages. Language inheritance allows sharing a language class on a common ancestor or on html or body for a default.
Hundreds of languages are listed in the documentation with aliases for use in class names. Plugins extend behavior for tasks such as showing invisibles or handling unescaped markup when needed.
Key features
- Small gzipped core
- language-xxxx class convention
- Automatic or manual highlighting
- Autoloader CDN plugin
- npm and bundler integration
- Node.js static HTML highlighting
- Language inheritance on ancestors
- Extensive language definitions
Use cases
- Code blocks on documentation sites
- Blog syntax highlighting
- Server-side highlighted HTML
- Bundled minimal language sets
- Meta highlighting of Prism itself