Basic Components
[02] Basic Components
Code
Renders inline code snippets in a themed monospace surface. Use for commands, file paths, or technical terms in prose; renders as an anchor when given href.
Code sets apart the parts of a sentence that a reader would type or copy, such as a package name, a hook or a prop value. It renders a native <code> whose text does not wrap, so it suits short snippets rather than multi-line listings. For keys the reader presses, use Kbd, and for a phrase that only needs emphasis, a Mark highlight.
Basic usage
Inline code snippets with default styling. Code aligns to the surrounding text's baseline, so it lines up with the text it's inlined in. Pass href to render Code as <a> instead of <code>. A focus-visible outline auto-enables when href is set.
Run npm install to install packages.
Declare a constant with const x = 'value'.
<Col> <Text>Run <Code>npm install</Code> to install packages.</Text> <Text>Declare a constant with <Code>{"const x = 'value'"}</Code>.</Text></Col>Sizes
Code elements in different sizes: xs, sm, md, lg, xl.
Size xs: console.log('Hello')
Size sm: console.log('Hello')
Size md: console.log('Hello')
Size lg: console.log('Hello')
Size xl: console.log('Hello')
<Col> <Text>Size xs: <Code xs>{"console.log('Hello')"}</Code></Text> <Text>Size sm: <Code sm>{"console.log('Hello')"}</Code></Text> <Text>Size md: <Code md>{"console.log('Hello')"}</Code></Text> <Text>Size lg: <Code lg>{"console.log('Hello')"}</Code></Text> <Text>Size xl: <Code xl>{"console.log('Hello')"}</Code></Text></Col>Appearances
Different appearance colors for inline code.
primary codeaccent codesecondary codetertiary codesuccess codedanger codewarning codeinfo codeinheritAppearance code<Row flexWrap> <Code primary>primary code</Code> <Code accent>accent code</Code> <Code secondary>secondary code</Code> <Code tertiary>tertiary code</Code> <Code success>success code</Code> <Code danger>danger code</Code> <Code warning>warning code</Code> <Code info>info code</Code> <Code inheritAppearance>inheritAppearance code</Code></Row>Variants
Code defaults to outline variant. Use filled for stronger visual emphasis.
Default outline: npm install then npm run build
Filled: git commit then git push
Colored filled: 200 OK 500 Error deprecated
<Col> <Text>Default outline: <Code>npm install</Code> then <Code>npm run build</Code></Text> <Text>Filled: <Code filled>git commit</Code> then <Code filled>git push</Code></Text> <Text>Colored filled: <Code success filled>200 OK</Code> <Code danger filled>500 Error</Code> <Code warning filled>deprecated</Code></Text></Col>Shapes
Code supports rounded (default), pill, and sharp border-radius styles.
roundedpillsharp<Row flexWrap> <Code rounded>rounded</Code> <Code pill>pill</Code> <Code sharp>sharp</Code></Row>Code in context
Code elements used within text content.
To create a new React component, use function Component() {} or the arrow function syntax const Component = () => {}.
Install the package with npm i @vaneui/ui and then import it using import { Button } from "@vaneui/ui".
The useState hook returns an array with two elements: the current state value and a setter function like [state, setState].
<Col> <Text> To create a new React component, use <Code>{"function Component() {}"}</Code> or the arrow function syntax <Code>{"const Component = () => {}"}</Code>. </Text> <p> Install the package with <Code primary>npm i @vaneui/ui</Code> and then import it using <Code secondary>{'import { Button } from "@vaneui/ui"'}</Code>. </p> <Text> The <Code info>useState</Code> hook returns an array with two elements: the current state value and a setter function like <Code info>[state, setState]</Code>. </Text></Col>In heading context
Code uses an em-based geometry pipeline: at the default md size it renders at ~87.5% of the surrounding text's font-size, with padding and border-radius scaling proportionally. The same <Code> looks right inside body copy, a subheading, a section heading, or a page title.
Body text with npm install inline.
npm run build first.useState hook@vaneui/ui<Col> <Text>Body text with <Code>npm install</Code> inline.</Text> <Title>Subheading: run <Code>npm run build</Code> first.</Title> <SectionTitle>Section: <Code>useState</Code> hook</SectionTitle> <PageTitle><Code>@vaneui/ui</Code></PageTitle></Col>As Link
Add href to render the Code element as an <a> tag. A keyboard focus-visible outline auto-renders so the link is reachable via Tab; opt out with noFocusVisible.
Install @vaneui/ui from npm.
The useState hook returns a value and a setter.
See the install guide for setup steps.
<Col> <Text>Install <Code href="https://npmjs.com/package/@vaneui/ui" target="_blank" rel="noopener noreferrer">@vaneui/ui</Code> from npm.</Text> <Text>The <Code href="https://react.dev/reference/react/useState" target="_blank" rel="noopener noreferrer" info>useState</Code> hook returns a value and a setter.</Text> <Text>See the <Code href="/docs/getting-started/installation" filled success>install guide</Code> for setup steps.</Text></Col>Next.js Link integration
Use the tag prop to render Code as a Next.js Link for client-side navigation.
import Link from 'next/link';import { Code, Text } from '@vaneui/ui';
<Text> Read the <Code href="/docs/getting-started" tag={Link}>getting started guide</Code> for setup steps.</Text>Frequently asked questions
How do I show a multi-line code block?
Code is for inline snippets: it renders a <code> whose text does not wrap. For a listing of several lines, render a <pre> through your own syntax highlighter, or a Text with tag="pre" and fontMono for plain output such as a log. With @vaneui/md, a fenced code block in Markdown renders as a code block on its own.
Why does inline code overflow its container on a phone?
Code defaults to whitespaceNowrap, so a long command or package name never breaks and can run past a narrow column. Pass whitespaceNormal to let it wrap at spaces, and add breakWords or breakAll for a long string with no spaces, such as a URL or a hash. Code takes the same whitespace and wordBreak props as the other inline components.
Why is inline code gray when I set no appearance?
Code defaults to the secondary appearance, a neutral tint. Pass another appearance, such as info or success, on a snippet that should stand out, as in Appearances. To change the default for an app, set themeDefaults={{ code: { info: true } }} on a ThemeProvider; Code has a flat theme node.
Code Props
| Prop | Category | Default | Description |
|---|---|---|---|
accent | Appearance | Accent color appearance (rose) | |
danger | Appearance | Danger color appearance (red) | |
info | Appearance | Info color appearance (cyan) | |
inheritAppearance | Appearance | Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables | |
primary | Appearance | Primary color appearance (gray) | |
secondary | Appearance | ✓ | Secondary color appearance (gray) |
success | Appearance | Success color appearance (green) | |
tertiary | Appearance | Tertiary color appearance | |
warning | Appearance | Warning color appearance (amber) | |
disabled | Disabled | Disable the component — reduces opacity, changes cursor to not-allowed, and prevents interaction | |
flex1 | Flex | Take up remaining space (= | |
flexAuto | Flex | Grow but respect intrinsic size (= | |
flexNone | Flex | Don't grow and don't shrink (= | |
fontHeading | Font Family | Heading font family (defaults to sans, customizable via --font-heading) — emits font-heading | |
fontMono | Font Family | ✓ | Monospace font family — emits font-mono |
fontSans | Font Family | Sans-serif font family (default) — emits font-sans | |
fontSerif | Font Family | Serif font family — emits font-serif | |
italic | Font Style | Italic font style | |
notItalic | Font Style | Not italic (normal) font style | |
fontBlack | Font Weight | Black font weight (900) — emits font-black | |
fontBold | Font Weight | Bold font weight (700) — emits font-bold | |
fontExtrabold | Font Weight | Extra bold font weight (800) — emits font-extrabold | |
fontExtralight | Font Weight | Extra light font weight (200) — emits font-extralight | |
fontLight | Font Weight | Light font weight (300) — emits font-light | |
fontMedium | Font Weight | Medium font weight (500) — emits font-medium | |
fontNormal | Font Weight | ✓ | Normal font weight (400) — emits font-normal |
fontSemibold | Font Weight | Semibold font weight (600) — emits font-semibold | |
fontThin | Font Weight | Thin font weight (100) — emits font-thin | |
inheritSize | Inherit Size | Inherit font-size and line-height from the nearest parent typography element | |
noInheritSize | Inherit Size | Keep own font-size; do not inherit from parent | |
noPadding | Padding | Disable internal padding | |
padding | Padding | ✓ | Enable internal padding |
paddingX | Padding | Enable only horizontal padding | |
paddingY | Padding | Enable only vertical padding | |
pill | Shape | Fully rounded corners (circular) | |
rounded | Shape | ✓ | Medium rounded corners (default) |
sharp | Shape | No rounded corners (square) | |
noShrink | Shrink | Prevent the flex item from shrinking below its content size (= | |
lg | Size | Large size | |
md | Size | ✓ | Medium size (default) |
sm | Size | Small size | |
xl | Size | Extra large size | |
xs | Size | Extra small size | |
skeleton | Skeleton | Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too | |
textCenter | Text Align | Align text to center | |
textEnd | Text Align | Align text to the reading-direction end (right in LTR, left in RTL) | |
textJustify | Text Align | Justify text | |
textLeft | Text Align | Align text to left (physical side, does not flip under RTL) | |
textRight | Text Align | Align text to right (physical side, does not flip under RTL) | |
textStart | Text Align | Align text to the reading-direction start (left in LTR, right in RTL) | |
lineThrough | Text Decoration | Add strikethrough/line-through decoration across text | |
noUnderline | Text Decoration | Remove ALL text-decoration — underline, line-through, and overline (text-decoration: none) | |
overline | Text Decoration | Add overline decoration above text | |
underline | Text Decoration | Add underline decoration below text | |
capitalize | Text Transform | Capitalize first letter of each word | |
lowercase | Text Transform | Transform text to lowercase | |
normalCase | Text Transform | Normal text case (no transformation) | |
uppercase | Text Transform | Transform text to uppercase | |
filled | Variant | Filled variant - solid background with contrasting text color | |
ghost | Variant | Ghost variant - transparent background, no border, appearance-colored text, tinted hover background | |
outline | Variant | ✓ | Outline variant - transparent background with border and colored text (default) |
breakAll | Word Break | Break between any two characters - word-break: break-all | |
breakKeep | Word Break | Do not break CJK text - word-break: keep-all | |
breakNormal | Word Break | Reset breaking - overflow-wrap and word-break normal | |
breakWords | Word Break | Break long words to prevent overflow - overflow-wrap: break-word |
Layout & utility props (gap, padding, hide, items, justify, ...)
Documented on Common Props.
| Prop | Category | Default | Description |
|---|---|---|---|
border | Border | Enable border on all sides | |
borderB | Border | Enable border on bottom | |
borderEnd | Border | Enable border on the inline-end side (right in LTR, left in RTL) | |
borderL | Border | Enable border on left | |
borderR | Border | Enable border on right | |
borderStart | Border | Enable border on the inline-start side (left in LTR, right in RTL) | |
borderT | Border | Enable border on top | |
borderX | Border | Enable border on left and right | |
borderY | Border | Enable border on top and bottom | |
noBorder | Border | Disable all borders | |
cursorDefault | Cursor | Default cursor - standard arrow | |
cursorMove | Cursor | Move cursor - indicates draggable element | |
cursorNone | Cursor | No cursor - hides the cursor | |
cursorNotAllowed | Cursor | Not-allowed cursor - indicates disabled state | |
cursorPointer | Cursor | Pointer cursor - indicates clickable element | |
cursorText | Cursor | Text cursor - indicates selectable text | |
cursorWait | Cursor | Wait cursor - indicates loading/processing | |
block | Display | Block display - takes full width, new line | |
contents | Display | Contents display - element's box is removed, children display as if parent didn't exist | |
flex | Display | Flex display - flexbox container | |
grid | Display | Grid display - CSS grid container | |
hidden | Display | Hidden display - element is not visible | |
inline | Display | ✓ | Inline display - flows with text |
inlineBlock | Display | Inline-block display - inline but with block properties | |
inlineFlex | Display | Inline-flex display - inline flexbox container | |
inlineGrid | Display | Inline-grid display - inline grid container | |
table | Display | Table display - behaves like table element | |
tableCell | Display | Table-cell display - behaves like td element | |
column | Flex Direction | Flex direction column (vertical) | |
columnReverse | Flex Direction | Flex direction column-reverse | |
row | Flex Direction | Flex direction row (horizontal) | |
rowReverse | Flex Direction | Flex direction row-reverse | |
focusVisible | Focus Visible | Enable focus-visible outline | |
noFocusVisible | Focus Visible | Disable focus-visible outline | |
gap | Gap | Enable gap spacing between children, at the component's size | |
gapLg | Gap | Large gap, whatever the component's size | |
gapMd | Gap | Medium gap, whatever the component's size | |
gapSm | Gap | Small gap, whatever the component's size | |
gapXl | Gap | Extra-large gap, whatever the component's size | |
gapXs | Gap | Extra-small gap, whatever the component's size | |
noGap | Gap | Disable gap spacing | |
hAuto | Height | Set height to auto | |
hFit | Height | ✓ | Set height to fit-content |
hFull | Height | Set height to 100% | |
hScreen | Height | Set height to 100vh (viewport height), removes max-height constraint | |
desktopHide | Hide | Hide element on desktop devices and below (max-desktop: 80rem) | |
mobileHide | Hide | Hide element on mobile devices and below (max-mobile: 48rem) | |
tabletHide | Hide | Hide element on tablet devices and below (max-tablet: 64rem) | |
itemsBaseline | Items | Align items to baseline | |
itemsCenter | Items | Align items to center | |
itemsEnd | Items | Align items to end (bottom/right) | |
itemsStart | Items | Align items to start (top/left) | |
itemsStretch | Items | Stretch items to fill container | |
justifyAround | Justify | Distribute items with space around them | |
justifyBaseline | Justify | Align items along their baseline on main axis | |
justifyBetween | Justify | Distribute items with space between them | |
justifyCenter | Justify | Center items along the main axis | |
justifyEnd | Justify | Pack items toward the end of the main axis | |
justifyEvenly | Justify | Distribute items with equal space around them | |
justifyStart | Justify | Pack items toward the start of the main axis | |
justifyStretch | Justify | Stretch items to fill the main axis | |
overflowAuto | Overflow | Auto overflow - show scrollbars if needed | |
overflowClip | Overflow | Clip overflow - hard clip without scrollbars | |
overflowHidden | Overflow | Hidden overflow - clip content without scrollbars | |
overflowScroll | Overflow | Scroll overflow - always show scrollbars | |
overflowVisible | Overflow | Visible overflow - content extends beyond bounds | |
overflowXAuto | Overflow | Auto overflow on X-axis only | |
overflowXClip | Overflow | Clip overflow on X-axis only | |
overflowXHidden | Overflow | Hidden overflow on X-axis only | |
overflowXScroll | Overflow | Scroll overflow on X-axis only | |
overflowXVisible | Overflow | Visible overflow on X-axis only | |
overflowYAuto | Overflow | Auto overflow on Y-axis only | |
overflowYClip | Overflow | Clip overflow on Y-axis only | |
overflowYHidden | Overflow | Hidden overflow on Y-axis only | |
overflowYScroll | Overflow | Scroll overflow on Y-axis only | |
overflowYVisible | Overflow | Visible overflow on Y-axis only | |
absolute | Position | Absolute positioning | |
fixed | Position | Fixed positioning | |
relative | Position | Relative positioning | |
static | Position | Static positioning | |
sticky | Position | Sticky positioning at the top edge; set --sticky-top to stick below a fixed header | |
responsiveSizing | Responsive Sizing | Enable responsive sizing - uses breakpoint-specific classes for font size, padding, and gap | |
desktopWFull | Responsive Width | Set width to 100% on desktop and below, below 1280px (max-desktop: 80rem) | |
mobileWFull | Responsive Width | Set width to 100% on mobile, below 768px (max-mobile: 48rem) | |
tabletWFull | Responsive Width | Set width to 100% on tablet and below, below 1024px (max-tablet: 64rem) | |
insetRing | Ring | Enable the inset ring — emits ring-inset | |
noInsetRing | Ring | ✓ | Disable the inset ring |
noShadow | Shadow | Disable drop shadow | |
shadow | Shadow | Enable drop shadow at the component's size | |
shadowLg | Shadow | Large drop shadow, whatever the component's size | |
shadowMd | Shadow | Medium drop shadow, whatever the component's size | |
shadowSm | Shadow | Small drop shadow, whatever the component's size | |
shadowXl | Shadow | Extra-large drop shadow, whatever the component's size | |
shadowXs | Shadow | Extra-small drop shadow, whatever the component's size | |
desktopShow | Show | Show element only on desktop and below, below 1280px (hidden from 80rem up) | |
mobileShow | Show | Show element only on mobile, below 768px (hidden from 48rem up) | |
tabletShow | Show | Show element only on tablet and below, below 1024px (hidden from 64rem up) | |
noTransition | Transition | Disable transitions for instant state changes | |
transition | Transition | ✓ | Enable smooth transitions between states |
transparent | Transparent | Disable background color - makes component background transparent | |
whitespaceBreakSpaces | Whitespace | Preserve whitespace incl. trailing spaces, wrap text (white-space: break-spaces) | |
whitespaceNormal | Whitespace | Normal wrapping - default browser behavior | |
whitespaceNowrap | Whitespace | ✓ | No wrap - text stays on single line |
whitespacePre | Whitespace | Preserve whitespace and line breaks | |
whitespacePreLine | Whitespace | Preserve line breaks, collapse spaces, wrap text | |
whitespacePreWrap | Whitespace | Preserve whitespace, wrap text | |
wAuto | Width | Set width to auto | |
wFit | Width | ✓ | Set width to fit-content |
wFull | Width | Set width to 100% | |
wScreen | Width | Set width to 100vw (viewport width), removes max-width constraint | |
flexNoWrap | Wrap | Force flex items to stay on single line (may overflow) | |
flexWrap | Wrap | Allow flex items to wrap to new lines when container is too narrow | |
flexWrapReverse | Wrap | Wrap flex items in reverse order (last items wrap first) |