---
title: "Code from files"
subtitle: "<Code> reads a project file or URL at build time and highlights it."
---

Reads a file from your project (or a URL) at build time and highlights it, keeping docs in sync with real code:

```mdx
<Code src="/docs.yml" lines="1-6" title="docs.yml (this site, first 6 lines)" />
```

<Code src="/docs.yml" lines="1-6" title="docs.yml (this site, first 6 lines)" />

<ParamField path="src" type="string" required>File path (a leading `/` means the project root; otherwise relative to the project root or the current page), or a public `https://` URL (downloaded at build time, 8-second timeout; local and private-network addresses aren't allowed).</ParamField>
<ParamField path="lines" type="string | array">Show only these lines, e.g. `"1-6"`, `{["1-3", 8]}`.</ParamField>
<ParamField path="language" type="string">Language; inferred from the extension by default.</ParamField>

All `CodeBlock` props are supported too (`title`, `highlight`, `focus`, `startLine`, `maxLines`, `wordWrap`, `showLineNumbers`, `for`, `links`, `collapsible`). A missing file produces a `code/src` warning.

<Warning>
  Use a string or an array of strings for line props. In `lines={[1-3]}`, `1-3` is a subtraction expression and is rejected by the safe subset (an `mdx/attribute` error).
</Warning>
