Prism is a lightweight, extensible syntax highlighter, built with modern web standards in mind. It’s used in thousands of websites, including some of those you visit daily.

HTML Example

<div class="container">
    <div class="row">
        <div class="col-md-6 order-md-1 text-center text-md-left pr-md-5">
            <h1 class="mb-3 bd-text-purple-bright">Bootstrap</h1>
            <p class="lead">
                Build responsive, mobile-first projects on the web with the world’s most popular front-end component
                library.
            </p>
            <p class="lead mb-4">
                Bootstrap is an open source toolkit for developing with HTML, CSS, and JS. Quickly prototype your ideas
                or build your entire app with our Sass variables and mixins, responsive grid system, extensive prebuilt
                components, and powerful plugins built on jQuery.
            </p>
            <div class="row mx-n2">
                <div class="col-md px-2">
                    <a href="/docs/4.4/getting-started/introduction/" class="btn btn-lg btn-bd-primary w-100 mb-3"
                        onclick="ga('send', 'event', 'Jumbotron actions', 'Get started', 'Get started');">Get
                        started</a>
                </div>
                <div class="col-md px-2">
                    <a href="/docs/4.4/getting-started/download/" class="btn btn-lg btn-outline-secondary w-100 mb-3"
                        onclick="ga('send', 'event', 'Jumbotron actions', 'Download', 'Download 4.4.1');">Download</a>
                </div>
            </div>
            <p class="text-muted mb-0">
                Currently v4.4.1
            </p>
        </div>
    </div>
</div>
            

CSS Example

#languages {
        column-count: 4;
    }
        #languages > h1 {
            margin-top: 0;
            column-span: all;
        }
        #languages label {
            display: block;
            padding: .2em;
        }
        #languages label[data-id="javascript"] {
            border-bottom: 1px solid #aaa;
            padding-bottom: 1em;
            margin-bottom: 1em;
        }
        #languages .unavailable {
            color: #aaa;
        }
        #languages input {
            margin-right: .7em;
        }
    
    #examples > section {
        display: block;
        margin: auto;
        max-width: 900px;
    }
        #examples h3 {
            margin: 1em 0 0.3em;
        }
    ul {
        padding-left: 40px;
    }

JavaScript Example

var each = _.each = _.forEach = function (obj, iterator, context) {
            if (obj == null) return;
            if (nativeForEach && obj.forEach === nativeForEach) {
                obj.forEach(iterator, context);
            } else if (obj.length === +obj.length) {
                for (var i = 0, l = obj.length; i < l; i++) {
                    if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return;
                }
            } else {
                for (var key in obj) {
                    if (_.has(obj, key)) {
                        if (iterator.call(context, obj[key], key, obj) === breaker) return;
                    }
                }
            }
        };

Basic usage

You will need to include the prism.css and prism.js files you downloaded in your page. Example:

<!DOCTYPE html>
<html>
<head>
            ...
            <link href="themes/prism.css" rel="stylesheet" />
        </head>
<body>
            ...
            <script src="prism.js"></script>
        </body>
</html>


Prism does its best to encourage good authoring practices. Therefore, it only works with <code> elements, since marking up code without a <code> element is semantically invalid. According to the HTML5 spec, the recommended way to define a code language is a language-xxxx class, which is what Prism uses. Alternatively, Prism also supports a shorter version: lang-xxxx.

To make things easier however, Prism assumes that this language definition is inherited. Therefore, if multiple <code> elements have the same language, you can add the language-xxxx class on one of their common ancestors. This way, you can also define a document-wide default language, by adding a language-xxxx class on the <body> or <html> element.

If you want to opt-out of highlighting for a <code> element that is a descendant of an element with a declared code language, you can add the class language-none to it (or any non-existing language, really).

The recommended way to mark up a code block (both for semantics and for Prism) is a <pre> element with a <code> element inside, like so:

<pre><code class="language-css">p { color: red }</code></pre>

If you use that pattern, the <pre> will automatically get the language-xxxx class (if it doesn’t already have it) and will be styled as a code block.

If you want to prevent any elements from being automatically highlighted and instead use the API, you can set Prism.manual to true before the DOMContentLoaded event is fired. By setting the data-manual attribute on the <script> element containing Prism core, this will be done automatically. Example:

<script src="prism.js" data-manual></script>

or

<script>
        window.Prism = window.Prism || {};
        window.Prism.manual = true;
        </script>
        <script src="prism.js"></script>

Usage with CDNs

In combination with CDNs, we recommend using the Autoloader plugin which automatically loads languages when necessary.

The setup of the Autoloader, will look like the following. You can also your own themes of course.

<!DOCTYPE html>
        <html>
        <head>
            ...
            <link href="https://myCDN.com/prism@v1.x/themes/prism.css" rel="stylesheet" />
        </head>
        <body>
            ...
        	<script src="https://myCDN.com/prism@v1.x/components/prism-core.min.js"></script>
            <script src="https://myCDN.com/prism@v1.x/plugins/autoloader/prism-autoloader.min.js"></script>
        </body>
        </html>

CDNs which provide PrismJS are e.g. cdnjs and jsDelivr.

Usage with Webpack, Browserify, & Other Bundlers

If you want to use Prism with a bundler, install Prism with npm:

$ npm install prismjs

You can then import into your bundle:

import Prism from 'prismjs';

To make it easy to configure your Prism instance with only the languages and plugins you need, use the babel plugin, babel-plugin-prismjs. This will allow you to load the minimum number of languages and plugins to satisfy your needs. See that plugin's documentation for configuration details.

Usage with Node

If you want to use Prism on the server or through the command line, Prism can be used with Node.js as well. This might be useful if you're trying to generate static HTML pages with highlighted code for environments that don't support browser-side JS, like AMP pages.

Example:

const Prism = require('prismjs');
        
        // The code snippet you want to highlight, as a string
        const code = `var data = 1;`;
        
        // Returns a highlighted HTML string
        const html = Prism.highlight(code, Prism.languages.javascript, 'javascript');

Requiring prismjs will load the default languages: markup, css, clike and javascript. You can load more languages with the loadLanguages() utility, which will automatically handle any required dependencies.

Example:

const Prism = require('prismjs');
        const loadLanguages = require('prismjs/components/');
        loadLanguages(['haml']);
        
        // The code snippet you want to highlight, as a string
        const code = `= ['hi', 'there', 'reader!'].join " "`;
        
        // Returns a highlighted HTML string
        const html = Prism.highlight(code, Prism.languages.haml, 'haml');

Note: Do not use loadLanguages() with Webpack or another bundler, as this will cause Webpack to include all languages and plugins. Use the babel plugin described above.

Supported Languages

This is the list of all 199 languages currently supported by Prism, with their corresponding alias, to use in place of xxxx in the language-xxxx (or lang-xxxx) class:

  • Markup - markup, html, xml, svg, mathml
  • CSS - css
  • C-like - clike
  • JavaScript - javascript, js
  • ABAP - abap
  • Augmented Backus–Naur form - abnf
  • ActionScript - actionscript
  • Ada - ada
  • ANTLR4 - antlr4, g4
  • Apache Configuration - apacheconf
  • APL - apl
  • AppleScript - applescript
  • AQL - aql
  • Arduino - arduino
  • ARFF - arff
  • AsciiDoc - asciidoc, adoc
  • 6502 Assembly - asm6502
  • ASP.NET (C#) - aspnet
  • AutoHotkey - autohotkey
  • AutoIt - autoit
  • Bash - bash, shell
  • BASIC - basic
  • Batch - batch
  • BBcode - bbcode
  • Bison - bison
  • Backus–Naur form - bnf, rbnf
  • Brainfuck - brainfuck
  • BrightScript - brightscript
  • Bro - bro
  • C - c
  • C# - csharp, cs, dotnet
  • C++ - cpp
  • CIL - cil
  • CoffeeScript - coffeescript, coffee
  • CMake - cmake
  • Clojure - clojure
  • Crystal - crystal
  • Content-Security-Policy - csp
  • CSS Extras - css-extras
  • D - d
  • Dart - dart
  • Diff - diff
  • Django/Jinja2 - django, jinja2
  • DNS zone file - dns-zone-file, dns-zone
  • Docker - docker, dockerfile
  • Extended Backus–Naur form - ebnf
  • Eiffel - eiffel
  • EJS - ejs
  • Elixir - elixir
  • Elm - elm
  • Embedded Lua templating - etlua
  • ERB - erb
  • Erlang - erlang
  • F# - fsharp
  • Firestore security rules - firestore-security-rules
  • Flow - flow
  • Fortran - fortran
  • FreeMarker Template Language - ftl
  • G-code - gcode
  • GDScript - gdscript
  • GEDCOM - gedcom
  • Gherkin - gherkin
  • Git - git
  • GLSL - glsl
  • GameMaker Language - gml, gamemakerlanguage
  • Go - go
  • GraphQL - graphql
  • Groovy - groovy
  • Haml - haml
  • Handlebars - handlebars
  • Haskell - haskell, hs
  • Haxe - haxe
  • HCL - hcl
  • HTTP - http
  • HTTP Public-Key-Pins - hpkp
  • HTTP Strict-Transport-Security - hsts
  • IchigoJam - ichigojam
  • Icon - icon
  • Inform 7 - inform7
  • Ini - ini
  • Io - io
  • J - j
  • Java - java
  • JavaDoc - javadoc
  • JavaDoc-like - javadoclike
  • Java stack trace - javastacktrace
  • Jolie - jolie
  • JQ - jq
  • JSDoc - jsdoc
  • JS Extras - js-extras
  • JS Templates - js-templates
  • JSON - json
  • JSONP - jsonp
  • JSON5 - json5
  • Julia - julia
  • Keyman - keyman
  • Kotlin - kotlin
  • LaTeX - latex, tex, context
  • Less - less
  • LilyPond - lilypond, ly
  • Liquid - liquid
  • Lisp - lisp, emacs, elisp, emacs-lisp
  • LiveScript - livescript
  • LOLCODE - lolcode
  • Lua - lua
  • Makefile - makefile
  • Markdown - markdown, md
  • Markup templating - markup-templating
  • MATLAB - matlab
  • MEL - mel
  • Mizar - mizar
  • Monkey - monkey
  • MoonScript - moonscript, moon
  • N1QL - n1ql
  • N4JS - n4js, n4jsd
  • Nand To Tetris HDL - nand2tetris-hdl
  • NASM - nasm
  • nginx - nginx
  • Nim - nim
  • Nix - nix
  • NSIS - nsis
  • Objective-C - objectivec
  • OCaml - ocaml
  • OpenCL - opencl
  • Oz - oz
  • PARI/GP - parigp
  • Parser - parser
  • Pascal - pascal, objectpascal
  • Pascaligo - pascaligo
  • PC-Axis - pcaxis, px
  • Perl - perl
  • PHP - php
  • PHPDoc - phpdoc
  • PHP Extras - php-extras
  • PL/SQL - plsql
  • PowerShell - powershell
  • Processing - processing
  • Prolog - prolog
  • .properties - properties
  • Protocol Buffers - protobuf
  • Pug - pug
  • Puppet - puppet
  • Pure - pure
  • Python - python, py
  • Q (kdb+ database) - q
  • Qore - qore
  • R - r
  • React JSX - jsx
  • React TSX - tsx
  • Ren'py - renpy
  • Reason - reason
  • Regex - regex
  • reST (reStructuredText) - rest
  • Rip - rip
  • Roboconf - roboconf
  • Robot Framework - robotframework, robot
  • Ruby - ruby, rb
  • Rust - rust
  • SAS - sas
  • Sass (Sass) - sass
  • Sass (Scss) - scss
  • Scala - scala
  • Scheme - scheme
  • Shell session - shell-session
  • Smalltalk - smalltalk
  • Smarty - smarty
  • Solidity (Ethereum) - solidity
  • Soy (Closure Template) - soy
  • SPARQL - sparql, rq
  • Splunk SPL - splunk-spl
  • SQF: Status Quo Function (Arma 3) - sqf
  • SQL - sql
  • Stylus - stylus
  • Swift - swift
  • TAP - tap
  • Tcl - tcl
  • Textile - textile
  • TOML - toml
  • Template Toolkit 2 - tt2
  • Turtle - turtle, trig
  • Twig - twig
  • TypeScript - typescript, ts
  • T4 Text Templates (C#) - t4-cs, t4
  • T4 Text Templates (VB) - t4-vb
  • T4 templating - t4-templating
  • Vala - vala
  • VB.Net - vbnet
  • Velocity - velocity
  • Verilog - verilog
  • VHDL - vhdl
  • vim - vim
  • Visual Basic - visual-basic, vb
  • WebAssembly - wasm
  • Wiki markup - wiki
  • Xeora - xeora, xeoracube
  • Xojo (REALbasic) - xojo
  • XQuery - xquery
  • YAML - yaml, yml
  • Zig - zig

Check official Website for more details.