Code Block
import { createCalendar } from "@invisible-ui/svelte";
const calendar = createCalendar({
value: "2026-06-15",
weekStartsOn: 1,
}); A block <pre><code> with an optional language caption and a copy button.
Import
Section titled “Import”<script> import CodeBlock from "@invisible-ui/svelte/CodeBlock.svelte";</script><script setup> import { CodeBlock } from "@invisible-ui/vue";</script>import { CodeBlock } from "@invisible-ui/react";<script type="module"> import "@invisible-ui/elements/define";</script>
<ds-code-block></ds-code-block>In Elements:
<ds-code-block language="bash" code="pnpm install"></ds-code-block>Set code as a property for a multi-line sample. It is always inserted as
text.
| Prop | Type | Default | Description |
|---|---|---|---|
code | string | "" | Source to render (or pass it as children). |
language | string | undefined | undefined | Language caption. |
copyable | boolean | true | Show a copy-to-clipboard button. |
copyLabel | string | undefined | undefined | Accessible label for the copy button. |
| Prop | Type | Default | Description |
|---|---|---|---|
code | string | "" | The source text. Drives the copy button and is rendered when no slot is given. |
language | string | undefined | Optional caption shown in the header (e.g. a language or filename). |
copyable | boolean | true | Render a copy-to-clipboard button. Defaults to true. |
copyLabel | string | undefined | Accessible name for the copy button. Defaults to the catalog's "Copy code". |
Slots: default.
| Prop | Type | Default | Description |
|---|---|---|---|
code | string | "" | The source text: what the copy button copies, and what shows without children. |
language | string | — | Optional caption in the header, such as a language or a filename. |
copyable | boolean | true | Render a copy button. Defaults to true. |
copyLabel | string | — | Name of the copy button. Defaults to the catalog's "Copy code". |
children | ReactNode | — | Already highlighted markup, shown in place of code. |
| Attribute | Reactive | Description |
|---|---|---|
code | yes | the source text |
language | yes | a caption such as a language or a filename |
copyable | yes | copyable="false" removes the copy button |
copy-label | yes | the copy button's name; "Copy code" by default |
Reactive attributes re-render the element when they change after the first render.
Properties: code.
Accessibility
Section titled “Accessibility”- The copy button is labelled and announces success; the code is selectable.
Example
Section titled “Example”<CodeBlock code={"const x = 1;"} language="ts" />In React, highlighted markup goes in children while code still drives
the copy button:
<CodeBlock code="const x = 1;" language="ts" />Themeable via --ds-code-block-*. The background is the
code-block-background component token of each theme,
--ds-components-code-block-background-default: Grey 50 in the light theme, Grey 950 in the
dark one.