<code-viewer> renders as the title (clickable).
<code-viewer>Optional Title</code-viewer>
<template>, <pre>, or <code>.
<code-viewer>
Title
<template slot="code">
// code here (will render as literal text in non-Prism mode)
</template>
</code-viewer>
bg-color — component background (maps to --component-bg).title-bg-color — title bar background (maps to --title-bg).background-color — code area background (maps to --code-bg), default #333.color — code foreground (maps to --code-fg), default #eee.width — width of the visible code box (e.g., 50ch, 28rem, 520px).height — height of the visible code box; defaults to auto.overflow-x — horizontal overflow policy; default auto.font-family — font family applied to visible element(s).font-size — font size applied to visible element(s).code-padding — padding inside code box; default 0.75rem 1rem.highlight — set to "prism" to use slotted <pre><code> with Prism highlighting.language — language ID (e.g., javascript, cpp); adds language-* classes to <pre> and <code>.trim — removes one leading and trailing blank line from content.normalize-indent — removes smallest common leading indent across non-empty lines.<pre>.<pre><code> structure, applies trim/normalize-indent, language classes, and triggers Prism.highlightElement().<code>.overflow-y: auto; Prism applies overflow-x to visible element.part="component" — main framed box.part="title" — title row.--wrapper-bg — wrapper background.--component-bg — set via bg-color.--title-bg — set via title-bg-color.--code-bg — set via background-color.--code-fg — set via color.--code-width, --code-height, --code-overflow-x — sync with attributes in non-Prism mode.No public events. Internal handlers respond to slotchange and click events but no custom events are emitted.
<code-viewer width="50ch" height="18rem" trim normalize-indent
font-family="JetBrains Mono" font-size="0.95rem">
HTML Example
<template slot="code">
<div class="note">This appears as literal text, not rendered HTML.</div>
</template>
</code-viewer>
<link rel="stylesheet" href="prism.css">
<script src="prism.js" defer></script>
<code-viewer highlight="prism" language="javascript" width="52ch"
overflow-x="auto" code-padding="0.5rem 0.75rem" trim normalize-indent>
JS Snippet
<pre slot="code"><code>
// Your code here...
function hello(name) {
console.log(`Hello, ${name}`);
}
</code></pre>
</code-viewer>
<pre><code> structure and that language definitions are loaded.