lit-material-code-field edits YAML, JSON or a script: line numbers, Tab indents (Escape, then Tab, to
leave), Enter keeps the indent. language="json" checks the text and names the line of an error.
Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide
API
<lit-material-code-block>
A monospace container for a block of source code — a filename/language
label, a copy-to-clipboard button, and optional truncation for long
snippets. Deliberately doesn't syntax-highlight: that's a real, separate
feature (tokenizing a specific language, shipping a grammar/theme) that
belongs to a dedicated highlighting library, not this component — slot in
pre-highlighted markup yourself if you need it, the same way a <pre>
element itself doesn't care what's inside it.
Properties
Property
Attribute
Type
Default
Description
label
label
string
""
A filename or language label shown in the header (e.g. "index.ts").
copyable
copyable
boolean
true
>
expandable
expandable
boolean
false
>
expanded
expanded
boolean
false
Whether an expandable block shows its full content. Ignored otherwise.
Events
Event
Description
copy
Fires after copy() writes the code's text to the clipboard (not when copying fails).
Slots
Slot
Description
default
The code content (plain text, or pre-highlighted markup from your own highlighter).
CSS parts
Part
Description
code-block
The outer container.
header
The label/copy-button row. Only rendered when label or copyable.
label
The label text.
copy
The copy button.
pre
The <pre> element.
code
The <code> element.
expand-toggle
The "Show more"/"Show less" button. Only rendered when expandable.