A lightweight, and easy-to-use, JavaScript library for code syntax highlighting!
Version: 3.1.0



What Features Does Syntax.js Have?
- Zero-dependencies and extremely lightweight!
- Written in TypeScript, allowing greater support for React, Angular, and other libraries!
- Highlights keywords, values, strings, and comments.
- 51 language translations available!
- Full API available via public functions.
- Fully styled in CSS/SASS and compatible with the Bootstrap library.
- Full CSS theme support with a default dark-mode theme.
- Copying and printing support available via action buttons.
- Custom triggers for actions (when elements are rendered, keywords are clicked, etc).
- 27 of the most popular languages built in by default.
- Language aliases and unknown language support.
- Tabbed organization for multiple languages.
Where Can I Find the Documentation?
All the documentation can be found here.
Supported Browsers
All modern browsers (such as Google Chrome, Firefox, and Opera) are fully supported.
Supported Languages
Supported languages include, but are not limited to:
- English (default)
- JavaScript
- Python
- C++
- Java
- Ruby
- PHP
- HTML
Recent Changes
To see a list of all the most recent changes, click here.
How Do I Install Syntax.js?
You can install the library using npm with the following command:
npm install js syntax.js
You can also download the latest zipped version here.
Alternatively, use the following CDN links:
https://cdn.jsdelivr.net/gh/williamtroup/Syntax.js@3.1.0/dist/syntax.min.js
https://cdn.jsdelivr.net/gh/williamtroup/Syntax.js@3.1.0/dist/syntax.js.min.css
How Do I Get Started?
To get started using Syntax.js, follow these steps:
1. Prerequisites:
Ensure you have the DOCTYPE HTML tag at the top of your HTML.
<!DOCTYPE html>
2. Include Files:
<link rel="stylesheet" href="dist/syntax.js.css">
<script src="dist/syntax.js"></script>
<script src="dist/languages/syntax.javascript.js"></script>
<script src="dist/languages/syntax.html.js"></script>
3. DOM Element Binding:
Use the following code structure to bind your DOM elements:
<div data-syntax-language="javascript">
var something = true;
if (something)
console.log("Output is written."); // Comment
/* Multi-line comment */
</div>
4. Finishing Up:
That’s it! You’ve set up Syntax.js and are ready to highlight code. Please refer to the code if you need additional help, as it is fully documented.
How to Customize Syntax.js?
To customize and maximize the utility of Syntax.js, review the following documentation:
1. Public Functions:
To see a list of all the public functions available, click here.
2. Configuration:
Configuration options can customize how Syntax.js behaves. Set them as follows:
script
$syntax.setConfiguration({
safeMode: false
});
For more configuration options, click here.
Troubleshooting
If you’re facing issues, consider the following troubleshooting steps:
- Ensure that all file paths are correct in your HTML file.
- Confirm that you’ve included the CSS file before the JavaScript files.
- Make sure that the supported languages are properly defined in the data attributes.
- If the syntax highlighting does not appear, check browser console logs for any JavaScript errors that may need addressing.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.