Labels should be used to describe the input. They can be used visually, and they will also be read out by screen readers when the user is focused on the input. This makes it easy for the user to understand the intent of the input. Input has several ways to assign a label:
label property: used for plaintext labels
label slot: used for custom HTML labels (experimental)
aria-label: used to provide a label for screen readers but adds no visible label
While plaintext labels should be passed in via the label property, if custom HTML is needed, it can be passed through the label slot instead.
Note that this feature is considered experimental because it relies on a simulated version of Web Component slots. As a result, the simulated behavior may not exactly match the native slot behavior.
Input masks are expressions that constrain input to support valid input values. Ionic recommends using Maskito for input masking. Maskito is a lightweight, dependency-free library for masking input fields. It supports a wide range of masks, including phone numbers, credit cards, dates, and more.
<!-- 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 --> <!-- Metadata such as counters and helper text should not be used when an input is in an item/list. If you need to provide more context on a input, consider using an ion-note underneath the ion-list. --> <ion-input label="Email:" counter="true" maxlength="100" helper-text="Enter an email" error-text="Please enter a valid email" ></ion-input>
<!-- 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 --> <!-- Metadata such as counters and helper text should not be used when an input is in an item/list. If you need to provide more context on a input, consider using an ion-note underneath the ion-list. --> <ion-input label="Email:" [counter]="true" maxlength="100" helperText="Enter an email" errorText="Please enter a valid email" ></ion-input>
{/* 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 */} {/* Metadata such as counters and helper text should not be used when an input is in an item/list. If you need to provide more context on a input, consider using an IonNote underneath the IonList. */} <IonInput label="Email:" counter={true} maxlength="100" helperText="Enter an email" errorText="Please enter a valid email" ></IonInput>
<!-- 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 --> <!-- Metadata such as counters and helper text should not be used when an input is in an item/list. If you need to provide more context on a input, consider using an ion-note underneath the ion-list. --> <ion-input label="Email:" :counter="true" maxlength="100" helper-text="Enter an email" error-text="Please enter a valid email" ></ion-input>