CodeViewer

Data Display

Read-only code viewer with syntax highlighting, line numbers, and copy functionality

CodeViewer

Read-only code block with syntax highlighting, themes, word wrap, line numbers and copy support. Ideal for documentation and examples.

Basic usage

Use value and language to render syntax-highlighted code. Enable copy and status for an integrated toolbar and footer.

Loading...
Ln 1, Col 1
tsx
Spaces: 2

This example uses CodeViewer with copy and status enabled for a toolbar and status bar.

Themesaha-ui-dark
Copyenabled
Word wrapoff

Variants

Just like other Saha UI components, CodeViewer supports variants for different backgrounds and borders.

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Sizes

Use height utilities and the size prop to adapt the viewer to inline snippets or larger blocks.

Loading...
Loading...
Loading...
Loading...

Themes

CodeViewer supports multiple built-in themes. Use the same theme tokens as CodeEditor for a consistent look.

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Copy, wrap & status

Combine features to match different documentation layouts.

Copy + status

Loading...
Ln 1, Col 1
tsx
Spaces: 2

Word wrap only

Loading...

Minimal (no chrome)

Loading...

Usage Guidelines

When to Use

  • Documentation code examples
  • Read-only snippets
  • API responses

Accessibility

  • Announced as code block
  • Copy action accessible

Performance

  • Static syntax highlighting
  • Memoized output

Common Mistakes

  • Missing copy button
  • Horizontal scroll on mobile

Frequently Asked Questions

CodeViewer is read-only with syntax highlighting. CodeEditor is editable.
Yes, CodeViewer includes a copy button for easy code copying.

View on GitHub

See the full source code on GitHub