# Code

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/code
- **Markdown:** https://refast.fastapicloud.dev/docs/components/code.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/typography/code.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

Syntax-highlighted code display. Renders as inline `<code>` or a full code block.

```python
from refast.components import Code

# Inline code (default)
Code("print('hello')", language="python")

# Code block with line numbers
Code(
    code="def add(a, b):\n    return a + b",
    language="python",
    inline=False,
    show_line_numbers=True,
)
```

```

```

## Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `code` | `str` | *(required)* | The code content to display |
| `language` | `str \| None` | `None` | Language for syntax highlighting (e.g. `"python"`) |
| `inline` | `bool` | `True` | `True` = inline `<code>`, `False` = block |
| `show_line_numbers` | `bool` | `False` | Show line numbers (block mode only) |
| `id` | `str \| None` | `None` | Unique element ID |
| `class_name` | `str` | `""` | Extra Tailwind classes |
| `style` | `dict \| None` | `None` | Inline CSS overrides |

## Inline vs Block

```python
# Inline — for use in prose
Text("Call the ")
Code("render()", language="python")
Text(" function.")

# Block — for code listings
Code(
    code=source_code,
    language="typescript",
    inline=False,
    show_line_numbers=True,
)
```

## Supported Languages

Any language supported by the underlying syntax highlighter, including:
`python`, `typescript`, `javascript`, `tsx`, `jsx`, `bash`, `json`, `yaml`,
`css`, `html`, `sql`, `rust`, `go`, and many more.

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
