This component is based on the <span> element, but can be used with any element. The following are the props that can be passed to the component.
Prop
Type
Default
as
The HTML tag to render. By default the component will render as a `span` unless `href` is defined, at which point it will render as an `a`.
TagType
span
variant
The variant the tag will take. Corresponds to the design system.
"contained" | "outlined"
"contained"
size
The size of the tag. Corresponds to the design system.
"sm" | "md" | "lg"
"sm"
clickable
Whether the tag should be rendered as a clickable element. By default, a tag with an `href` will be clickable.
boolean
false
href
The URL to link to. Passing in a value will cause the element to render as an anchor.
string
—
Accessibility
The <Tag> component includes some accessibility features to help ensure that the component is usable and understandable by all users. The following are the accessibility features that have been implemented:
When a tag is set to clickable, it will render as a <button> element and include a type="button" attribute.
When a tag is given the href prop, it will render as an <a> element.
Examples
Variants
Use the variant prop to adjust the visual style. Tag components come in the following variants: contained and outlined, and should be added, removed, and tweaked as necessary based on the needs of the project.
Use the size prop to adjust the tag size. Tags come in the following sizes: sm, md and lg. Sizes should be added, removed, and tweaked as necessary based on the needs of the project.
Use the clickable prop to convert a tag to a clickable element. This is useful when you want to add an onClick event to the tag. By default, a tag with an href will be clickable.
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.