Items are elements that can contain text, icons, avatars, images, inputs, and any other native or custom elements. Generally they are placed in a list with other items. Items can be swiped, deleted, reordered, edited, and more.
Items left align text and add an ellipsis when the text is wider than the item. We can modify this behavior using the CSS Utilities provided by Ionic Framework, such as using .ion-text-wrap in the below example. See the CSS Utilities Documentation for more classes that can be added to an item to transform the text.
<ion-item> <ion-label>Basic Item</ion-label> </ion-item> <ion-item> <ion-label> Multi-line text that should ellipsis when it is too long to fit on one line. Lorem ipsum dolor sit amet, consectetur adipiscing elit. </ion-label> </ion-item> <ion-item> <ion-labelclass="ion-text-wrap"> Multi-line text that should wrap when it is too long to fit on one line. Lorem ipsum dolor sit amet, consectetur adipiscing elit. </ion-label> </ion-item> <ion-item> <ion-label> <h1>H1 Heading</h1> <p>Paragraph</p> </ion-label> </ion-item> <ion-item> <ion-label> <h2>H2 Heading</h2> <p>Paragraph</p> </ion-label> </ion-item> <ion-item> <ion-label> <h3>H3 Heading</h3> <p>Paragraph</p> </ion-label> </ion-item>
An item is considered "clickable" if it has an href or button property set. Clickable items have a few visual differences that indicate they can be interacted with. For example, a clickable item receives the ripple effect upon activation in md mode, has a highlight when activated in ios mode, and has a detail arrow by default in ios mode.
By default clickable items will display a right arrow icon on ios mode. To hide the right arrow icon on clickable elements, set the detail property to false. To show the right arrow icon on an item that doesn't display it naturally, set the detail property to true.
<ion-itemdetail="true"> <ion-label> <h3>Text Item</h3> <p>Detail set to true - detail arrow displays on both modes</p> </ion-label> </ion-item> <ion-itembutton> <ion-label> <h3>Button Item</h3> <p>Default detail - detail arrow displays on iOS only</p> </ion-label> </ion-item> <ion-itembuttondetail="true"> <ion-label> <h3>Button Item</h3> <p>Detail set to true - detail arrow displays on both modes</p> </ion-label> </ion-item> <ion-itembuttondetail="false"> <ion-label> <h3>Button Item</h3> <p>Detail set to false - detail arrow hidden on both modes</p> </ion-label> </ion-item> <ion-itembuttondetail="true"detail-icon="caret-forward-outline"> <ion-label> <h3>Button Item</h3> <p>Detail set to true - detail arrow displays on both modes</p> <p>Detail icon set to caret-forward-outline</p> </ion-label> </ion-item>
Items show an inset bottom border by default. The border has padding on the left and does not appear under any content that is slotted in the "start" slot. The lines property can be modified to "full" or "none" which will show a full width border or no border, respectively.
Buttons are styled smaller inside of items than when they are outside of them. To make the button size match buttons outside of an item, set the size attribute to "default".
<ion-item> <ion-buttonslot="start"> Start </ion-button> <ion-label>Default Buttons</ion-label> <ion-buttonslot="end"> End </ion-button> </ion-item> <ion-item> <ion-buttonslot="start"> Start <ion-iconname="home"slot="end"></ion-icon> </ion-button> <ion-label>Buttons with Icons</ion-label> <ion-buttonslot="end"> <ion-iconname="star"slot="end"></ion-icon> End </ion-button> </ion-item> <ion-item> <ion-buttonslot="start"> <ion-iconslot="icon-only"name="navigate"></ion-icon> </ion-button> <ion-label>Icon only Buttons</ion-label> <ion-buttonslot="end"> <ion-iconslot="icon-only"name="star"></ion-icon> </ion-button> </ion-item> <ion-item> <ion-label>Button Sizes</ion-label> <ion-buttonslot="end"size="small"> Small </ion-button> <ion-buttonslot="end"size="default"> Default </ion-button> <ion-buttonslot="end"size="large"> Large </ion-button> </ion-item>
Helper & error text can be used inside of an item with an input by slotting a note in the "helper" and "error" slots. The error slot will not be displayed unless the ion-invalid class is added to the ion-item. In Angular, this is done automatically through form validation. In JavaScript, React and Vue, the class needs to be manually added based on your own validation.
<ion-itemfill="solid"> <ion-labelposition="floating">Email</ion-label> <ion-inputtype="email"ngModelemail></ion-input> <ion-noteslot="helper">Enter a valid email</ion-note> <ion-noteslot="error">Invalid email</ion-note> </ion-item>
The item counter is helper text that displays under an input to notify the user of how many characters have been entered out of the total that the input will accept. When adding counter, the default behavior is to format the value that gets displayed as inputLength / maxLength. This behavior can be customized by passing in a formatter function to the counterFormatter property.
Items containing an input will highlight the bottom border of the input with a different color when focused, valid, or invalid. By default, md items have a highlight with a height set to 2px and ios has no highlight (technically the height is set to 0). The height can be changed using the --highlight-height CSS property. To turn off the highlight, set this variable to 0.
The highlight color changes based on the item state, but all of the states use Ionic colors by default. When focused, the input highlight will use the primary color. If the input is valid it will use the success color, and invalid inputs will use the danger color. This can be customized using the provided CSS properties.
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.
If true, a character counter will display the ratio of characters used and the total character limit. Only applies when the maxlength property is set on the inner ion-input or ion-textarea.
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).