Skip to content

Basic Components

[02] Basic Components

Button

Button triggers an action or event when clicked. It can contain text, an icon, or both, and is a primary way for users to interact with the app.

SourceEdit this page

Use Button for actions, Link for an in-prose hyperlink, and NavLink for a sidebar or navigation item. An action shown only as an icon goes in an IconButton. Button renders a native <button>, or an <a> when href is set. It sets no type, so a Button inside a <form> submits the form: pass type="button" on every button that does anything else, as the Forms guide shows. A disabled or loading Button with an href drops the href but stays focusable, marked with aria-disabled.

Basic usage

Button triggers an action when the user clicks it; each appearance prop maps to a semantic color from the active theme.

<Row flexWrap>
<Button primary>primary</Button>
<Button accent>accent</Button>
<Button secondary>secondary</Button>
<Button tertiary>tertiary</Button>
<Button success>success</Button>
<Button danger>danger</Button>
<Button warning>warning</Button>
<Button info>info</Button>
<Button inheritAppearance>inheritAppearance</Button>
</Row>

Sizes

Buttons come in five sizes: xs, sm (default), md, lg, xl. Size drives font-size, padding, gap, and border-radius simultaneously via CSS variables.

<Row flexWrap>
<Button xs>xs</Button>
<Button sm>sm</Button>
<Button md>md</Button>
<Button lg>lg</Button>
<Button xl>xl</Button>
</Row>

Variants

Buttons can be styled as filled, outline (default), or ghost.

<Col>
<Row flexWrap>
<Button filled primary>primary</Button>
<Button filled accent>accent</Button>
<Button filled secondary>secondary</Button>
</Row>
<Row flexWrap>
<Button primary>primary</Button>
<Button accent>accent</Button>
<Button secondary>secondary</Button>
</Row>
<Row flexWrap>
<Button ghost primary>primary</Button>
<Button ghost accent>accent</Button>
<Button ghost secondary>secondary</Button>
</Row>
</Col>

Shapes

Button supports three border-radius styles: rounded (default), pill, and sharp.

<Row flexWrap>
<Button pill>Subscribe</Button>
<Button sharp>Subscribe</Button>
<Button rounded>Subscribe</Button>
</Row>

With icon

Drop an icon directly inside the button. gap is on by default, so spacing is automatic.

<Row flexWrap>
<Button><Download/> Download</Button>
<Button success filled><Check/> Saved</Button>
<Button danger><Trash2/> Delete</Button>
<Button secondary>Next <ArrowRight/></Button>
</Row>

Sizes with icon

The same size matrix paired with an inline icon.

<Row flexWrap>
<Button xs><Star/> Extra Small</Button>
<Button sm><Star/> Small</Button>
<Button md><Star/> Medium</Button>
<Button lg><Star/> Large</Button>
<Button xl><Star/> Extra Large</Button>
</Row>

Font weights

Buttons default to fontSemibold. Use any of the standard weight props to override.

<Row flexWrap>
<Button fontThin>Submit</Button>
<Button fontExtralight>Submit</Button>
<Button fontLight>Submit</Button>
<Button fontNormal>Submit</Button>
<Button fontMedium>Submit</Button>
<Button fontSemibold>Submit</Button>
<Button fontBold>Submit</Button>
<Button fontExtrabold>Submit</Button>
<Button fontBlack>Submit</Button>
</Row>

As Link and disabled

Pass href to render the button as an <a> for navigation. Use disabled to prevent interaction.

Link ButtonSuccess Link
<Row flexWrap>
<Button href="#">Link Button</Button>
<Button success filled href="#">Success Link</Button>
<Button disabled>Disabled</Button>
<Button danger filled disabled>Disabled Danger</Button>
</Row>

Loading state

Set loading to swap the label for a spinner and auto-disable the button. The width is kept, so the layout does not jump when the state flips.

<Row flexWrap itemsCenter>
<Button loading>Saving</Button>
<Button loading filled danger>Deleting</Button>
<Button loading lg>Large</Button>
</Row>

The ring is the Spinner component, so there is one spinner in the library and restyling theme.spinner restyles both. The button forwards its own size, and the ring inherits the button's text colour: a filled button gets a light ring, an outline button a dark one.

It is decorative here rather than a live region. The button already carries aria-busy, so the Spinner's role="status" is suppressed and the accessible name stays the button's own.

const [loading, setLoading] = useState(false);
return (
<Button loading={loading} onClick={() => setLoading(true)}>
Submit
</Button>
);

Next.js Link integration

Use the tag prop to render the button as a Next.js Link for client-side navigation.

import Link from 'next/link';
import { Button } from '@vaneui/ui';
<Button href="/docs" tag={Link}>Documentation</Button>

How Button centers its label

A browser centers the line box of a font, and that box is rarely even around the letters. A label therefore sits a fraction of a pixel above or below the middle of its button, in a direction that depends on the font. Since 1.7.0, Button renders each run of its own text in a <span class="vane-text-run">, and the stylesheet trims that span to the height of the capital letters with text-box. The label sits in the middle with any font, and the button keeps its size.

<Button><Download/> Download</Button>
<button class="vane-button ...">
<svg></svg>
<span class="vane-text-run"> Download</span>
</button>

IconButton, Badge, Chip, Alert, Tooltip and the items and labels of a Menu wrap their text the same way. NavLink trims the label span it already renders. The markup has three consequences:

  • In a test, find the component by its role or its class, for example getByRole('button', { name: 'Download' }). getByText('Download') returns the span, not the button.
  • Text passed as an element (a translation component, a fragment, a <span> of your own) is not wrapped and renders where the line box of the font puts it. Give your own span className="vane-text-run" to center it the same way.
  • The trim needs the CSS text-box property: Chrome and Edge 133, Safari 18.2 or Firefox 154. An older browser renders the span without the trim, so the text stays where it was before 1.7.0.

Customizing

Set app-wide Button defaults with ThemeProvider's themeDefaults:

<ThemeProvider themeDefaults={{
button: { main: { primary: true, lg: true, filled: true } },
}}>
<Button>Submit</Button>
</ThemeProvider>

Add prop-conditional classes with extraClasses, applied whenever the matching boolean prop is active. For compound themes like Button, nest the prop-class map under the sub-theme name (main for Button's primary surface):

<ThemeProvider extraClasses={{
button: {
main: {
primary: 'shadow-lg hover:shadow-xl transition-shadow',
danger: 'animate-pulse',
},
},
}}>
<Button primary>Glowing Primary</Button>
</ThemeProvider>

Frequently asked questions

Why do my Button theme defaults have no effect?

Button's theme has sub-themes, so its defaults sit one level down, under main: write themeDefaults={{ button: { main: { filled: true } } }}, not { button: { filled: true } }. The flat form matches no theme node and does nothing, and a development build logs a console warning about it. IconButton has a theme node of its own, iconButton, so set both when the two should match.

How do I make a Button full width?

Pass wFull. Button defaults to wFit, so it is as wide as its label wherever it sits. For a button that fills its container only on small screens, use mobileWFull (below 768px) or tabletWFull (below 1024px), and it keeps its fit width above that. In your own Tailwind build, the responsive props need the @vaneui/ui/tokens import from the installation guide.

How do I make a Button as tall as the Input next to it?

Give both the same size prop. Button, IconButton, Input and Select all default to sm and share one height scale, so a field and a button written without a size prop line up in a Row. When you change one, such as <Input md>, pass the same prop to the other (<Button md>). A Field passes its size to the control inside it, but not to a Button placed beside it.

Can I wrap a Button in a Next.js Link?

No. A <button> inside an <a> nests two interactive elements, which HTML does not allow and which confuses keyboard and screen reader users. Pass href and tag={Link} to the Button instead, so it renders a single anchor through Next.js Link, as Next.js Link integration shows. A Button that only runs code takes onClick and no href.

Button Props

PropCategoryDefaultDescription
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 (= flex-1, i.e. flex: 1 1 0%)

flexAuto

Flex

Grow but respect intrinsic size (= flex-auto, i.e. flex: 1 1 auto)

flexNone

Flex

Don't grow and don't shrink (= flex-none, i.e. flex: none)

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 (= shrink-0)

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.

PropCategoryDefaultDescription
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)