---
title: "Code"
description: "Code block with highlighting and copy."
---

> Documentation Index
> Fetch the complete documentation index at: https://gistui.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Code

```gistui
root = Code("const res = await fetch(\"/api/chat\", { method: \"POST\" });\nconst text = await res.text();", lang:"ts", title:"client.ts", numbered)
```

## Signature

This is the line a model reads in the system prompt.

```gistui
Code(code, lang:str, title:str, numbered)
```

- **Group:** Content
- **Children:** No
- **Positional arguments:** `code` (a trailing `?` means it may be left out)

## Props

| Prop | Type | How to write it | Notes |
|---|---|---|---|
| `code` | string | positional, required |  |
| `lang` | string | named: `lang:…` |  |
| `title` | string | named: `title:…` |  |
| `numbered` | flag | bare word: `numbered` |  |

## Use your own component

Keep the name and schema, swap what is drawn. The prompt and the model's output do not change.

### React

```tsx
import { ui } from "@gistui/react/ui";

const lib = ui.extend({ Code: MyCode });
<GistUI library={lib} stream={response.body} />;
```
### Vue

```vue
<GistUI :source="answer" :components="{ Code: MyCode }" />
```
### Svelte

```svelte
<GistUI source={answer} components={{ Code: MyCode }} />
```
### Solid

```tsx
<GistUI source={answer()} components={{ Code: MyCode }} />
```
### Vanilla

```ts
import { ui } from "@gistui/vanilla/ui";

const lib = ui.extend({ Code: (ctx) => ({ el: myElement(ctx) }) });
```

See [Custom components](/docs/guides/custom-components/) for the full contract. Style hook: `[data-gistui="Code"]`.

Source: https://gistui.com/docs/components/content/code/index.mdx
