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 here
Subtle 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

As Pre for Code Blocks

<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";