Playground

Icon button

A square button holding only an icon. The accessible name is required.

  • Built on native elements
  • Native button; aria-label is required by the type.
  • Space and Enter activate it.
  • Styles in one file: 02-buttons.css

Import

import '@monoline/css';
import {IconButton} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add icon-button

Usage

import {IconButton} from '@monoline/react';

const Plus = () => <svg aria-hidden="true" viewBox="0 0 12 12" width="12" height="12"><path d="M6 1v10M1 6h10" stroke="currentColor" fill="none" /></svg>;

<div style={{display: 'flex', gap: 'var(--s3)'}}>
  <IconButton aria-label="Add">
    <Plus />
  </IconButton>
  <IconButton variant="solid" aria-label="Add item">
    <Plus />
  </IconButton>
  <IconButton variant="ghost" size="sm" aria-label="Add row">
    <Plus />
  </IconButton>
</div>

Examples

Variants

Props

IconButtonProps

PropTypeDefaultDescription
aria-label requiredstring–Required: what the button does, because there is no visible text.
children requiredReactNode–An inline SVG with `currentColor` and `aria-hidden`.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

This component sets no state attributes.

CSS classes

ClassStylesheet
.btn02-buttons.css
.btn-block02-buttons.css
.btn-danger02-buttons.css
.btn-ghost02-buttons.css
.btn-lg02-buttons.css
.btn-line02-buttons.css
.btn-sm02-buttons.css
.btn-solid02-buttons.css
.btnicon-button.css
.btn-iconicon-button.css
.btn-smicon-button.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.btn {
  border-color: var(--accent);
}

Accessibility

  • Native button; aria-label is required by the type.
  • Space and Enter activate it.

Keyboard

KeysAction
Space / EnterActivate it