Horje

How to print HTML code with colors syntax highlighting on a HTML page

I'd recommend using highlightjs as it supports a large number of languages and comes with many color themes. For HTML code specifically, you need to escape HTML tags. There're many tools online to help you in achieving that.

Here's a quick demo for that using highlighjs:

index.html
Example: HTML
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/darkula.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<pre><code class="hljs html">
<ul>
<li ng-repeat="list in lists" class="input">
{{list}}
</li>
</ul>
</code></pre>

Output should be:

How to print HTML code with colors syntax highlighting on a HTML page




Type:
html
Category:
Web Tutorial
Sub Category:
HTML Syntax Highlighter Tutorial
Uploaded by:
Admin