Testing the axe rule aria-conditional-attr

Test cases for the axe-core rule aria-conditional-attr (axe-core 4.14). The rule checks ARIA attributes that are only allowed under certain conditions. It looks at three things:

One thing to know up front: the rule doesn't fail every aria-checked on a native checkbox. It only fails when the value disagrees with the real state, at the moment axe runs.

Every example is live in the page, so you can run the axe extension straight over it. The expected results were checked by running axe-core 4.14.1 over this page. Look in both the axe issues list and the needs review list.

Number of test cases by expected result
Expected resultCases
Fail11
Flagged by a different rule instead5
Passes, but broken (axe misses it)2
Pass (valid control cases)7
Changes after interaction2

Sections

Checkbox state disagrees

The checkbox says one thing, aria-checked says another. Screen readers may announce either.

A1 Unticked, but aria-checked="true"

<label><input type="checkbox" aria-checked="true"> Send me updates</label>

Expected result: fail

A2 Ticked, but aria-checked="false"

<label><input type="checkbox" checked aria-checked="false"> Remember me</label>

Expected result: fail

A3 aria-checked="mixed" on a normal checkbox

A native checkbox is only mixed when its indeterminate property is set with JavaScript.

<label><input type="checkbox" aria-checked="mixed"> Select all</label>

Expected result: fail

Radio state disagrees

Radio buttons get the same check, but they can't be mixed.

B1 Unselected, but aria-checked="true"

Delivery
<fieldset>
  <legend>Delivery</legend>
  <label><input type="radio" name="b1" aria-checked="true"> Standard</label>
  <label><input type="radio" name="b1"> Express</label>
</fieldset>

Expected result: fail

States that match

Control cases. These pass because aria-checked agrees with the real state. They're still redundant, and the Deque page recommends removing aria-checked from native checkboxes altogether. The interaction cases at the end show why.

C1 Ticked and aria-checked="true"

<label><input type="checkbox" checked aria-checked="true"> I agree</label>

Expected result: pass (valid)

C2 Unticked and aria-checked="false"

<label><input type="checkbox" aria-checked="false"> Add gift wrap</label>

Expected result: pass (valid)

C3 Indeterminate and aria-checked="mixed"

The script below sets indeterminate on page load, so the states match.

<label><input type="checkbox" id="c3-input" aria-checked="mixed"> All toppings</label>

Expected result: pass (valid)

C4 Selected radio and aria-checked="true"

Size
<fieldset>
  <legend>Size</legend>
  <label><input type="radio" name="c4" checked aria-checked="true"> Small</label>
  <label><input type="radio" name="c4"> Large</label>
</fieldset>

Expected result: pass (valid)

C5 Custom checkbox

The rule only checks native inputs. On a custom checkbox, aria-checked is the only state there is.

Subscribe
<div role="checkbox" tabindex="0" aria-checked="true">Subscribe</div>

Expected result: pass (valid)

Row attributes outside a treegrid

aria-level, aria-expanded, aria-posinset and aria-setsize only make sense on rows in a treegrid. In a table or grid they do nothing.

D1 aria-level on a table row

My downloads
<table>
  <tr aria-level="1"><td>My downloads</td></tr>
</table>

Expected result: fail

D2 aria-expanded on a table row

<table>
  <tr aria-expanded="false"><td>2025 invoices</td></tr>
</table>

Expected result: fail

D3 aria-posinset and aria-setsize on a table row

Chapter one
<table>
  <tr aria-posinset="1" aria-setsize="3"><td>Chapter one</td></tr>
</table>

Expected result: fail

D4 aria-level on a row in a grid table

Reports
<table role="grid" aria-label="Files">
  <tr aria-level="1"><td>Reports</td></tr>
</table>

Expected result: fail

D5 aria-expanded on an ARIA grid row

Order 1042
<div role="grid" aria-label="Orders">
  <div role="row" aria-expanded="true">
    <div role="gridcell">Order 1042</div>
  </div>
</div>

Expected result: fail

D6 aria-level on an ARIA table row

Introduction
<div role="table" aria-label="Contents">
  <div role="row" aria-level="2">
    <div role="cell">Introduction</div>
  </div>
</div>

Expected result: fail

D7 A table nested inside a treegrid

The outer treegrid doesn't help. Axe looks at the nearest table, which is the inner one.

Budget
<div role="treegrid" aria-label="Projects">
  <div role="row" aria-level="1">
    <div role="gridcell">
      <table>
        <tr aria-level="2"><td>Budget</td></tr>
      </table>
    </div>
  </div>
</div>

Expected result: fail

The outer row (inside the treegrid) passes. Only the inner one fails.

Rows that pass

Control cases.

E1 Row attributes in a treegrid

<table role="treegrid" aria-label="Folders">
  <tr aria-level="1" aria-expanded="false">
    <td role="gridcell">Photos</td>
  </tr>
</table>

Expected result: pass (valid)

E2 Other row attributes in a plain table

aria-selected and aria-rowindex aren't on the list, so this rule doesn't care about them.

Invoice 7
<table>
  <tr aria-selected="true" aria-rowindex="1"><td>Invoice 7</td></tr>
</table>

Expected result: pass (valid)

Flagged by a different rule instead

This rule doesn't flag these, but another one does.

F1 aria-checked="banana" on an unticked checkbox

This rule treats any unknown value as false, which happens to match.

<label><input type="checkbox" aria-checked="banana"> Fruit box</label>

Expected result: flagged by aria-valid-attr-value instead

F2 Empty aria-checked

This rule ignores an empty value.

<label><input type="checkbox" checked aria-checked=""> Newsletter</label>

Expected result: flagged by aria-valid-attr-value instead

F3 aria-checked="TRUE" on a ticked checkbox

This rule ignores case, so it matches.

<label><input type="checkbox" checked aria-checked="TRUE"> Terms</label>

Expected result: flagged by aria-allowed-attr instead

F4 A row with no table at all

With no table, grid or treegrid around it, this rule has nothing to compare against.

Orphan row
<div role="row" aria-level="1">
  <div role="cell">Orphan row</div>
</div>

Expected result: flagged by aria-required-parent instead

F5 Row in a presentation table

role="presentation" removes the table semantics, so the row isn't a row any more.

Layout cell
<table role="presentation">
  <tr aria-level="1"><td>Layout cell</td></tr>
</table>

Expected result: flagged by aria-allowed-attr instead

Missed completely

Nothing in axe flags these.

G1 Native checkbox with role="switch"

The same mismatch as A1. But because the role is switch, not checkbox, this rule doesn't check it. Which state gets announced depends on the browser.

<label><input type="checkbox" role="switch" aria-checked="true"> Dark mode</label>

Expected result: passes, but it's broken (check manually)

G2 aria-checked="mixed" on a radio button

Radios can't be mixed. The rule quietly treats mixed as false, which matches the unselected radio.

Colour
<fieldset>
  <legend>Colour</legend>
  <label><input type="radio" name="g2" aria-checked="mixed"> Red</label>
  <label><input type="radio" name="g2"> Blue</label>
</fieldset>

Expected result: passes, but it's broken (check manually)

Changes after interaction

Axe only sees the page as it is when you run it. These pass on page load. Activate each button, then run axe again.

H1 Checkbox goes stale when ticked

aria-checked="false" matches on load. Tick the checkbox and the native state changes, but aria-checked doesn't. This is the best argument for never putting aria-checked on a native checkbox.

<label><input type="checkbox" id="h1-input" aria-checked="false"> Email me a receipt</label>

On load: pass. After ticking: fail

H2 Radio group goes stale

Both radios match on load. Choose "Pick up" and both are now wrong: the first still says true and the second still says false.

Collection
<fieldset>
  <legend>Collection</legend>
  <label><input type="radio" name="h2" checked aria-checked="true"> Delivery</label>
  <label><input type="radio" name="h2" id="h2-pickup" aria-checked="false"> Pick up</label>
</fieldset>

On load: pass. After choosing Pick up: fail