Skip to content

Code Block

ts
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.

<script>
import CodeBlock from "@invisible-ui/svelte/CodeBlock.svelte";
</script>

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.

PropTypeDefaultDescription
codestring""Source to render (or pass it as children).
languagestring | undefinedundefinedLanguage caption.
copyablebooleantrueShow a copy-to-clipboard button.
copyLabelstring | undefinedundefinedAccessible label for the copy button.
  • The copy button is labelled and announces success; the code is selectable.
<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.