Get started with prettify CDN

Apache-2.0 licensed

Library: Formats, beautifies HTML code snippets.

Tags:
  • code
  • syntax
  • highlighting
  • code-prettify

Stable version

Copied!

How to start using prettify CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with prettify CDN - cdnhub.io</title>
  <style>
    pre {
      white-space: pre-wrap;
      word-wrap: break-word;
    }
  </style>
</head>
<body>
  <button onclick="highlightCode()">Prettify Code</button>
  <pre id="code">
    <code id="js-code">
      const add = (a, b) => a + b;
      const subtract = (a, b) => a - b;
      const multiply = (a, b) => a * b;

      const numbers = [1, 2, 3, 4, 5];

      const sum = numbers.map(add).reduce(add);
      const difference = numbers.map(subtract, 0).reduce(subtract);
      const product = numbers.map(multiply).reduce(multiply);

      console.log(`Sum: ${sum}`);
      console.log(`Difference: ${difference}`);
      console.log(`Product: ${product}`);
    </code>
  </pre>
  <script src="https://cdn.cdnhub.io/prettify/r298/prettify.min.js"></script>
  <script>
    function highlightCode() {
      const jsCode = document.getElementById("js-code");
      const codeEl = document.getElementById("code");
      Prettier.highlightCode(codeEl, jsCode.textContent);
    }
  </script>
</body>
</html>
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions