Code Viewer for Angular
Introduction
Section titled “Introduction”Read-only code display with line numbers, syntax highlighting for TypeScript, JavaScript, JSON, HTML, CSS, SQL, Bash, and Markdown (an in-repo tokenizer that produces text nodes with classes, never HTML), highlighted lines, a wrap toggle, a copy button, and a diff view (unified or side by side) computed in the repo with Myers’ algorithm. The code is a focusable, named region; files above 400 rows are virtualized on the shared windowing engine.
- Eight languagesTypeScript, JavaScript, JSON, HTML, CSS, SQL, Bash, and Markdown, highlighted by an in-repo tokenizer that only creates text nodes.
- Diff built inUnified or side-by-side views from a Myers line diff, with Added and Removed spoken, not just colored.
- 10,000 linesLarge files are virtualized; only the rows in view are in the DOM, and wrapped rows are measured as they render.
- Copy and wrapOne-click copy with an announced result, a wrap toggle, highlighted lines, and pinned line numbers.
- Themed tokensEvery token color is a theme token that passes the contrast gate on code, added, removed, and highlighted lines.
Behavior, design tokens, and limitations are described on the Code Viewer page; this page covers the Angular API.
Live example
Section titled “Live example”import { Component } from '@angular/core';import type { CodeViewerCopyDetail } from '@absoluteui/components/code-viewer';import { AuiCodeViewer } from '@absoluteui/angular/code-viewer';
@Component({ selector: 'app-snippet', imports: [AuiCodeViewer], template: `<aui-code-viewer label="Install" language="bash" [code]="code" (copied)="onCopy($event)"></aui-code-viewer>`,})export class SnippetComponent { readonly code = 'npm install @absoluteui/components'; copiedText = ''; onCopy(detail: CodeViewerCopyDetail): void { this.copiedText = detail.text; }}Install and start
Section titled “Install and start”npm install @absoluteui/angular @absoluteui/components @absoluteui/core @absoluteui/themeSetup with provideAbsoluteUI() is covered in Getting started. Styles are included with the component.
import { AuiCodeViewer } from '@absoluteui/angular/code-viewer';Defaults for every instance: provideAbsoluteUIConfig({ components: { codeViewer: { ... } } }) (see Configuration).
API reference
Section titled “API reference”<aui-code-viewer>
Section titled “<aui-code-viewer>”Class AuiCodeViewer; template reference #ref="auiCodeViewer".
Server rendering: Renders on the server; the browser re-creates it after hydration.
Inputs
Section titled “Inputs”| Input | Type | Default | Description |
|---|---|---|---|
label |
string |
Required. Accessible name of the code region. | |
code |
string |
'' |
Source text (ignored when diff is set). |
diff |
CodeViewerDiff | null |
null |
Show a diff: { original, modified, mode?: ‘unified’ | ‘split’, originalLabel?, modifiedLabel?, ignoreWhitespace? }. |
language |
CodeLanguage |
'plain' |
‘typescript’ | ‘javascript’ | ‘json’ | ‘html’ | ‘css’ | ‘sql’ | ‘bash’ | ‘markdown’ | ‘plain’. |
filename |
string |
File name shown in the toolbar. | |
startLine |
number |
'1' |
Number of the first line (code view). |
highlightLines |
readonly CodeViewerLineRange[] |
'[]' |
Line numbers or [from, to] ranges to highlight (modified line numbers in a diff). |
toolbar |
boolean |
true |
Show the toolbar (file name, language, actions). |
copyable |
boolean |
true |
Show the copy button. |
wrapToggle |
boolean |
true |
Show the wrap toggle. |
maxHeight |
string | null |
'30rem' |
Maximum block size of the scroll area (CSS length), or null to grow with the content (no virtualization). |
icons |
Partial<CodeViewerIcons> |
Toolbar icons: copy, copied, unified, split. | |
lineNumbers |
boolean |
true |
Show line numbers. |
wrap |
boolean |
false |
Wrap long lines (the side-by-side diff always wraps). |
tabSize |
number |
'2' |
Width of a tab character in spaces (1 to 16). |
locale |
string |
'en-US' |
Locale of messages and counts. |
density |
Density |
'comfortable' |
Line and toolbar spacing. |
Outputs
Section titled “Outputs”| Output | Payload | Description |
|---|---|---|
(copied) |
CodeViewerCopyDetail |
The text was written to the clipboard: { text }. Re-emits aui-copy. |
(changed) |
CodeViewerChangeDetail |
The user toggled wrapping or the diff mode: { wrap, mode, reason }. Re-emits aui-change. |
Methods
Section titled “Methods”Call them through a viewChild query or a template reference.
| Method | Description |
|---|---|
scrollToLine(line: number, align?: "auto" | "start" | "end" | "center" | undefined): void |
Scroll a displayed line number (modified side in a diff) into view. |
copy(): Promise<boolean> | undefined |
Copy the text to the clipboard; resolves false when the clipboard refused. |
Accessibility and performance
Section titled “Accessibility and performance”Pattern: A focusable, named scroll region (role=region) containing the code as text; toolbar actions are native toggle and push buttons.
The Angular component renders the framework-neutral component, so its keyboard support, roles, WCAG 2.2 criteria, budgets, and import cost apply unchanged: see Code Viewer: Accessibility and performance.
(c) 2026 Kasadara Technology Solutions Pvt Ltd. AbsoluteUI is free to use under the AbsoluteUI Free Use License; it is not open source.