Home / Components / CodeBlock Pass plain source text to code. language supplies a recognizable badge; lang is an optional display-label override, not the document locale. wrap allows long lines to wrap; otherwise the code body scrolls horizontally. density changes spacing. Code is escaped text: this component does not execute it or apply syntax highlighting.
Try the interaction and open Code for the complete implementation.
Demo Source
const greeting = 'Hello, Neural UI';
console.log(greeting);Change the options, try the result and see the template update. Code contains the full executable example.
Demo Source
const greeting = 'Hello, Neural UI';
console.log(greeting);Behavior and content Structured data, callbacks and templates are shown in the examples and API.
Code adds advanced options when they differ from the default. Current configuration data and values appear in the template state.
Template generated from your current options. Open Code for the complete example.
<neu-code-block
[code]="code()"
language="typescript"
density="normal"
[wrap]="true"
[copiedAriaLabel]="'Example code copied'"
[copiedLabel]="'Copied'"
[copyAriaLabel]="'Copy example code'"
[copyLabel]="'Copy code'"
/>These values match the current preview. Complete handlers, Core imports and templates are in Source.
import { signal } from '@angular/core';
export const code = signal("const greeting = 'Hello, Neural UI';\nconsole.log(greeting);");The copy button writes the exact code string to the clipboard and confirms only a successful copy. Labels can be translated. CodeBlock has no Outputs or Templates; supply code and style it with its public tokens.
Reach the copy button with Tab and activate it with Enter or Space. Keep copyAriaLabel and copiedAriaLabel meaningful, especially when using short visible labels. Wrapped code is useful on narrow screens; unwrapped source has local horizontal scrolling.
Tab Reach the enabled copy button. Enter Copy the code from the focused copy button. Space Copy the code from the focused copy button.
Inputs and Outputs match the installed package. Named types link to definitions. Every available Template has a Demo and Code example.
Inputs Configure the component with [property]="value". Your application supplies these values; the component does not replace the state you pass in.
codestring''[code]Exact source text displayed and copied. copiedAriaLabelstring | undefinedundefined[copiedAriaLabel]Label for copy confirmation. Translate it for your application. copiedLabelstring | undefinedundefined[copiedLabel]Label for successful copy. Translate it for your application. copyAriaLabelstring | undefinedundefined[copyAriaLabel]Label for copy button. Translate it for your application. copyLabelstring | undefinedundefined[copyLabel]Label for copy action. Translate it for your application. densityNeuDensity 'normal'[density]Spacing scale: compact, normal or relaxed. langstring''[lang]Optional visible badge-label override. languagestring''[language]Language identifier used to derive the badge. wrapbooleanfalse[wrap]Wrap long source lines instead of local horizontal scrolling.
Templates ng-content projects content into the component. TemplateRef inputs receive a template; ng-template directives identify templates with a typed context. A directive shared by an entrypoint is not necessarily a slot of this component.
This component does not expose content projection or public customization templates.
Public Types Open a type to inspect its definition and interface fields.
import type { NeuDensity } from '@neural-ui/core';
// Public declaration (reference only)
type NeuDensity = 'compact' | 'normal' | 'relaxed';Customize supported public tokens and check both themes. Example illustrations and application state are not Core inputs.
Specific tokens --neu-code-block-accent Inherited theme value used by this component Field surface #9ab8ffRoot declaration No token alias--neu-code-block-bar-bg Inherited theme value used by this component Field surface #16161eRoot declaration No token alias--neu-code-block-bg Inherited theme value used by this component Field surface #1a1b26Root declaration No token alias--neu-code-block-border Inherited theme value used by this component Field surface rgba(255, 255, 255, 0.14)Root declaration No token alias--neu-code-block-copy-bg Inherited theme value used by this component Field surface rgba(255, 255, 255, 0.12)Root declaration No token alias--neu-code-block-copy-border Inherited theme value used by this component Field surface rgba(255, 255, 255, 0.22)Root declaration No token alias--neu-code-block-copy-hover-bg Inherited theme value used by this component Field surface rgba(255, 255, 255, 0.18)Root declaration No token alias--neu-code-block-copy-hover-border Inherited theme value used by this component Field surface rgba(255, 255, 255, 0.34)Root declaration No token alias--neu-code-block-copy-hover-text Inherited theme value used by this component Field surface #ffffffRoot declaration No token alias--neu-code-block-copy-text Inherited theme value used by this component Field surface #d9e2ffRoot declaration No token alias--neu-code-block-muted Inherited theme value used by this component Field surface #565f89Root declaration No token alias--neu-code-block-text Inherited theme value used by this component Field surface #d9e2ffRoot declaration No token alias
Shared tokens used Override these on a local wrapper to affect this example. An override on :root affects other components that use the same token.
--neu-focus-ring Normal keyboard-focus ring Shared by other Core consumers; scope the override. 0 0 0 var(--neu-focus-ring-width) rgba(0, 122, 255, 0.15)--neu-font-mono Text typography Shared by other Core consumers; scope the override. 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace--neu-font-sans Text typography Shared by other Core consumers; scope the override. 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif--neu-radius-lg Corner radius Shared by other Core consumers; scope the override. 12px--neu-radius-sm Corner radius Shared by other Core consumers; scope the override. 6px--neu-space-3 Spacing between content and controls Shared by other Core consumers; scope the override. 0.75rem--neu-transition Timing of state changes Shared by other Core consumers; scope the override. 200ms ease
PreviousCarousel Next Compare