Adding Syntax Highlighting to Code Snippets in a Website
This article was last updated on 2022-04-10, the content may be out of date.
All rights and credits reserved to Tania Rascia. This is a rewrite (kind of) just for sake of simplicity.
It’s your choice to pick one but in this guide, we will use Prism.js. If you want to local hosting your file. Download it here,
Or we can simply link the css in our
And link to the JS before the closingtag:
Finally, wrap your desired code in
<pre><code class="language-whatever">. You’re defining the language, and the
<pre> ensures that all your indentation will be properly preserved.
If you find this post helpful, please consider sponsoring.Sponsor