Skip to main content

Code

Code is an inline code styling component with monospace font and optional background.

Open in Storybook

Import​

import { Code } from "@tosui/react";

Basic usage​

Variants​

Plain variant: code hereSubtle variant: code here

Colors​

Default colorPrimary colorAccent colorSuccess colorError color

Sizes​

Extra smallSmallMediumLarge

Common patterns​

Inline code in documentation​

Use the useState hook to manage component state. Import it from react.

Keyboard shortcuts​

Press Ctrl + C to copy.

File paths​

Edit the configuration in src/config/settings.ts

Render a code block​

<Code as="pre" variant="subtle" p={4} display="block" overflow="auto">
{`function greet(name) {
return \`Hello, \${name}!\`;
}`}
</Code>

Props reference​

PropTypeDefaultDescription
variant"plain" | "subtle""plain"Visual variant
size"xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl"-Font size
colorstring-Text color (semantic color token)
asElementType"code"HTML element to render

Code also accepts most Box props.

TypeScript​

import { Code, type CodeVariant, type CodeProps, type CodeOwnProps } from "@tosui/react";