Skip to content

CodeBlock

Read, select, and copy an example with its file name.

alpina-ui/portal/code-block

Interactive preview

layout.tsx
<Grid>
  <GridItem small={4}>Programme</GridItem>
</Grid>

Usage notes

If automatic copying is unavailable, the control selects the code and focuses it. Use the browser’s copy command while the selection is active.

When to use

Present a complete command, configuration fragment or code example that readers may copy intact.

When to avoid

Use inline code for a single prop name within a sentence and Prose for an explanation spanning paragraphs.

Accessibility

Name the snippet with its file name or purpose. Allow keyboard access to horizontal scrolling and give the copy action an accessible name.

Keys
KeyAction
Enter / SpaceActivate Copy when the button has focus.
Ctrl+C / ⌘CCopy the selected code when clipboard access requires manual copying.

Content

Use a concise caption and preserve code exactly in every translation. Put translated explanations outside the snippet.

Use
Terminal · npm run build
Avoid
Run these magic commands!!!

Copy in four languages

German
Installationsbefehl19 characters
French
Commande d’installation23 characters
Italian
Comando di installazione24 characters
Romansh
Cumond d’installaziun21 characters
Add to your project
npx --no-install alpina add code-block