Can the rowspan attribute only be used within `<td>` tags?

Question

Can the rowspan attribute only be used within <td> tags?

Answer

No. The rowspan attribute can also be used on <th> tags. For improved accessibility, when we create table headings that span multiple rows, we should also include the scope=”rowgroup” attribute within the opening <th> tag.

14 Likes

Why is it again that we would include scope=“rowgroup” attribute and not just use rowspan?
I might have overlooked the explanation for it or forgotten if it was mentioned before.

2 Likes

They are two completely different attributes. A rowgroup in terms of scope is a group of table rows. It defines a relationship between those rows and the TH used.

rowspan deals with how the cell is drawn. If the rowspan is two or more, it will have the height of that many rows.

25 Likes

Is it already set where the rowspan and colspan attributes expand into(like always expand downwards for rowspan and right for colspan), or do they fill the nearest empty cell?

4 Likes

my is taking a long to load

To expand on using rowspan on table headers, there are several more steps you have to take in order to provide an accessible table with irregular headers that correctly informs users using assistive technologies of the structure of the table (such as specifying the rowgroup). You can read the details here: https://www.w3.org/WAI/tutorials/tables/irregular/

1 Like

Maybe the issue is your browser. I use Google Chrome and sometimes it takes way too long to load the pages on Codecademy, so I found a Youtube video showing how to clear things up in command prompt, and it works well.

1 Like

Thank you for the explanation

1 Like