motion-code-inline
Inline <code> tag with a styled background, monospace font, and an optional copy button. The accent, background, and icon colours are all controllable via CSS custom properties.
Preview
Run
Import
import 'motion-components/motion-code-inline' // just this one
import 'motion-components' // or the whole libraryUsage
<p>Import <motion-code-inline>motion-components</motion-code-inline> once.</p>Copy on hover
Add copy. A copy icon appears on hover and copies the text content on click. The icon is a motion-icon-state that morphs into a check after copying. It scales with the text, so it follows the font size around it.
<motion-code-inline copy>npm install motion-components</motion-code-inline>Always visible copy
Use copy-visible to keep the copy button always visible. No hover required.
<motion-code-inline copy-visible>npm install motion-components</motion-code-inline>Properties
| Attribute | Property | Type | Default | Description |
|---|---|---|---|---|
| | | boolean | false | Show a copy button on hover. Copies text content on click and shows a checkmark briefly. |
| | | boolean | false | Keep the copy button always visible instead of only on hover. |
CSS variables
| Variable | Type | Default | Description |
|---|---|---|---|
| | color | #2563eb | Text colour and icon hover colour |
| | color | #2563eb18 | Background fill behind the code text |
| | color | #60608a | Copy icon default colour |
| | color | copy button colour | Colour of the check after copying |
Theming
All colours are CSS custom properties that pierce the Shadow DOM. Override them on any parent to match your brand.
Import
Run
/* Dark theme example */
.theme-block {
--mc-color-accent: #60a5fa;
--mc-color-accent-dim: #60a5fa20;
--mc-color-muted: #94a3b8;
}Accessibility
The copy button is a native <button> named "Copy", which changes to "Copied" after a click. With prefers-reduced-motion, the copy icon switches to the check at once, with no morph. Respects system colours via CSS custom properties.