# Code

> Syntax-highlighted code with optional line numbers.

- Category: [Rich content](https://tarve.dev/docs.md#rich-content)
- Import: `import { Code } from "@tarve/core";`
- Props type: `CodeProps`
- Source: [packages/core/src/components/rich-content.ts:70](https://github.com/omarcosr/tarve/blob/main/packages/core/src/components/rich-content.ts#L70)

## Usage

```tsx title="Code.tsx"
import { Code } from "@tarve/core";

const code = [
  "export function sum(a: number, b: number) {",
  "  return a + b;",
  "}",
].join("\n");

<Code code={code} language="ts" path="src/sum.ts" showLineNumbers />
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `code` (required) | `string` | — |  |
| `language` | `string` | — | Syntect syntax name, token, or file extension. |
| `path` | `string` | — | Optional path used for extension-based language detection. |
| `showLineNumbers` | `boolean` | — | Paint line numbers as non-selectable chrome. |

### Inherited from `RichProps`

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `syntaxTheme` | `Partial<SyntaxTheme>` | — | Overrides syntax colours without changing parsing or layout. |

## Common props

Shared by every component (descriptions: https://tarve.dev/docs.md#common-props): `class`, `className`, `highlight`, `id`, `key`, `motionFrom`, `onHighlight`, `onPaste`, `onPointerLeave`, `onPointerMove`, `onSize`, `onTransitionEnd`, `rovingGroup`, `style`.

Previous: [Markdown](https://tarve.dev/docs/components/Markdown.md) · Next: [Diff](https://tarve.dev/docs/components/Diff.md)

---

Tarve v0.13.8 · HTML version: https://tarve.dev/docs/components/Code · Index for agents: https://tarve.dev/llms.txt
