This component is based on the <button> and <a> HTML elements. The following are the props that can be passed to the component.
Prop
Type
Default
variant
The variant the button will take. Corresponds to the design system.
"contained" | "outlined" | "subtle" | "text"
"contained"
size
The size of the button. Corresponds to the design system.
"sm" | "md" | "lg"
"md"
title
The title of the button. Used for screen readers and assistive tooltips
string
—
icon
Whether the button should be an icon only button or not. If `true`, the button will omit the text, become a 1:1 aspect ratio, and only display the icon.
boolean
false
href
The URL to link to. Passing in a value will cause the element to render as an anchor.
string
—
disabled
Whether the button is disabled or not.
boolean
false
Accessibility
The <Button> component has some accessibility features that are important to consider when implementing it in your project. The following are some of the key accessibility features that are included in the component:
When the button renders as a <button> element, the component includes the a type property that can be changed and defaults to button. This is important for screen readers to understand the purpose of the button.
When a button has the icon prop set to true, the button will omit the text and only display the icon. The text will still be included in the button for screen readers to understand the purpose of the button.
You can use the title prop to provide a tooltip for the button. This is useful for providing additional context about the purpose of a button, especially so with icon buttons.
Examples
Variants
Use the variant prop to adjust the visual style. Buttons come in the following variants: contained, outlined, subtle, text, and icon. Variants should be added, removed, and tweaked as necessary based on the needs of the project.
Use the size prop to adjust the size. Buttons come in the following different sizes: sm, md, and lg. By default, buttons will use md unless specified. Sizes should be added, removed, and tweaked as necessary based on the needs of the project.
Use the icon prop to make the button into an icon button. Button Icons are buttons that only contain an icon. They are useful for situations where you want to provide a button that is only an icon, such as in a toolbar. By adding the btn-icon class, the button will have a 1:1 aspect ration and the text will be omitted and used only for screen-reader purposes.
Depending on the framework, it’s sometimes beneficial to use a component for generating the button. In this case, we have put together the following Astro component to serve as a blueprint for how you could possibly set up a Button component, and what properties to consider.