Skip to main content

Component | Code

Render a formatted code block.

ui.code(`
function add(a, b) {
return a + b;
}

const result = add(1, 2);
`)

Syntax Highlighting

Compose will try it's best to infer the language automatically. You can also specify the language manually using the lang property.

type LanguageName =
| "ada" | "clojure" | "coffeescript" | "dart" | "django"
| "dockerfile" | "dust" | "elixir" | "elm" | "erlang"
| "graphql" | "haskell" | "java" | "javascript" | "julia"
| "kotlin" | "python" | "typescript" | "json" | "html"
| "css" | "scss" | "jsx" | "bash" | "c" | "c++" | "csharp"
| "go" | "markdown" | "php" | "ruby" | "rust" | "sql"
| "swift" | "xml" | "yaml" | "zig" | "r"

API reference

Function signature

ui.code(
text: string,
options?: {
label?: string,
description?: string,
lang?: "ada" | "clojure" | "coffeescript" | /* ... */ | "r"
style?: Style
}
)

Parameters

text

required string
The code to format and display.

properties.label

optional string
Display a label above the code block.

properties.description

optional string
Display a description between the label and the code block.

properties.lang

optional string literal
The language to use for syntax highlighting. If not specified, Compose will attempt to infer the language from the code.

properties.style

optional Style

Directly style the underlying element using CSS. See the styling guide for more details on available style properties.