Code
Inline code element for commands, snippets, and tokenized literals.
pnpm dlx @glinui/cli@latest add codeConfigure retries
Set maxRetries on the client to control how often a failed request is repeated. The default is 3, and requests that return 4xx are never retried.
Override it per call with client.get(url, { maxRetries: 0 }) or set the ACME_MAX_RETRIES variable in your environment.
pnpm acme config set maxRetries 5Installation
pnpm dlx @glinui/cli@latest add codePrefer the package?
Usage
Variants and tones
Surface variants plus tones for status values.
glinrplainsoftoutlineghostsolidaccentsuccesswarningdangerimport { Code } from "@glinui/ui"
export function CodeVariants() { return ( <div className="flex w-full flex-wrap items-center justify-center gap-3 rounded-xl border border-[var(--line-soft)] bg-[var(--surface-1)] p-6"> {(["glinr", "plain", "soft", "outline", "ghost", "solid"] as const).map((variant) => ( <Code key={variant} variant={variant}>{variant}</Code> ))} {(["accent", "success", "warning", "danger"] as const).map((tone) => ( <Code key={tone} variant="soft" tone={tone}>{tone}</Code> ))} </div> )}Variants
The `variant` prop adjusts the surface behind the code token, filled, glass-blurred, border-only, or fully transparent.
import { Code } from "@glinui/ui"
export function CodeVariantDemo() {
return (
<div className="flex flex-wrap gap-3">
<Code variant="default">default</Code>
<Code variant="glass">glass</Code>
<Code variant="outline">outline</Code>
<Code variant="ghost">ghost</Code>
</div>
)
}Sizes
Scale the monospace font with `size`. All three sizes remain optically balanced against body text at the corresponding text scale.
import { Code } from "@glinui/ui"
export function CodeSizeDemo() {
return (
<div className="flex flex-wrap items-center gap-3">
<Code size="sm">sm code</Code>
<Code size="md">md code</Code>
<Code size="lg">lg code</Code>
</div>
)
}Inline in Paragraph
`Code` is designed to sit inside flowing text without disrupting line height. Drop it directly into a `<p>` element alongside prose.
import { Code } from "@glinui/ui"
export function CodeInlineDemo() {
return (
<p className="text-sm leading-relaxed text-neutral-700 dark:text-neutral-300">
Run <Code>pnpm dev</Code> to start the development server, then open{" "}
<Code>http://localhost:3000</Code> in your browser. Set the{" "}
<Code>NODE_ENV</Code> environment variable to <Code>production</Code>{" "}
before deploying.
</p>
)
}Glass Variant in Context
The `glass` variant pairs well with translucent surfaces like cards or overlays.
import { Code } from "@glinui/ui"
export function CodeGlassDemo() {
return (
<p className="text-sm text-neutral-700 dark:text-neutral-300">
Import the hook with{" "}
<Code variant="glass">import {"{ useLiquidGlass }"} from "@glinui/ui"</Code>
{" "}and attach the returned <Code variant="glass">ref</Code> to your element.
</p>
)
}Accessibility
- Uses semantic `<code>` element for inline code fragments.
- `Code` renders a native `<code>` element, which assistive technologies announce as a code region.
- Screen readers may vocalize code content differently, keep snippets short and purposeful.
- Do not use `Code` for decorative styling; only wrap content that is genuinely code or a technical literal.
- Ensure sufficient contrast between the code token and the surrounding prose in all variants.
Reduced Motion
No motion-dependent behavior.
`Code` is a static inline element with no animation. No reduced-motion considerations apply.
API Reference
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
variant | SurfaceVariant | "block" | "default" | "primary" | "secondary" | "destructive" | "success" | "warning" | "info" | "raised" | "frosted" | No | ambient (glinr) | Surface variant. Omit to follow the ambient design style (glinr by default, plain for minimal, glass for glass). |
tone | SurfaceTone | No | neutral | Colour tone for the vocabulary variants. |
size | "sm" | "md" | "lg" | No | md | Font-size scale. |
Source
Import directly from the package or browse the source on GitHub. Click any file to view it.
Generated API Snapshot
Beta
Generated API Snapshot
BetaAuto-extracted from TypeScript source in packages/ui/src/components/code.tsx. This section is in beta and may lag behind hand-curated docs. Regenerate with pnpm --filter @glinui/docs api:generate.
Generated: 2026-10-08T01:41:21.546Z · Full index: /docs/api-metadata
Primary Props Type
CodeProps
CodeProps
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
size | "sm" | "md" | "lg" | No | - | - |
tone | SurfaceTone | No | - | - |
variant | SurfaceVariant | "block" | "default" | "primary" | "secondary" | "destructive" | "success" | "warning" | "info" | "raised" | "frosted" | No | - | Visual variant. Omit for the ambient design style (glinr by default). `block` renders a full width code well: inset well under glinr, flat bordered block under plain. |