Button is an extension to standard input element with icons and theming.
import Button from 'primevue/button';
Text to display on a button is defined with the label property.
<Button label="Submit" />
Icon of a button is specified with icon property and position is configured using iconPos attribute.
<Button icon="pi pi-home" aria-label="Save" />
<Button label="Profile" icon="pi pi-user" />
<Button label="Save" icon="pi pi-check" iconPos="right" />
<Button label="Search" icon="pi pi-search" iconPos="top" />
<Button label="Update" icon="pi pi-refresh" iconPos="bottom" />
Busy state is controlled with the loading property.
<Button type="button" label="Search" icon="pi pi-search" :loading="loading" @click="load" />
The button element can be displayed as a link element visually when the link property is present. If you need to customize the rendering, use the as to change the element or asChild for advanced templating.
<Button label="Link" variant="link" />
<Button as="a" label="External" href="https://vuejs.org/" target="_blank" rel="noopener" />
<Button asChild v-slot="slotProps">
<RouterLink to="/" :class="slotProps.class">Router</RouterLink>
</Button>
The severity property defines the variant of a button.
<Button label="Primary" />
<Button label="Secondary" severity="secondary" />
<Button label="Success" severity="success" />
<Button label="Info" severity="info" />
<Button label="Warn" severity="warn" />
<Button label="Help" severity="help" />
<Button label="Danger" severity="danger" />
<Button label="Contrast" severity="contrast" />
When disabled is present, the element cannot be used.
<Button label="Submit" disabled />
Raised buttons display a shadow to indicate elevation.
<Button label="Primary" raised />
<Button label="Secondary" severity="secondary" raised />
<Button label="Success" severity="success" raised />
<Button label="Info" severity="info" raised />
<Button label="Warn" severity="warn" raised />
<Button label="Help" severity="help" raised />
<Button label="Danger" severity="danger" raised />
<Button label="Contrast" severity="contrast" raised />
Rounded buttons have a circular border radius.
<Button label="Primary" rounded />
<Button label="Secondary" severity="secondary" rounded />
<Button label="Success" severity="success" rounded />
<Button label="Info" severity="info" rounded />
<Button label="Warn" severity="warn" rounded />
<Button label="Help" severity="help" rounded />
<Button label="Danger" severity="danger" rounded />
<Button label="Contrast" severity="contrast" rounded />
Text buttons are displayed as textual elements.
<Button label="Primary" variant="text" />
<Button label="Secondary" severity="secondary" variant="text" />
<Button label="Success" severity="success" variant="text" />
<Button label="Info" severity="info" variant="text" />
<Button label="Warn" severity="warn" variant="text" />
<Button label="Help" severity="help" variant="text" />
<Button label="Danger" severity="danger" variant="text" />
<Button label="Contrast" severity="contrast" variant="text" />
Text buttons can be displayed elevated with the raised option.
<Button label="Primary" variant="text" raised />
<Button label="Secondary" severity="secondary" variant="text" raised />
<Button label="Success" severity="success" variant="text" raised />
<Button label="Info" severity="info" variant="text" raised />
<Button label="Warn" severity="warn" variant="text" raised />
<Button label="Help" severity="help" variant="text" raised />
<Button label="Danger" severity="danger" variant="text" raised />
<Button label="Contrast" severity="contrast" variant="text" raised />
Outlined buttons display a border without a transparent background.
<Button label="Primary" variant="outlined" />
<Button label="Secondary" severity="secondary" variant="outlined" />
<Button label="Success" severity="success" variant="outlined" />
<Button label="Info" severity="info" variant="outlined" />
<Button label="Warn" severity="warn" variant="outlined" />
<Button label="Help" severity="help" variant="outlined" />
<Button label="Danger" severity="danger" variant="outlined" />
<Button label="Contrast" severity="contrast" variant="outlined" />
Buttons can have icons without labels.
<Button icon="pi pi-check" aria-label="Filter" />
<Button icon="pi pi-bookmark" severity="secondary" aria-label="Bookmark" />
<Button icon="pi pi-search" severity="success" aria-label="Search" />
<Button icon="pi pi-user" severity="info" aria-label="User" />
<Button icon="pi pi-bell" severity="warn" aria-label="Notification" />
<Button icon="pi pi-heart" severity="help" aria-label="Favorite" />
<Button icon="pi pi-times" severity="danger" aria-label="Cancel" />
<Button icon="pi pi-star" severity="contrast" aria-label="Star" />
<Button icon="pi pi-check" rounded aria-label="Filter" />
<Button icon="pi pi-bookmark" severity="secondary" rounded aria-label="Bookmark" />
<Button icon="pi pi-search" severity="success" rounded aria-label="Search" />
<Button icon="pi pi-user" severity="info" rounded aria-label="User" />
<Button icon="pi pi-bell" severity="warn" rounded aria-label="Notification" />
<Button icon="pi pi-heart" severity="help" rounded aria-label="Favorite" />
<Button icon="pi pi-times" severity="danger" rounded aria-label="Cancel" />
<Button icon="pi pi-star" severity="contrast" rounded aria-label="Star" />
<Button icon="pi pi-check" rounded variant="outlined" aria-label="Filter" />
<Button icon="pi pi-bookmark" severity="secondary" rounded variant="outlined" aria-label="Bookmark" />
<Button icon="pi pi-search" severity="success" rounded variant="outlined" aria-label="Search" />
<Button icon="pi pi-user" severity="info" rounded variant="outlined" aria-label="User" />
<Button icon="pi pi-bell" severity="warn" rounded variant="outlined" aria-label="Notification" />
<Button icon="pi pi-heart" severity="help" rounded variant="outlined" aria-label="Favorite" />
<Button icon="pi pi-times" severity="danger" rounded variant="outlined" aria-label="Cancel" />
<Button icon="pi pi-star" severity="contrast" rounded variant="outlined" aria-label="Star" />
<Button icon="pi pi-check" variant="text" raised rounded aria-label="Filter" />
<Button icon="pi pi-bookmark" severity="secondary" variant="text" raised rounded aria-label="Bookmark" />
<Button icon="pi pi-search" severity="success" variant="text" raised rounded aria-label="Search" />
<Button icon="pi pi-user" severity="info" variant="text" raised rounded aria-label="User" />
<Button icon="pi pi-bell" severity="warn" variant="text" raised rounded aria-label="Notification" />
<Button icon="pi pi-heart" severity="help" variant="text" raised rounded aria-label="Favorite" />
<Button icon="pi pi-times" severity="danger" variant="text" raised rounded aria-label="Cancel" />
<Button icon="pi pi-star" severity="contrast" variant="text" raised rounded aria-label="Star" />
<Button icon="pi pi-check" variant="text" rounded aria-label="Filter" />
<Button icon="pi pi-bookmark" severity="secondary" variant="text" rounded aria-label="Bookmark" />
<Button icon="pi pi-search" severity="success" variant="text" rounded aria-label="Search" />
<Button icon="pi pi-user" severity="info" variant="text" rounded aria-label="User" />
<Button icon="pi pi-bell" severity="warn" variant="text" rounded aria-label="Notification" />
<Button icon="pi pi-heart" severity="help" variant="text" rounded aria-label="Favorite" />
<Button icon="pi pi-times" severity="danger" variant="text" rounded aria-label="Cancel" />
<Button icon="pi pi-star" severity="contrast" variant="text" rounded aria-label="Star" />
Buttons have built-in badge support with badge and badgeSeverity properties.
<Button type="button" label="Emails" badge="2" />
<Button type="button" label="Messages" icon="pi pi-users" badge="2" badgeSeverity="contrast" variant="outlined" />
Multiple buttons are grouped when wrapped inside an element with ButtonGroup component.
<ButtonGroup>
<Button label="Save" icon="pi pi-check" />
<Button label="Delete" icon="pi pi-trash" />
<Button label="Cancel" icon="pi pi-times" />
</ButtonGroup>
Button provides small and large sizes as alternatives to the base.
<Button label="Small" icon="pi pi-check" size="small" />
<Button label="Normal" icon="pi pi-check" />
<Button label="Large" icon="pi pi-check" size="large" />
Custom content inside a button is defined as children.
<Button variant="outlined" class="!border-2">
<svg width="35" height="40" viewBox="0 0 35 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="..." fill="var(--p-primary-color)" />
<path d="..." fill="var(--p-text-color)" />
</svg>
</Button>
Headless mode is enabled by adding the asChild property and defining your own UI element with the available bindings.
<Button v-slot="slotProps" asChild>
<button
v-bind="slotProps.a11yAttrs"
class="rounded-lg bg-gradient-to-br from-primary-400 to-primary-700 active:from-primary-700 active:to-primary-900 text-white border-none px-6 py-3 font-bold hover:ring-2 cursor-pointer ring-offset-2 ring-offset-surface-0 dark:ring-offset-surface-900 ring-primary transition-all"
>
SIGN UP
</button>
</Button>
Button component renders a native button element that implicitly includes any passed prop. Text to describe the button is defined with the aria-label prop, if not present label prop is used as the value. If the button is icon only or custom templating is used, it is recommended to use aria-label so that screen readers would be able to read the element properly.
<Button icon="pi pi-check" aria-label="Submit" />
<Button icon="pi pi-check" label="Submit" />
<Button class="youtube p-0" aria-label="Youtube">
<i class="pi pi-youtube px-2"></i>
<span class="px-4">Youtube</span>
</Button>
Key | Function |
---|---|
tab | Moves focus to the button. |
enter | Activates the button. |
space | Activates the button. |
API defines helper props, events and others for the PrimeVue Button module.
Button is an extension to standard button element with icons and theming.
Defines valid properties in Button component.
name | type | default | description | |
---|---|---|---|---|
aria-activedescendant | string | null | Identifies the currently active element when DOM focus is on a composite widget, textbox, group, or application. | |
aria-atomic | Booleanish | null | Indicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute. | |
aria-autocomplete | "none" | "inline" | "list" | "both" | null | Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for an input and specifies how predictions would be presented if they are made. | |
aria-busy | Booleanish | null | Indicates an element is being modified and that assistive technologies MAY want to wait until the modifications are complete before exposing them to the user. | |
aria-checked | Booleanish | "mixed" | null | Indicates the current "checked" state of checkboxes, radio buttons, and other widgets. | |
aria-colcount | Numberish | null | Defines the total number of columns in a table, grid, or treegrid. | |
aria-colindex | Numberish | null | Defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid. | |
aria-colspan | Numberish | null | Defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid. | |
aria-controls | string | null | Identifies the element (or elements) whose contents or presence are controlled by the current element. | |
aria-current | Booleanish | "page" | "step" | "location" | "date" | "time" | null | Indicates the element that represents the current item within a container or set of related elements. | |
aria-describedby | string | null | Identifies the element (or elements) that describes the object. | |
aria-details | string | null | Identifies the element that provides a detailed, extended description for the object. | |
aria-disabled | Booleanish | null | Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. | |
aria-dropeffect | "link" | "none" | "copy" | "execute" | "move" | "popup" | null | Indicates what functions can be performed when a dragged object is released on the drop target. | |
aria-errormessage | string | null | Identifies the element that provides an error message for the object. | |
aria-expanded | Booleanish | null | Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed. | |
aria-flowto | string | null | Identifies the next element (or elements) in an alternate reading order of content which, at the user's discretion, allows assistive technology to override the general default of reading in document source order. | |
aria-grabbed | Booleanish | null | Indicates an element's "grabbed" state in a drag-and-drop operation. | |
aria-haspopup | Booleanish | "menu" | "listbox" | "tree" | "grid" | "dialog" | null | Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element. | |
aria-hidden | Booleanish | null | Indicates whether the element is exposed to an accessibility API. | |
aria-invalid | Booleanish | "grammar" | "spelling" | null | Indicates the entered value does not conform to the format expected by the application. | |
aria-keyshortcuts | string | null | Indicates keyboard shortcuts that an author has implemented to activate or give focus to an element. | |
aria-label | string | null | Defines a string value that labels the current element. | |
aria-labelledby | string | null | Identifies the element (or elements) that labels the current element. | |
aria-level | Numberish | null | Defines the hierarchical level of an element within a structure. | |
aria-live | "off" | "assertive" | "polite" | null | Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region. | |
aria-modal | Booleanish | null | Indicates whether an element is modal when displayed. | |
aria-multiline | Booleanish | null | Indicates whether a text box accepts multiple lines of input or only a single line. | |
aria-multiselectable | Booleanish | null | Indicates that the user may select more than one item from the current selectable descendants. | |
aria-orientation | "horizontal" | "vertical" | null | Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous. | |
aria-owns | string | null | Identifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship between DOM elements where the DOM hierarchy cannot be used to represent the relationship. | |
aria-placeholder | string | null | Defines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value. A hint could be a sample value or a brief description of the expected format. | |
aria-posinset | Numberish | null | Defines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. | |
aria-pressed | Booleanish | "mixed" | null | Indicates the current "pressed" state of toggle buttons. | |
aria-readonly | Booleanish | null | Indicates that the element is not editable, but is otherwise operable. | |
aria-relevant | "text" | "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text additions" | "text removals" | null | Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. | |
aria-required | Booleanish | null | Indicates that user input is required on the element before a form may be submitted. | |
aria-roledescription | string | null | Defines a human-readable, author-localized description for the role of an element. | |
aria-rowcount | Numberish | null | Defines the total number of rows in a table, grid, or treegrid. | |
aria-rowindex | Numberish | null | Defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid. | |
aria-rowspan | Numberish | null | Defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid. | |
aria-selected | Booleanish | null | Indicates the current "selected" state of various widgets. | |
aria-setsize | Numberish | null | Defines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. | |
aria-sort | "none" | "ascending" | "descending" | "other" | null | Indicates if items in a table or grid are sorted in ascending or descending order. | |
aria-valuemax | Numberish | null | Defines the maximum allowed value for a range widget. | |
aria-valuemin | Numberish | null | Defines the minimum allowed value for a range widget. | |
aria-valuenow | Numberish | null | Defines the current value for a range widget. | |
aria-valuetext | string | null | Defines the human readable text alternative of aria-valuenow for a range widget. | |
innerHTML | string | null | ||
accesskey | string | null | ||
contenteditable | Booleanish | "inherit" | "plaintext-only" | null | ||
contextmenu | string | null | ||
dir | string | null | ||
draggable | Booleanish | null | ||
hidden | "" | Booleanish | "hidden" | "until-found" | null | ||
id | string | null | ||
inert | Booleanish | null | ||
lang | string | null | ||
placeholder | string | null | ||
spellcheck | Booleanish | null | ||
tabindex | Numberish | null | ||
title | string | null | ||
translate | "yes" | "no" | null | ||
radiogroup | string | null | ||
role | string | null | ||
about | string | null | ||
datatype | string | null | ||
inlist | any | null | ||
prefix | string | null | ||
property | string | null | ||
resource | string | null | ||
typeof | string | null | ||
vocab | string | null | ||
autocapitalize | string | null | ||
autocorrect | string | null | ||
autosave | string | null | ||
color | string | null | ||
itemprop | string | null | ||
itemscope | Booleanish | null | ||
itemtype | string | null | ||
itemid | string | null | ||
itemref | string | null | ||
results | Numberish | null | ||
security | string | null | ||
unselectable | "on" | "off" | null | ||
inputmode | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | "search" | null | Hints at the type of data that might be entered by the user while editing the element or its contents | |
is | string | null | Specify that a standard HTML element should behave like a defined custom built-in element | |
autofocus | Booleanish | null | ||
disabled | Booleanish | null | ||
form | string | null | ||
formaction | string | null | ||
formenctype | string | null | ||
formmethod | string | null | ||
formnovalidate | Booleanish | null | ||
formtarget | string | null | ||
name | string | null | ||
type | "submit" | "reset" | "button" | null | ||
value | string | number | readonly string[] | null | ||
onCopy | Function | null | ||
onCut | Function | null | ||
onPaste | Function | null | ||
onCompositionend | Function | null | ||
onCompositionstart | Function | null | ||
onCompositionupdate | Function | null | ||
onDrag | Function | null | ||
onDragend | Function | null | ||
onDragenter | Function | null | ||
onDragexit | Function | null | ||
onDragleave | Function | null | ||
onDragover | Function | null | ||
onDragstart | Function | null | ||
onDrop | Function | null | ||
onFocus | Function | null | ||
onFocusin | Function | null | ||
onFocusout | Function | null | ||
onBlur | Function | null | ||
onChange | Function | null | ||
onBeforeinput | Function | null | ||
onInput | Function | null | ||
onReset | Function | null | ||
onSubmit | Function | null | ||
onInvalid | Function | null | ||
onLoad | Function | null | ||
onError | Function | null | ||
onKeydown | Function | null | ||
onKeypress | Function | null | ||
onKeyup | Function | null | ||
onAuxclick | Function | null | ||
onClick | Function | null | ||
onContextmenu | Function | null | ||
onDblclick | Function | null | ||
onMousedown | Function | null | ||
onMouseenter | Function | null | ||
onMouseleave | Function | null | ||
onMousemove | Function | null | ||
onMouseout | Function | null | ||
onMouseover | Function | null | ||
onMouseup | Function | null | ||
onAbort | Function | null | ||
onCanplay | Function | null | ||
onCanplaythrough | Function | null | ||
onDurationchange | Function | null | ||
onEmptied | Function | null | ||
onEncrypted | Function | null | ||
onEnded | Function | null | ||
onLoadeddata | Function | null | ||
onLoadedmetadata | Function | null | ||
onLoadstart | Function | null | ||
onPause | Function | null | ||
onPlay | Function | null | ||
onPlaying | Function | null | ||
onProgress | Function | null | ||
onRatechange | Function | null | ||
onSeeked | Function | null | ||
onSeeking | Function | null | ||
onStalled | Function | null | ||
onSuspend | Function | null | ||
onTimeupdate | Function | null | ||
onVolumechange | Function | null | ||
onWaiting | Function | null | ||
onSelect | Function | null | ||
onScroll | Function | null | ||
onScrollend | Function | null | ||
onTouchcancel | Function | null | ||
onTouchend | Function | null | ||
onTouchmove | Function | null | ||
onTouchstart | Function | null | ||
onPointerdown | Function | null | ||
onPointermove | Function | null | ||
onPointerup | Function | null | ||
onPointercancel | Function | null | ||
onPointerenter | Function | null | ||
onPointerleave | Function | null | ||
onPointerover | Function | null | ||
onPointerout | Function | null | ||
onWheel | Function | null | ||
onAnimationstart | Function | null | ||
onAnimationend | Function | null | ||
onAnimationiteration | Function | null | ||
onTransitionend | Function | null | ||
onTransitionstart | Function | null | ||
style | any | null | Inline style of the button. | |
class | any | null | Style class of the button. | |
label | string | null | Text of the button. | |
icon | string | null | Name of the icon. | |
iconPos | HintedString<"left" | "right" | "top" | "bottom"> | left | Position of the icon. | |
iconClass | string | object | null | Style class of the icon. | |
badge | string | null | Value of the badge. | |
badgeClass | string | object | null | Style class of the badge. | |
badgeSeverity | null | HintedString<"secondary" | "info" | "success" | "warn" | "danger" | "contrast"> | null | Severity type of the badge. | |
loading | boolean | false | Whether the button is in loading state. | |
loadingIcon | string | null | Icon to display in loading state. | |
as | string | Component | BUTTON | Use to change the HTML tag of root element. | |
asChild | boolean | false | When enabled, it changes the default rendered element for the one passed as a child element. | |
link | boolean | false | Add a link style to the button. | |
severity | HintedString<"secondary" | "info" | "success" | "warn" | "danger" | "contrast" | "help"> | null | Defines the style of the button. | |
raised | boolean | false | Add a shadow to indicate elevation. | |
rounded | boolean | false | Add a circular border radius to the button. | |
text | boolean | false | Add a textual class to the button without a background initially. | |
outlined | boolean | false | Add a border class without a background initially. | |
size | HintedString<"small" | "large"> | null | Defines the size of the button. | |
variant | HintedString<"outlined" | "text" | "link"> | undefined | Specifies the variant of the component. | |
plain | boolean | false | Add a plain textual class to the button without a background initially. | |
fluid | boolean | null | Spans 100% width of the container when enabled. | |
dt | any | null | It generates scoped CSS variables using design tokens for the component. | |
pt | PassThrough<ButtonPassThroughOptions<any>> | null | Used to pass attributes to DOM elements inside the component. | |
ptOptions | any | null | Used to configure passthrough(pt) options of the component. | |
unstyled | boolean | false | When enabled, it removes component related styles in the core. |
Defines valid slots in Button component.
Defines the custom interfaces used by the module.
Custom passthrough(pt) option method.
name | type | default | description |
---|---|---|---|
instance | any | null | Defines instance. |
props | ButtonProps | null | Defines valid properties. |
context | ButtonContext | null | Defines current options. |
parent | any | null | Defines parent instance. |
global | undefined | object | null | Defines passthrough(pt) options in global config. |
Custom passthrough(pt) options.
name | type | default | description |
---|---|---|---|
root | ButtonPassThroughOptionType<T> | null | Used to pass attributes to the root's DOM element. |
loadingIcon | ButtonPassThroughOptionType<T> | null | Used to pass attributes to the loading icon's DOM element. |
icon | ButtonPassThroughOptionType<T> | null | Used to pass attributes to the icon's DOM element. |
label | ButtonPassThroughOptionType<T> | null | Used to pass attributes to the label's DOM element. |
pcBadge | ButtonPassThroughOptionType<T> | null | Used to pass attributes to the Badge component. |
hooks | any | null | Used to manage all lifecycle hooks. |
Custom passthrough attributes for each DOM elements
Defines current options in Button component.
Defines the custom types used by the module.
values |
---|
ButtonPassThroughAttributes | (options: ButtonPassThroughMethodOptions) => undefined | string | null | undefined |
values |
---|
EmitFn<ButtonEmitsOptions> |
A set of Buttons can be displayed together using the ButtonGroup component.
Defines valid properties in ButtonGroup component.
Defines valid slots in ButtonGroup component.
name | parameters | returnType | description | |
---|---|---|---|---|
default | VNode<RendererNode, RendererElement, Object>[] | Default slot to detect Button components. |
Defines the custom interfaces used by the module.
Custom passthrough(pt) option method.
name | type | default | description |
---|---|---|---|
instance | any | null | Defines instance. |
props | ButtonGroupProps | null | Defines valid properties. |
global | undefined | object | null | Defines passthrough(pt) options in global config. |
Custom passthrough(pt) options.
name | type | default | description |
---|---|---|---|
root | ButtonGroupPassThroughOptionType | null | Used to pass attributes to the root's DOM element. |
hooks | any | null | Used to manage all lifecycle hooks. |
Custom passthrough attributes for each DOM elements
Defines the custom types used by the module.
values |
---|
ButtonGroupPassThroughAttributes | (options: ButtonGroupPassThroughMethodOptions) => undefined | string | null | undefined |
values |
---|
EmitFn<ButtonGroupEmitsOptions> |