Shiki-powered syntax-highlighted code block with optional line numbers, line highlighting, copy button, filename header, compact pill mode and theme awareness. Supports 14 languages and honours the active Origam theme.
Preview
Rendering the live preview…
default
Rendering the live preview…
compact
Rendering the live preview…
with filename
Structure
Anatomy
Visual breakdown of the component's internal structure with BEM class call-outs.
Anatomy of <origam-code> — 6 internal parts. Root is <figure> for W3C correctness.
1.origam-code
Root element (default tag: ). Carries display, background, border, font-family and overflow tokens.
2.origam-code__header
Header bar rendered when filename is set. Contains the filename badge or lang badge and the copy button.
3.origam-code__copy
OrigamBtn copy button. Positioned in the header (--header), floating top-right (--floating) or inline in compact mode (--compact).
4.origam-code__scroller
Scrollable area wrapping the
pair. flex: 1 1 auto in non-compact mode so it fills a constrained height.
5.origam-code__pre / .origam-code__code
semantic pair. The element carries data-lang and receives the shiki-highlighted innerHTML.
6.origam-code__footer
API
Props
All props accepted by this component, with their type, default value and description.
code
string
Code to highlight. When omitted, the default slot is used as the source. When both are provided, the prop wins.
Language grammar to apply. Supported: 'plaintext' | 'vue' | 'ts' | 'js' | 'tsx' | 'jsx' | 'scss' | 'css' | 'json' | 'bash' | 'html' | 'xml' | 'yaml' | 'md'. Unknown values fall back to plaintext.
lineNumbers
boolean
false
Shows a left gutter with line numbers. Pure CSS counter — no JS layout work.
highlightLines
number[] | string | null
null
Lines to highlight. Accepts a 1-based array ([2, 5, 6]) or a range string ('2,5-7'). Null/empty disables.
copyable
boolean
true
Shows the copy-to-clipboard button. True by default — most code blocks benefit from it.
format
boolean
false
Auto-format the code before highlighting. Reserved — currently a no-op that warns in dev mode. Prettier is not bundled at runtime to keep the tarball small.
wrap
boolean
false
Wraps long lines instead of scrolling horizontally.
filename
string
Optional filename rendered in the header bar (e.g. 'App.vue'). When present AND copyable=true, the header hosts the copy button; otherwise the copy button floats in the top-right corner.
compact
boolean
false
Renders as a single-line inline pill (ideal for install commands). Header, filename and line numbers are suppressed; the copy button collapses to a small icon.
prompt
string
Decorative prefix rendered before the code (e.g. '$' for shell commands). Purely visual — not copied to clipboard.
hideHeader
boolean
Do not render the header bar (filename / language badge / copy button). For a block embedded in a surface that already shows that information, such as a tab of OrigamCodeGroup.
flat
boolean
Flatten the block into its host: no border, no radius, no elevation, no outer margin.
scrollerAriaLabel
string
Accessible name of the scrollable region. Left out, it is derived from filename, then lang. Set it when several blocks of the same language share a page.
id
string
class
string | Array<string> | object
style
string | Array<string> | object | StyleValue
tag
string
'figure'
Root HTML element. Defaults to <figure> for semantic correctness.
border
boolean | number | string | TDirectionBoth | Array<TDirectionBoth>
Replaces the default header bar (filename/lang badge + copy button). Receives filename, lang name, the copy function and the copied flag.
#footer—
Content appended after the code block inside a <footer> element.
#default—
Source code as slot text. Used when the code prop is absent. Whitespace is preserved.
API
Emits
Events emitted by this component.
@copy
string
API
Exposed members
Properties and methods accessible via template ref (defineExpose). Use them for programmatic control.
() => void
Force re-highlights the code. Useful when the theme changes or the code prop is mutated without Vue reactivity.
Ref<boolean>
True for feedbackDuration ms after a successful copy.
Ref<HTMLElement | undefined>
Template ref pointing to the inner <code> element. Useful for external syntax processing or DOM inspection.
Customisation
CSS variables
CSS custom properties exposed by this component. Override them to customise the component without losing theme compatibility.
Code block background colour.
Default foreground colour for non-highlighted tokens.
Border radius.
Monospace font stack.
Font size.
Line height of code rows.
Vertical padding inside the code surface.
Horizontal padding inside the code surface.
Header bar background.
Background of highlighted lines.
API
Composable
Lazily instantiates a shiki highlighter singleton on first call and reuses it across every OrigamCode instance. Exposes highlight(), prime(), isReady() and resetCacheForTesting().
Signature
typescript
Usage
vue
Inclusion
Accessibility
ARIA roles, keyboard navigation and focus management. Sourced from the real component template.
ARIA roles
figure
Keyboard interactions
Keyboard interactions
Key
Action
Tab
Moves focus to the copy button when copyable=true.
Enter / Space
Triggers the copy action on the focused copy button.
Notes
Root element defaults to <figure> for W3C correctness. The code block is rendered inside <pre><code data-lang="..."> which gives screen readers proper semantic context.
The copy button aria-label and aria-live="polite" are set so screen readers announce "Copied" after a successful write without interrupting the current reading.
The prompt prefix (<span aria-hidden="true">) is decorative — it is never read aloud and is never included in the clipboard payload.
The scrollable code area is focusable via keyboard when content overflows, allowing keyboard users to scroll horizontally.
Foundation
Design tokens
Excerpt from this component's token declarations — the --origam-<component>---<property> variables, declared in its hand-maintained token sheet with no build step.
Source
color
var(--origam-color__surface---raised)
Block background.
dimension
var(--origam-radius---md)
Corner radius.
fontFamily
var(--origam-font__family---mono)
Monospace font stack.
dimension
var(--origam-font__size---sm)
Font size.
color
var(--origam-color__feedback--warning---bgSubtle)
Highlighted line background.
Interactive
Playground
Edit props live and see the component update in real time. The generated code snippet updates as you change values.
Rendering the live preview…
Usage
Examples
Ready-to-paste code snippets for your templates.
Basic code block
vue
Compact install command
vue
Line highlighting
vue
Ecosystem
Related elements
Components and directives from different folders that collaborate with this one.