Getting StartedComponentsDesign TokensThemingTheme SynthesizerFrameworksAccessibilityUtilitiesServer RenderingBrowser SupportContributingChangelogApp ShellAspect GridAuth ShellCenterContainerDashboard GridFloat BarInsetMasonryPage HeaderPage LayoutResizableResponsive SwitcherSectionSettings LayoutSplit PaneStatus BarStickyToolbarAnchor NavBottom NavBreadcrumbBreadcrumb MenuCommand BarDrawerFooterLinkMenubarNavigation MenuPage IndicatorPaginationRailScroll IndicatorScroll SpyScroll To TopSidebarSkip LinkStepper NavTabsTop BarTree ViewAccordionAspect RatioAvatarAvatar GroupCardCarouselCollapsibleColor SwatchCTA BannerDividerEmpty StateFeature CardIconImageImage CompareImage HotspotsInfinite ScrollLightboxMarqueeQR CodeScroll AreaSkeletonSpinnerStackVideoVirtual ListActivity HeatmapAnimated NumberBadgeBar ListChartClockComparisonCountdown TimerData GridDescription ListDiffGaugeJSON TreeKanbanLevel MeterListMeterSparklineStatStepperTagTimelineUptimeValue CardWaveformBlockquoteCode BlockCode GroupGradient TextHighlightKbdKeyboard MapMarkdownNumber FormatProseTerminalTextTime AgoTruncateTypewriterButtonButton GroupCalendarCheckboxChipColor PickerComboboxCopy ButtonDate PickerDate Range PickerField ListFieldsetFile UploadFormHotkeyIcon ButtonImage CropperInline EditInputInput GroupKnobLabelMasked InputMulti SelectNumber InputPassword InputPin InputRadio GroupRange SliderRatingSearchSegmented ControlSelectSignature PadSliderSortable ListSwitch GroupTag InputTextareaTheme ToggleTime PickerToggleTransfer ListTree SelectAlertAnnouncementBannerCommand PaletteConfirmConnection StatusContext MenuConversationDialogDropdown MenuHover CardLoading OverlayNotification PanelPopoverProgressSheetToastTooltip
ARC UIARC Radiant Components
v4.9DocsComponentsTokensSynthesizer
Getting StartedFrameworksServer RenderingDesign TokensThemingTheme SynthesizerTypographyUtilitiesAll ComponentsAccessibilityBrowser SupportChangelogContributingStatsApp ShellAspect GridAuth ShellCenterContainerDashboard GridFloat BarInsetMasonryPage HeaderPage LayoutResizableResponsive SwitcherSectionSettings LayoutSplit PaneStatus BarStickyToolbarAnchor NavBottom NavBreadcrumbBreadcrumb MenuCommand BarDrawerFooterLinkMenubarNavigation MenuPage IndicatorPaginationRailScroll IndicatorScroll SpyScroll To TopSidebarSkip LinkStepper NavTabsTop BarTree ViewAccordionAspect RatioAvatarAvatar GroupCardCarouselCollapsibleColor SwatchCTA BannerDividerEmpty StateFeature CardIconImageImage CompareImage HotspotsInfinite ScrollLightboxMarqueeQR CodeScroll AreaSkeletonSpinnerStackVideoVirtual ListActivity HeatmapAnimated NumberBadgeBar ListChartClockComparisonCountdown TimerData GridDescription ListDiffGaugeJSON TreeKanbanLevel MeterListMeterSparklineStatStepperTagTimelineUptimeValue CardWaveformBlockquoteCode BlockCode GroupGradient TextHighlightKbdKeyboard MapMarkdownNumber FormatProseTerminalTextTime AgoTruncateTypewriterButtonButton GroupCalendarCheckboxChipColor PickerComboboxCopy ButtonDate PickerDate Range PickerField ListFieldsetFile UploadFormHotkeyIcon ButtonImage CropperInline EditInputInput GroupKnobLabelMasked InputMulti SelectNumber InputPassword InputPin InputRadio GroupRange SliderRatingSearchSegmented ControlSelectSignature PadSliderSortable ListSwitch GroupTag InputTextareaTheme ToggleTime PickerToggleTransfer ListTree SelectAlertAnnouncementBannerCommand PaletteConfirmConnection StatusContext MenuConversationDialogDropdown MenuHover CardLoading OverlayNotification PanelPopoverProgressSheetToastTooltip

Code Block

Syntax-highlighted code with a title, a copy button, line numbers, line emphasis, diff tints, a shell prompt and a collapsed height.

ComponentsCode Block
typographyhybrid
<arc-code-block>

Overview

CodeBlock shows source code in a framed block. A slim header carries a title (`label`, in the body font), an optional `filename` in monospace, the `language` as a quiet tag, and an icon-only copy button that writes the code to the clipboard and turns into a green check for a moment. Code goes in through the `code` property; there is no default slot. Code renders line by line whether or not it is highlighted, so every reading aid works without the highlighter: `line-numbers` adds a gutter, `highlight="2,4-6"` emphasizes lines, `diff` (or `language="diff"`) tints added and removed lines, `wrap` soft-wraps long lines instead of scrolling them, and `max-lines` collapses a tall block behind a "Show all" button. None of this reaches the clipboard: the copy button copies `code` exactly as given. **Shell blocks.** Set `prompt` to put a `$` (or your own prompt, such as `#`) before each command. Continuation lines after a trailing backslash and blank lines get none, and the prompt can't be selected or copied. Shell highlighting separates the parts of a command: a wrapper like `sudo` is muted, the command is bold, its subcommand takes the accent, and paths, URLs and image references read as values. For variants of the same command (npm, pnpm and yarn, or two editions of a product), put the blocks in an [arc-code-group](/docs/components/code-group) for one block with tabs. **Highlighting is opt-in.** CodeBlock is the one component in ARC UI with a heavy dependency: shiki and its grammars are around 13.6 MB, which no other component touches. So shiki is an *optional peer dependency*, and CodeBlock is the one component the main barrel does not re-export. A bundler resolves the dynamic imports of everything it can reach, so being in the barrel would have made shiki everyone's install. Import it by its own subpath and install shiki alongside: ``` npm install shiki @shikijs/langs ``` ```js import '@arclux/arc-ui/code-block'; ``` Without shiki, CodeBlock still renders: the header, the copy button, the reading aids and the code itself all work. The code is not colored, and the console says so once. With shiki, the colors fade in when the grammar loads and no line moves. `@arclux/arc-ui/register` does not register CodeBlock for the same reason; import the subpath. CodeBlock is a hybrid component: the code display works without JavaScript, but copying needs JS and a secure context (HTTPS). Copy failures are caught, so it degrades without errors on HTTP or in restricted environments.

Guidelines

When to use

  • Give a block a `label` when it is one of several on a page, so a reader can tell them apart
  • Use `prompt` for commands a reader will paste into a terminal, and leave it off for scripts and output
  • Use arc-code-group for variants of the same command instead of stacking near-identical blocks
  • Use `highlight` to point at the lines the surrounding text talks about
  • Set `max-lines` on long samples in running text, so the page keeps its shape
  • Install shiki and @shikijs/langs when you want highlighting; the component works without them, uncolored
  • Import `@arclux/arc-ui/code-block` directly; the main barrel and `/register` exclude it

When not to use

  • Do not pass content between the tags. There is no default slot; use the `code` prop
  • Do not type a `$` into the code itself. It ends up in the reader's clipboard; use `prompt`
  • Do not use `wrap` for code where indentation matters to the reader, such as Python or YAML, unless the lines are short
  • Do not use CodeBlock for single-line inline code; use arc-text variant="code" instead
  • Do not assume copy will always work; it requires HTTPS and a user gesture in modern browsers

Features

  • Slim header: a `label` title in the body font, an optional `filename` in mono, the language as a quiet tag, and an icon-only copy
  • Copies `code` exactly: prompts and line numbers are never selected or copied
  • Shell prompt with `prompt`, skipping continuation and blank lines
  • Shell colors that separate the wrapper, command, subcommand, flags, variables, operators and values
  • `line-numbers`, `highlight="2,4-6"` line emphasis, and `diff` tints for added and removed lines
  • `wrap` for soft-wrapped lines, aligned after the gutter and prompt
  • `max-lines` collapses a tall block with a fade and a "Show all N lines" button
  • Syntax highlighting via shiki, an optional peer dependency imported only by this component; colors fade in without moving a line
  • Every reading aid works without shiki installed
  • Window variant with a title bar and a line count; basic variant with no chrome

Preview

Shell, with a prompt
Line numbers and emphasis
Diff, collapsed to five lines
Window
Basic

Usage

Layout and styling work without JavaScript via the HTML/CSS versions. Interactive features like events and state management require the Web Component or a framework wrapper.

<arc-code-block language="bash" label="Install" prompt></arc-code-block>
<arc-code-block language="js" filename="app.js" line-numbers highlight="2"></arc-code-block>

<script type="module">
  import '@arclux/arc-ui/code-block';
  const [install, app] = document.querySelectorAll('arc-code-block');
  install.code = 'npm install @arclux/arc-ui';
  app.code = "import '@arclux/arc-ui/register';\ndocument.body.classList.add('ready');";
</script>

API

languagestring''
Language identifier (e.g. js, css, bash). Shown in uppercase in the header and used to pick the highlighter grammar.
labelstring''
A plain title for the header in the body font, such as "Pulsar for NVIDIA". Shown before the filename when both are set. Also the tab name inside an arc-code-group.
filenamestring''
A filename for the header, in monospace. When label is also set it follows the label, muted.
codestring''
The code to display. Copied as-is by the copy button: no prompts, no line numbers.
promptstringnull
Shows a prompt before each command line, never selectable and never copied. Set with no value for $, or give the character (#, >, PS>). Continuation lines after a trailing backslash and blank lines get none.
highlightstring''
Lines to emphasize, 1-based: a comma-separated list of numbers and ranges such as 2,4-6.
variant'default' | 'window' | 'basic''default'
Visual variant. default shows the standard layout with an optional header and status bar. window adds a macOS-style title bar with colored orbs and a centered title. basic strips all chrome for a compact display.
lineNumbersbooleanfalse
Shows line numbers in a gutter that is not selected or copied.
diffbooleanfalse
Tints lines that start with + as added and - as removed, on top of the block's own language. Always on for language="diff".
wrapbooleanfalse
Soft-wraps long lines instead of scrolling them. Wrapped text stays aligned after the line number and prompt.
maxLinesnumber0
Collapses a longer block to this many lines, with a fade and a button to show the rest.

Events

arc-toggle
Fired when a collapsed block is expanded or collapsed again. detail.value is true when expanded.

See Also