Button

A button starts an action or navigates to a page. It renders a native <button>, or a link when href is set.

Import
import { Button } from 'svelte-ant-design';
Links
src/lib/Button Report an issue Component README

When to use

  • Use a primary button for the main action of a screen. There should be one per area.
  • Use default and dashed for secondary actions, text and link for the least important ones.
  • Use danger for destructive actions, and loading while a request is in progress.

Examples

Types

Five kinds: primary, default, dashed, text and link.

Sizes

large, medium and small. The value middle is accepted as a compatibility alias of medium.

Shape

Round and circle buttons. A circle button with an icon needs an accessible name.

Icons

Pass an icon as a snippet; iconPlacement puts it before or after the label.

Danger

The red scheme for destructive actions works with every type.

Ghost

A transparent background: the button takes the colour of the surface under it. Contrast is guaranteed on the page background.

Loading

Press the first button: it goes into loading for two seconds without losing focus. The second shows the spinner at once, the third after 500 ms. A loading button keeps the colors of its type; in the default light theme it is dimmed.

Link

Disabled

Native disabled for a button; a disabled link is rendered without href.

Block

The block prop stretches the button to the width of its container.

Download

Forms and native attributes

htmlType for submit and reset, name and value of the pressed button, and a link that downloads a file with download.

API

PropertyDescriptionTypeDefault
typeVisual style of the button.'primary' | 'default' | 'dashed' | 'text' | 'link''default'
sizeSize. middle is a compatibility alias of medium. In a SpaceCompact a button without a size takes the one of the block.'large' | 'medium' | 'middle' | 'small''medium'
shapeShape of the button.'default' | 'circle' | 'round''default'
disabledPrevents activation. A link is rendered without href.booleanfalse
loadingA spinner at once or after a delay in milliseconds. The button keeps focus.boolean | { delay: number }false
dangerRed colour scheme.booleanfalse
ghostTransparent background for default, dashed and primary.booleanfalse
blockStretches the button to the container width.booleanfalse
hrefRenders an <a> instead of a <button>. An empty string also selects a link.string—
target / rel / downloadNative link attributes, only together with href.string / string / string | boolean—
htmlTypeNative button type; ignored for a link.'button' | 'submit' | 'reset''button'
form / name / valueNative button attributes for forms.string—
iconAn icon snippet, hidden from assistive technology.Snippet—
iconPlacementPosition of the icon relative to the label.'start' | 'end''start'
childrenThe label or content of the button.Snippet—
classAn additional CSS class.string—
native attributesNative button or a attributes (including tabindex and aria-*) are forwarded to the element; the loading and disabled states take priority over a consumer aria-busy, aria-disabled and tabindex.HTMLButtonAttributes | HTMLAnchorAttributes—
onclickCalled when an enabled button is activated; not called while disabled or loading.(event: MouseEvent) => void—
Reserved for v1.1 (additive, not implemented yet): color, variant, classNames, styles.

Design tokens

TokenDescriptionDefault
--ads-control-heightHeight of a medium button.32px
--ads-control-height-lgHeight of a large button.40px
--ads-control-height-smHeight of a small button.24px
--ads-radius-mdCorner radius.6px
--ads-color-primary-solidFill of a primary button. tokens-accessible.css darkens it to #1668dc.#1677ff
--ads-color-primary-textText colour of ghost and of the border and text of the default and dashed types on hover.#1677ff
--ads-color-linkText colour of the link type. The tokens -hover and -active hold its states.#1677ff
--ads-color-link-hoverText colour of the link type on hover.#69b1ff
--ads-button-text-hover-bgBackground of the text type on hover.rgba(0, 0, 0, 0.04)
--ads-button-loading-opacityOpacity of a loading button. The dark theme and tokens-accessible.css set it to 1.0.65
--ads-color-danger-solidFill of a danger button. tokens-accessible.css darkens it to #d9363e.#ff4d4f
--ads-color-focus-outlineColour of the focus ring.#1677ff

Accessibility

  • A loading button stays focusable and exposes aria-busy and aria-disabled; clicks, Enter and Space are ignored.
  • A disabled or loading link is rendered without href, so it cannot be opened in a new tab.
  • An icon-only button needs an accessible name, for example aria-label.