How to use Highlight.js to highlight code

Posted on February 18, 2019 at 11:45 pm

Using Highlight.js to highlight code is simple:

First include this inside the HEAD tag of the HTML page:

<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/highlight.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/styles/darcula.min.css" />
<script>hljs.initHighlightingOnLoad();</script>

Then you can use it like this:

<code class="json">
{name: "John", age: 31, city: "New York"}
</code>

Receive updates via email

Other Posts

Updated Posts