Garden 9 is now available.
The website has been updated to the latest major version. View previous versions
Skip to main content
Design
Components
Patterns
    • Introduction
      • Overview
    • Foundations
      • Bedrock CSS
      • Design tokens
      • Containers
      • Theming
      • Versions
    • Components
      • Accordion
      • Anchor
      • Avatar
      • Breadcrumbs
      • Buttons
      • Chrome
      • Code block
      • Color picker
      • Color swatch
      • Date picker
      • Draggable
      • Drawer
      • Forms
      • Grid
      • Loaders
      • Menu
      • Modal
      • Notification
      • Pagination
      • Pane
      • Sheet
      • Status indicator
      • Stepper
      • Table
      • Tabs
      • Tags
      • Tiles
      • Timeline
      • Tooltip
      • Tooltip dialog
      • Typography
      • Well
    Table of Contents
    • How to use it
      • Default
      • Light mode
      • Language
      • Line highlights
      • Line numbers
      • Size
      • Source diff
    • Configuration
    • API
      • CodeBlock

    Code block

    Code block is used to display text with code formatting. It uses syntax highlighting to make code more legible.


    Table of Contents
    • How to use it
      • Default
      • Light mode
      • Language
      • Line highlights
      • Line numbers
      • Size
      • Source diff
    • Configuration
    • API
      • CodeBlock

    Used for this
    • To display read-only text with code formatting
    • To display code snippets for users to copy
    Not for this
    • For editing code
    • For simple, single-line usage, use the Code component

    How to use it

    Default

    Code block renders code with syntax highlighting.

    Toggle dark mode
    Set primary hue
    Toggle RTL
    Open in CodeSandbox
    Copy code
    View code

    Light mode

    By default, Code block is dark. Shed some light on it using isLight.

    Toggle dark mode
    Set primary hue
    Toggle RTL
    Open in CodeSandbox
    Copy code
    View code

    Language

    Use the language prop to specify the syntax highlighting language. Default is tsx.

    Toggle dark mode
    Set primary hue
    Toggle RTL
    Open in CodeSandbox
    Copy code
    View code

    Line highlights

    Use the highlightLines prop to call attention to particular lines of code.

    Toggle dark mode
    Set primary hue
    Toggle RTL
    Open in CodeSandbox
    Copy code
    View code

    Line numbers

    Line numbers make it easier to reference specific lines of code. You can turn this on with the isNumbered prop.

    Toggle dark mode
    Set primary hue
    Toggle RTL
    Open in CodeSandbox
    Copy code
    View code

    Size

    By default, Code block text is medium-sized, but it can also be small or large.

    Toggle dark mode
    Set primary hue
    Toggle RTL
    Open in CodeSandbox
    Copy code
    View code

    Source diff

    Use Code block to highlight source code changes.

    Toggle dark mode
    Set primary hue
    Toggle RTL
    Open in CodeSandbox
    Copy code
    View code

    Configuration

    • Name9.5.3•View source•View on npm
    • Installnpm install @zendeskgarden/react-typography
    • Depsnpm install react react-dom styled-components @zendeskgarden/react-theming
    • Importimport { CodeBlock } from '@zendeskgarden/react-typography'

    API

    CodeBlock

    Extends HTMLAttributes<HTMLPreElement>

    Prop nameTypeDefaultDescription
    containerProps
    HTMLAttributes<HTMLDivElement>

    Passes props to the code block container

    highlightLines
    number[]

    Determines the lines to highlight

    isLight
    boolean

    Applies light mode styling

    isNumbered
    boolean

    Displays line numbers

    language
    'bash' | 'css' | 'diff' | 'graphql' | 'javascript' | 'json' | 'jsx' | 'markdown' | 'markup' | 'python' | 'typescript' | 'tsx' | 'yaml'
    'tsx'

    Selects the language used by the Prism tokenizer

    size
    'small' | 'medium' | 'large'
    'medium'

    Specifies the font size

    Garden is the design system by Zendesk.
    BlogGitHubVersions
    © Zendesk 2025