motion-code
A syntax-highlighted code block with a macOS-style chrome, built-in tokenizer for multiple languages, typing animation, and compact mode.
Preview
Import
Usage
Typing animation
Add type to animate code appearing character by character — syntax highlighting applies as it types. Loops automatically by default. Control speed with type-speed (chars/sec, default 80) and the pause between loops with type-loop-delay (ms).
On reveal — no-loop
Add no-loop to disable looping. The animation plays once when the element scrolls into the viewport instead of starting immediately.
Delayed typing
Use type-delay (ms) to hold before typing starts — useful when the window animates into view.
Compact
Add compact for tighter padding, smaller font, and a slimmer title bar — useful inside cards or sidebars.
Hide chrome
Use hide-chrome to remove the title bar entirely — just the code body.
Languages
Language is inferred from the filename extension. Override with the lang attribute.
Theming
Token colours are CSS custom properties that pierce the Shadow DOM. Map any external theme's palette to these variables on :root.
Properties
| Attribute | Property | Type | Default | Description |
|---|---|---|---|---|
| | | string | "app.html" | Shown in the chrome bar; also used to infer the language |
| | | string | "" | Override language: html · js · css · json · python · sh |
| | | boolean | false | Show a Copy button in the chrome bar |
| | | boolean | false | Remove the title bar entirely |
| | | boolean | false | Reduce padding, font size, border radius, and title bar height |
| | | boolean | false | Animate code in character by character with a blinking cursor. Loops automatically. |
| | | number | 80 | Typing speed in characters per second |
| | | number | 0 | Delay in ms before typing starts |
| | | boolean | false | Disable looping — play once on viewport entry instead of repeating |
| | | number | 1500 | Pause in ms between the end of one loop and the start of the next |
CSS variables
| Variable | Type | Default | Description |
|---|---|---|---|
| | color | #7c3aed | Keywords, booleans, null |
| | color | #16a34a | String literals |
| | color | #0369a1 | HTML tags, CSS selectors |
| | color | #be123c | Attributes, CSS properties, JSON keys, decorators |
| | color | #b45309 | Numbers and units |
| | color | var(--color-muted) | Comments |
Methods
| Method | Type | Default | Description |
|---|---|---|---|
| | void | — | Set code programmatically. Triggers typing if type is enabled. |
| | void | — | Restart the typing animation from the beginning. |
Accessibility
Respects prefers-reduced-motion: when enabled, the cursor blink animation is disabled. The typing animation remains functional.