Code
Code shows a short piece of code inside a line of text, in the mono font with a light fill behind it.
Code shows a short piece of code inside a line of text, such as a command, a file name or a value. It uses the mono font with a light fill behind it.
Use Code for code that sits inside a sentence. For code on several lines, use a CodeBlock, and for a key or a keyboard shortcut, use a Kbd.
size is optional. When you don't set it, the code takes the size of the line it sits in, so it stays small in a caption and grows in a heading. Only set size when the code stands on its own.
emphasis changes the text colour, just as it does on Text. The default is loud, because faded code is harder to read. tone changes both the text and the fill, so use it when the value itself has a meaning, such as an error code or a success status. The default tone is neutral.
Code renders a <code> element, which a screen reader reads as ordinary text. Use render when the document needs another element, such as <samp> for program output.
Props
Generated from the types. It lists what this component DECLARES: a prop that arrives from a shared type or from the platform is real and is not repeated here.
| Prop | Type | What it does |
|---|---|---|
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
emphasis? | "loud" | "medium" | "quiet" | The emphasis level of the text: loud, medium or quiet. |
render? | RenderElement | Renders the code as a different element. |
size? | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | The text size step, from 1 to 9. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
tone? | "neutral" | "accent" | "destructive" | "blue" | "green" | "orange" | "amber" | "pink" | "purple" | "success" | "warning" | "info" | The colour family of the text and the fill. |
weight? | "regular" | "medium" | "semibold" | The font weight, by name. |
It also takes every prop of a <code>.
- A fill that gets louder with emphasis —
emphasischanges the text colour on Code just as it does on Text. If it changed the fill as well, the same prop would mean two different things. - Block code — Code on several lines needs wrapping, scrolling and a height limit, which an inline element can't provide. Use a CodeBlock for that.