Code

Display blocks of code

Basic usage

Display a block of code in the specified language.
Loading view...

Supported languages

The Code component supports the following languages:
  • markup
  • bash
  • clike
  • c
  • cpp
  • css
  • css-extras
  • javascript
  • jsx
  • js-extras
  • js-templates
  • coffeescript
  • diff
  • git
  • go
  • graphql
  • markup-templating
  • handlebars
  • json
  • less
  • makefile
  • markdown
  • objectivec
  • ocaml
  • python
  • reason
  • sass
  • scss
  • sql
  • stylus
  • tsx
  • typescript
  • wasm
  • yaml

Line numbers

Set withLineNumbers to display line numbers.
Loading view...

Component API

NameDescriptionDefault
children
string
The code content.
language
"go" | "markup" | "bash" | "clike" | "c" | "cpp" | "css" | "javascript" | "jsx" | "coffeescript" | "actionscript" | "css-extr" | "diff" | "git" | "graphql" | "handlebars" | "json" | "less" | "makefile" | "markdown" | "objectivec" | "ocaml" | "python" | "reason" | "sass" | "scss" | "sql" | "stylus" | "tsx" | "typescript" | "wasm" | "yaml"
The code language.
withLineNumbers
boolean
Whether to render line numbers.
radius
"xs" | "sm" | "md" | "lg" | "xl"
Border radius of the code block
theme
"light" | "dark"
Theme of the code.
dark
sx
CSSObject
CSS style overrides
width
number | "content" | "auto" | `${number}%` | `${number}/${number}` | { xs?: ColWidth; sm?: ColWidth; md?: ColWidth; lg?: ColWidth; xl?: ColWidth; }
Width of the component. This component must be a direct child of a <Stack> for this prop to take effect. If an integer is specified, signifies the width in a 12 item grid. 12 means that the component takes up the entire row, 6 is half, 1 is 1/12. If a decimal or fraction is specified, signifies the fractional share of the row. e.g. 1/2 takes up half of the row. If a percentage is specified, signifies the percentage share of the row. e.g. "50%" takes up half of the row. content indicates that the component should take up as much space as its content. auto indicates that the component should take any leftover space on the row. To set width based on the screen size, use an object with a specific width for each breakpoint. e.g. {xs: "100%", md: "50%"} sets the width on xs-md screens to 100% and md and larger screens to 50%.
content
offset
number | `${number}%` | `${number}/${number}` | { xs?: ColOffset; sm?: ColOffset; md?: ColOffset; lg?: ColOffset; xl?: ColOffset; }
Creates a gap to the left of the component. Has the same units as width. This component must be a direct child of a <Stack> for this prop to take effect. If an integer is specified, signifies the offset in a 12 item grid. 6 means the component is offset by half a row, 1 is 1/12 of a row. If a decimal or fraction is specified, signifies the fractional share of the row. e.g. 1/2 offsets a component by half of the row. If a percentage is specified, signifies the percentage share of the row. e.g. "50%" offsets a component by half of the row. To set offset based on the screen size, use an object with a specific offset for each breakpoint. e.g. {xs: "50%", md: "0%"} sets the offset on xs-md screens to 50% and md and larger screens to 0%.