import Button from 'primevue/button';
<script src="https://unpkg.com/primevue@^3/core/core.min.js"></script>
Button is created using the Button element.
<Button />
Text of the button is defined using the label property.
<Button label="Submit" />
Icon on a button is specified with icon property and position is configured using iconPos attribute. Default icon position is "left" and alternative is "right". To display only an icon, leave the label as undefined.
<Button label="Submit" icon="pi pi-check" iconPos="right" />
Events are defined with the standard notation.
<Button label="Submit" @click="handleClick($event)"/>
Different options are available as severity levels.
<Button label="Primary" />
<Button label="Secondary" class="p-button-secondary" />
<Button label="Success" class="p-button-success" />
<Button label="Info" class="p-button-info" />
<Button label="Warning" class="p-button-warning" />
<Button label="Warning" class="p-button-help" />
<Button label="Danger" class="p-button-danger" />
Text buttons have transparent background and borders, use p-button-text to apply text button styling. In addition when used with .p-button-plain text buttons ignore severity levels and displayed as a regular text.
<Button label="Submit" class="p-button-text" />
<Button icon="pi pi-check" class="p-button-text" />
<Button label="Cancel" icon="pi pi-times" class="p-button-text" />
<Button label="Search" icon="pi pi-search" iconPos="right" class="p-button-text p-button-text" />
A button can be raised by having "p-button-raised" style class and similarly borders can be made rounded using "p-button-rounded" class.
<Button label="Primary" class="p-button-raised p-button-rounded" />
An alternate styling for a button is the outlined option where background becomes transparent. Apply "p-button-outlined" to style a button as outlined.
<Button label="Primary" class="p-button-outlined" />
Use "p-button-link" class to render the button as a link.
<Button label="Link" class="p-button-link" />
Badge is a small status indicator for a button. Refer to the
<Button type="button" label="Emails" badge="8" />
<Button type="button" label="Messages" icon="pi pi-users" class="p-button-warning" badge="8" badgeClass="p-badge-info" />
Wrapping the buttons in a container having a .p-buttonset class, groups the buttons side to side.
<span class="p-buttonset">
<Button label="Save" icon="pi pi-check" />
<Button label="Delete" icon="pi pi-trash" />
<Button label="Cancel" icon="pi pi-times" />
</span>
2 more sizes are available in addition to a regular button, for a smaller input add p-button-sm and for a larger one, use p-button-lg. Note that these classes available to change the size of a particular button, for global
scaling see the
<Button label="Small" icon="pi pi-check" class="p-button-sm" />
<Button label="Normal" icon="pi pi-check" class="p-button" />
<Button label="Large" icon="pi pi-check" class="p-button-lg" />
Button displays a loadingIcon when loading property is enabled.
<Button label="Save" icon="pi pi-check" :loading="isLoading" />
Custom content such as icons, images and text can be placed inside the button via the default slot. Note that when slot is used, label, icon and badge properties are not included.
<Button type="button" class="px-3">
<img alt="logo" src="@/assets/images/logo.svg" style="width: 1.5rem"/>
</Button>
<Button type="button" class="p-button-outlined p-button-success">
<img alt="logo" src="@/assets/images/logo.svg" style="width: 1.5rem" />
<span class="ml-2 font-bold">PrimeVue</span>
</Button>
Any property such as style and class are passed to the underlying button element. Following are the additional properties to configure the component.
Name | Type | Default | Description |
---|---|---|---|
label | string | null | Text of the button. |
icon | string | null | Name of the icon. |
iconPos | string | left | Position of the icon, valid values are "left", "right", "bottom" and "top". |
iconClass | string | null | Style class of the icon. |
badge | string | null | Value of the badge. |
badgeClass | string | null | Style class of the badge. |
loading | boolean | false | Whether the button is in loading state. |
loadingIcon | string | pi pi-spinner pi-spin | Icon to display in loading state. |
Following is the list of structural style classes, for theming classes visit
Name | Element |
---|---|
p-button | Button element |
p-button-icon | Icon element |
p-button-label | Label element of the button |
p-button-sm | Smaller button element |
p-button-lg | Larger button element |
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-3">Youtube</span>
</Button>
Key | Function |
---|---|
tab | Moves focus to the button. |
enter | Activates the button. |
space | Activates the button. |
None.