How to create: Syntax Highlighter
- Previous Page JS Media Queries
- Next Page JS Animation
Learn how to create and use syntax highlighters.
Syntax Highlighter
When you add some color to code snippets, they are easier to read:
<!DOCTYPE html>
<html>
<body>
<h1>Testing an HTML Syntax Highlighter</h2>
<p>Hello world!</p>
<a href="https://www.codew3c.com">Back to School</a>
</body>
</html>
How to create a syntax highlighter
Step 1 - Add HTML:
A <div> containing HTML code:
<div id="myDiv"> <!DOCTYPE html><br> <html><br> <body><br> <br> <h1>Testing an HTML Syntax Highlighter</h2><br> <p>Hello world!</p><br> <a href="https://www.codew3c.com">Back to School</a><br> <br> </body><br> </html> </div>
Step 2 - Add JavaScript:
Create a function named "w3CodeColor" and use a DIV element as an argument to call it:
w3CodeColor(document.getElementById("myDiv")); function w3CodeColor(elmnt) { // click "Try it Yourself" to see the JavaScript... }
- Previous Page JS Media Queries
- Next Page JS Animation