Inline code — a <code> fragment set in the mono face on a tinted, hairline-bordered chip. Sized xs–xl so a snippet tracks the surrounding text; data-density scales each size further.
Registry-only
No headless primitive — this component ships only as a copied styled file, so there is no Headless mode. primitiv add inline-code installs it whichever mode you are reading.
No headless primitive — this one ships only as a copied styled surface, so primitiv add is the only way in, whichever mode you are reading.
Props
Generated from the copied file’s props type and contract.json. Never hand-maintained.
InlineCode
Extends HTMLElement — every native attribute of that element is accepted and forwarded.
Prop
Type
Default
Description
asChild
boolean
—
Render the single child element instead of a wrapping <code>, merging the
inline-code classes onto it — e.g. <InlineCode asChild><kbd>...</kbd></InlineCode>.
size
"xs" | "sm" | "md" | "lg" | "xl"
md
Snippet size; data-density scales each size further.
Styling contract
10 CSS custom properties on .primitiv-inline-code — mode-agnostic. These names are the stable surface; the values are not.
InlineCode renders a real <code> element, so assistive tech treats it as code rather than emphasised prose — the semantics are the element's, not a style.
It is presentational by default and adds no ARIA. Under asChild the semantics are whatever element you supply — a rendered <a> stays a link.
The chip is tint + a hairline border, not colour alone, so the distinction from surrounding text survives for low-vision readers and does not lean on a single hue.
Examples
Every example below reacts to the density control. Currently showing Styled mode.
Inline in text
A <code> fragment for a value, identifier or path named in running text — useState, --primitiv-space-16, package.json. It reads as code without breaking the line. Reach for Kbd instead when the thing is a key to press.
Every component is imported from @primitiv-ui/react, and its class is .primitiv-button.
import{InlineCode}from"@/components/ui/inline-code";<p> Import it from <InlineCode>@primitiv-ui/react</InlineCode>.</p>
Sizing to the text
size tracks the type around the chip — sm beside body text, xs inside a caption or a table cell — so the code never looms larger than the words it sits among. It inherits nothing from context, so set size at each call site.
asChild renders your own element with the code styling merged on — a <code> fragment that is also a link to an API reference, say. The chip's look transfers to the element you supply.