The input component is a wrapper to the HTML input element with custom styling and additional functionality. It accepts most of the same properties as the HTML input, but works great on desktop devices and integrates with the keyboard on mobile devices.
The input component is meant for text type inputs only, such as "text", "password", "email", "number", "search", "tel", and "url". It supports all standard text input events including keyup, keydown, keypress, and more. The default type is "text".
Labels will take up the width of their content by default. Developers can use the labelPlacement property to control how the label is placed relative to the control.
Inputs offer two options for clearing the input based on how you interact with it. The first way is by adding the clearInput property which will show a clear button when the input has a value. The second way is the clearOnEdit property which will clear the input after it has been blurred and then typed in again. Inputs with a type set to "password" will have clearOnEdit enabled by default.
Helper and error text can be used inside of an input with the helperText and errorText property. The error text will not be displayed unless the ion-invalid class is added to the ion-input. 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.
The input counter is 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.
Setting the color property changes the color palette for each input. On ios mode, this property changes the caret color. On md mode, this property changes the caret color and the highlight/underline color.
Input uses scoped encapsulation, which means it will automatically scope its CSS by appending each of the styles with an additional class at runtime. Overriding scoped selectors in CSS requires a higher specificity selector. Targeting the ion-input for customization will not work; therefore we recommend adding a class and customizing it that way.
A simpler input syntax was introduced in Ionic 7.0. This new syntax reduces the boilerplate required to setup an input, resolves accessibility issues, and improves the developer experience.
Developers can perform this migration one input at a time. While developers can continue using the legacy syntax, we recommend migrating as soon as possible.
Remove ion-label and use the label property on ion-input instead. The placement of the label can be configured using the labelPlacement property on ion-input.
Move input-specific properties from ion-item on to ion-input. This includes the counter, counterFormatter, fill, and shape properties.
Remove usages of the helper and error slots on ion-item and use the helperText and errorText properties on ion-input instead.
JavaScript
Angular
React
Vue
<!-- Label and Label Position --> <!-- Before --> <ion-item> <ion-labelposition="floating">Email:</ion-label> <ion-input></ion-input> </ion-item> <!-- After --> <ion-item> <ion-inputlabel="Email:"label-placement="floating"></ion-input> </ion-item> <!-- Fill --> <!-- Before --> <ion-itemfill="outline"shape="round"> <ion-labelposition="floating">Email:</ion-label> <ion-input></ion-input> </ion-item> <!-- After --> <!-- Inputs using `fill` should not be placed in ion-item --> <ion-inputfill="outline"shape="round"label="Email:"label-placement="floating"></ion-input> <!-- Input-specific features on ion-item --> <!-- Before --> <ion-itemcounter="true"> <ion-labelposition="floating">Email:</ion-label> <ion-inputmaxlength="100"></ion-input> <divslot="helper">Enter an email</div> <divslot="error">Please enter a valid email</div> </ion-item> <!-- After --> <ion-item> <ion-input label="Email:" counter="true" maxlength="100" helper-text="Enter an email" error-text="Please enter a valid email" ></ion-input> </ion-item>
<!-- Label and Label Position --> <!-- Before --> <ion-item> <ion-labelposition="floating">Email:</ion-label> <ion-input></ion-input> </ion-item> <!-- After --> <ion-item> <ion-inputlabel="Email:"labelPlacement="floating"></ion-input> </ion-item> <!-- Fill --> <!-- Before --> <ion-itemfill="outline"shape="round"> <ion-labelposition="floating">Email:</ion-label> <ion-input></ion-input> </ion-item> <!-- After --> <!-- Inputs using `fill` should not be placed in ion-item --> <ion-inputfill="outline"shape="round"label="Email:"labelPlacement="floating"></ion-input> <!-- Input-specific features on ion-item --> <!-- Before --> <ion-item[counter]="true"> <ion-labelposition="floating">Email:</ion-label> <ion-inputmaxlength="100"></ion-input> <divslot="helper">Enter an email</div> <divslot="error">Please enter a valid email</div> </ion-item> <!-- After --> <ion-item> <ion-input label="Email:" [counter]="true" maxlength="100" helperText="Enter an email" errorText="Please enter a valid email" ></ion-input> </ion-item>
{/* Label and Label Position */} {/* Before */} <IonItem> <IonLabelposition="floating">Email:</IonLabel> <IonInput></IonInput> </IonItem> {/* After */} <IonItem> <IonInputlabel="Email:"labelPlacement="floating"></IonInput> </IonItem> {/* Fill */} {/* Before */} <IonItemfill="outline"shape="round"> <IonLabelposition="floating">Email:</IonLabel> <IonInput></IonInput> </IonItem> {/* After */} {/* Inputs using `fill` should not be placed in IonItem */} <IonInputfill="outline"shape="round"label="Email:"labelPlacement="floating"></IonInput> {/* Input-specific features on IonItem */} {/* Before */} <IonItemcounter={true}> <IonLabelposition="floating">Email:</IonLabel> <IonInputmaxlength="100"></IonInput> <divslot="helper">Enter an email</div> <divslot="error">Please enter a valid email</div> </IonItem> {/* After */} <IonItem> <IonInput label="Email:" counter={true} maxlength="100" helperText="Enter an email" errorText="Please enter a valid email" ></IonInput> </IonItem>
<!-- Label and Label Position --> <!-- Before --> <ion-item> <ion-labelposition="floating">Email:</ion-label> <ion-input></ion-input> </ion-item> <!-- After --> <ion-item> <ion-inputlabel="Email:"label-placement="floating"></ion-input> </ion-item> <!-- Fill --> <!-- Before --> <ion-itemfill="outline"shape="round"> <ion-labelposition="floating">Email:</ion-label> <ion-input></ion-input> </ion-item> <!-- After --> <!-- Inputs using `fill` should not be placed in ion-item --> <ion-inputfill="outline"shape="round"label="Email:"label-placement="floating"></ion-input> <!-- Input-specific features on ion-item --> <!-- Before --> <ion-item:counter="true"> <ion-labelposition="floating">Email:</ion-label> <ion-inputmaxlength="100"></ion-input> <divslot="helper">Enter an email</div> <divslot="error">Please enter a valid email</div> </ion-item> <!-- After --> <ion-item> <ion-input label="Email:" :counter="true" maxlength="100" helper-text="Enter an email" error-text="Please enter a valid email" ></ion-input> </ion-item>
Ionic uses heuristics to detect if an app is using the modern input syntax. In some instances, it may be preferable to continue using the legacy syntax. Developers can set the legacy property on ion-input to true to force that instance of the input to use the legacy syntax.
While not required, this interface can be used in place of the CustomEvent interface for stronger typing with Ionic events emitted from this component.
Indicates whether and how the text value should be automatically capitalized as it is entered/edited by the user. Available options: "off", "none", "on", "sentences", "words", "characters".
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.
Set the amount of time, in milliseconds, to wait to trigger the ionChange event after each keystroke. This also impacts form bindings such as ngModel or v-model.
If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the maximum number of characters that the user can enter.
If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the minimum number of characters that the user can enter.
A regular expression that the value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is "text", "search", "tel", "url", "email", "date", or "password", otherwise it is ignored. When the type attribute is "date", pattern will only be used in browsers that do not support the "date" input type natively. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date for more information.
Instructional text that shows before the input has a value. This property applies only when the type property is set to "email", "number", "password", "search", "tel", "text", or "url", otherwise it is ignored.
The initial size of the control. This value is in pixels unless the value of the type attribute is "text" or "password", in which case it is an integer number of characters. This attribute applies only when the type attribute is set to "text", "search", "tel", "url", "email", or "password", otherwise it is ignored.
Works with the min and max attributes to limit the increments at which a value can be set. Possible values are: "any" or a positive floating point number.