Buttons provide a clickable element, which can be used in forms, or anywhere that needs simple, standard button functionality. They may display text, icons, or both. Buttons can be styled with several attributes to look a specific way.
This property lets you specify how wide the button should be. By default, buttons have display: inline-block, but setting this property will change the button to a full-width element with display: block.
This property lets you specify the shape of the button. By default, buttons are rectangular with a small border radius, but setting this to "round" will change the button to a rounded element.
import{ Component }from'@angular/core'; import{ IonButton, IonIcon }from'@ionic/angular/standalone'; import{ addIcons }from'ionicons'; import{ heart }from'ionicons/icons'; @Component({ selector:'app-example', templateUrl:'example.component.html', styleUrls:['example.component.css'], imports:[IonButton, IonIcon], }) exportclassExampleComponent{ constructor(){ /** * Any icons you want to use in your application * can be registered in app.component.ts and then * referenced by name anywhere in your application. */ addIcons({ heart }); } }
This property determines the background and border color of the button. By default, buttons have a solid background unless the button is inside of a toolbar, in which case it has a transparent background.
<ion-buttonsize="small"> <ion-iconslot="icon-only"ios="logo-apple"md="settings-sharp"></ion-icon> </ion-button> <ion-button> <ion-iconslot="icon-only"ios="logo-apple"md="settings-sharp"></ion-icon> </ion-button> <ion-buttonsize="large"> <ion-iconslot="icon-only"ios="logo-apple"md="settings-sharp"></ion-icon> </ion-button> <ion-buttonsize="small"> <ion-iconslot="start"name="star"></ion-icon> Left Icon </ion-button> <ion-button> <ion-iconslot="start"name="star"></ion-icon> Left Icon </ion-button> <ion-buttonsize="large"> <ion-iconslot="start"name="star"></ion-icon> Left Icon </ion-button> <ion-buttonsize="small"> Right Icon <ion-iconslot="end"name="heart"></ion-icon> </ion-button> <ion-button> Right Icon <ion-iconslot="end"name="heart"></ion-icon> </ion-button> <ion-buttonsize="large"> Right Icon <ion-iconslot="end"name="heart"></ion-icon> </ion-button>
import{ Component }from'@angular/core'; import{ IonButton, IonIcon }from'@ionic/angular/standalone'; import{ addIcons }from'ionicons'; import{ heart, logoApple, settingsSharp, star }from'ionicons/icons'; @Component({ selector:'app-example', templateUrl:'example.component.html', styleUrls:['example.component.css'], imports:[IonButton, IonIcon], }) exportclassExampleComponent{ constructor(){ /** * Any icons you want to use in your application * can be registered in app.component.ts and then * referenced by name anywhere in your application. */ addIcons({ heart, logoApple, settingsSharp, star }); } }
Buttons are built to be accessible, but may need some adjustments depending on their content. The button component renders a native button element which allows it to take advantage of the functionality that a native button provides.
There are many cases where a button's text content may overflow the container. It is recommended to wrap the text inside of the button when this happens so that all of the text can still be read. The button component will automatically adjust its height to accommodate the extra lines of text.
The button text does not automatically wrap to the next line when the text is too long to fit. In order to make the text wrap, the ion-text-wrap class can be added, which will set the white-space property to "normal". This will become the default in a future major release.
info
The max-width style is set on the button below for demo purposes only. Text wrapping will work with a dynamic button width.
src/app/example.component.html
src/app/example.component.ts
<ion-button>Default</ion-button> <ion-buttonclass="ion-text-wrap"style="max-width:400px" >This is the button that never ends it just goes on and on and on and on and on and on and on and on my friends</ion-button >
The color to use from your application's color palette. Default options are: "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", and "dark". For more information on colors, see theming.
This attribute instructs browsers to download a URL instead of navigating to it, so the user will be prompted to save it as a local file. If the attribute has a value, it is used as the pre-filled file name in the Save prompt (the user can still change the file name if they want).
Set to "clear" for a transparent button that resembles a flat button, to "outline" for a transparent button with a border, or to "solid" for a button with a filled background. The default fill is "solid" except inside of a toolbar, where the default is "clear".
Set to "small" for a button with less height and padding, to "default" for a button with the default height and padding, or to "large" for a button with more height and padding. By default the size is unset, unless the button is inside of an item, where the size is "small" by default. Set the size to "default" inside of an item to make it a standard size button.
By clicking “Accept All Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts.
Privacy Preference Center
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
Manage Consent Preferences
Strictly Necessary Cookies
Always Active
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.
Performance Cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
Functional Cookies
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
Targeting Cookies
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising.