Open SourceWeb Components
Reading time about a minuteLast updated
Table of contents
A custom element that uses the CSS Custom Highlight API for syntax highlighting.
Code highlighting works without modification. No need to wrap each token with a <span> element.
Try it#
HTML
<syntax-highlight language="js">// Hello world
console.log('Hello world!');
</syntax-highlight>CSS
@import url(https://cdn.jsdelivr.net/npm/syntax-highlight-element@1/dist/themes/prettylights.min.css);
syntax-highlight {
display: block;
border-radius: .5rem;
padding: 1rem;
}
JS
import 'https://cdn.jsdelivr.net/npm/syntax-highlight-element@1/+esm';
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.