How to provide external label referenced to the ion-checkbox with the for attribute in ionic v7?

I’m rendering labels for ionic checkboxes separately from the ion-checkbox, because they positioned above the element. Then I need to reference on appropriate checkbox from the respective label. And the attribute for doesn’t work. Any workarounds?

Are you using checkbox list ?? Share your code

You’ll need to add an aria-label to ion-checkbox in this case. However, having stacked labels for other form controls built-in might be nice to have. Could you file a feature request? Issues · ionic-team/ionic-framework · GitHub

<div class="week-container" formGroupName="weekDays">
    *ngFor="let day of weekDays; let i = index"
    id="day{{ i }}-label"
    >{{ day }}</label
    *ngFor="let control of dayArray.controls; let i = index"
    formControlName="{{ i }}"
    aria-labelledby="day{{ i }}-label"

week-container is grid
It looks following:

Thank you! I’ve made a feature request. Probably I use aria-label the wrong way, but I can’t make it work.

Check if it works

<ion-list > 
            <ion-col size-lg="1" *ngFor="let day of weekDays; let i = index">
              <ion-checkbox formControlName="days"
              justify="start"  (ionChange)="onDaySelect(day)"
    if(day && day.checked==true)      

To provide an external label for an ion-checkbox in Ionic v7 using the for attribute, you can do the following:

Add a unique id attribute to the ion-checkbox element. This ID will be used to reference the checkbox in the external label.
Copy code

Add a label element outside the ion-checkbox element and use the for attribute to reference the id of the checkbox. You can also add text or other elements inside the label element.
Copy code
Check this box
Style the label element as desired using CSS.
Copy code
label {
display: inline-block;
margin-left: 10px;
The final code will look like this:

Copy code


Check this box
This will create an external label that is associated with the ion-checkbox using the for attribute. When the label is clicked, it will toggle the checkbox.

Thank you! Of course, it renders the needed layout. The problem is that the desired behavior is when you click the label the appropriate checkbox should be triggered. This is standard expected behavior for the checkbox labels, usually done by providing a unique ID to the checkbox and setting attribute for to the label.

Add a unique id attribute to the ion-checkbox element. This ID will be used to reference the checkbox in the external label.

Thank you! Exactly this point does not work.