Making table rows clickable

Our example table

For clarity, we'll use a short table of invoices. The Reference column contains a unique identifier for each row.

In situations where we don't have a unique identifier for each row, it might be worth asking if we there should be one. Is it clear what each row is referring to?

Reference To Description Amount
INV-004 Scarlett Papava Plane ticket 1,000
INV-008 Alec Trevelyan Statue with two faces 500

Make it clickable!

Here are some things to consider for best usability and accessibility.

Some options:

The DOM looks like: table > tr > td > a.

Reference To Description Amount
INV-004 Scarlett Papava Plane ticket 1,000
INV-008 Alec Trevelyan Statue with two faces 500

The DOM looks like: table > tr > td > a.

Reference To Description Amount
INV-004 Scarlett Papava Plane ticket 1,000
INV-008 Alec Trevelyan Statue with two faces 500

Option: wrap each row in a link

The DOM looks like: table > a > tr > td. This is invalid HTML, so it causes errors.

Reference To Description Amount
INV-004 Scarlett Papava Plane ticket 1,000
INV-008 Alec Trevelyan Statue with two faces 500

Option: wrap each row of cells in a link

The DOM looks like: table > tr > a > td. This is invalid HTML, so it causes errors.

Reference To Description Amount
INV-004 Scarlett Papava Plane ticket 1,000
INV-008 Alec Trevelyan Statue with two faces 500

Option: give each row a role of link

For this option, we need to add keyboard interactivity to each row, add JavaScript to handle the click events, and add hover styles.

Reference To Description Amount
INV-004 Scarlett Papava Plane ticket 1,000
INV-008 Alec Trevelyan Statue with two faces 500