---
title: "Code"
description: "Shows a command, a file name, or a prop inside a sentence. The chip takes the size of the text around it, and it can color the code."
url: https://gelatinui.com/components/code
markdown_url: https://gelatinui.com/components/code.md
access: free
install: "npx shadcn@latest add @gelatin-ui/code"
registry_item: https://gelatinui.com/r/code.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Code

> Shows a command, a file name, or a prop inside a sentence. The chip takes the size of the text around it, and it can color the code.

Page: https://gelatinui.com/components/code

## When to use it

Best for: A command, a prop, or a file name in running text, in a chip that follows the text size.

- Use `lang` to highlight a short piece of code.
- Use `size="xs"` for a fixed 12/16 chip in a row or a cell.

## When not to use it

- For a block of code, use a [Code Block](https://gelatinui.com/components/code-block.md).

## Notes for agents

- It is the native `code` element with no hooks and no state, so it renders on a server.
- `palette` is `ink`, `color`, or `theme`, as in Code Block.
- Text from JSX parts joins into one string before it is highlighted.

## Anatomy

```text
Code
```

## API reference

### CodeTokens

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `nodes` | `readonly HighlightRenderNode[]` |  | The nodes of `renderTokens` from |

### Code

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `lang` | `string` |  | Highlight the text in this language (a name or alias that `highlighter` knows). Works when the children are text (strings and numbers). Without it the code is plain ink. |
| `palette` | `"color" \| "ink" \| "theme"` |  |  |
| `size` | `"default" \| "xs"` |  |  |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Code | `code` |  |  |  |

## Usage

Put the code text inside, and set `lang` to color it.

```tsx title="install-note.tsx"
import { Code } from "@/components/ui/code";

export function InstallNote() {
  return (
    <p className="text-sm leading-6">
      Run{" "}
      <Code lang="bash" palette="color">
        bun add @tanstack/highlight
      </Code>{" "}
      once, then restart the dev server.
    </p>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/code
```

It adds 7 registry items: 6 files, 642 lines, and the npm packages `@tanstack/highlight`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Mark](https://gelatinui.com/components/mark.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Code Block](https://gelatinui.com/components/code-block.md)
- [Kbd](https://gelatinui.com/components/kbd.md)

## Accessibility

It renders the native `code` element.

A long value breaks at any character, so it does not push the page wider.
