HTML th Tag scope Attribute Tutorial

In this section, we will learn what the scope attribute is in HTML <th> element and how to use it.

What is scope Attribute in HTML <th> Tag?

HTML <th> element is used as either to create header cells of a table column or as the header (the first cell) of a table row (inside the body of a table).

So, in order to declare where a <th> element is being used, we implement the scope attribute.

There two possible values for this attribute: “col”, “row”.

These values mainly used in other programming languages like JavaScript when we access a table and its header cells to differentiate between which one is a header cell of a column and which one is a header cell for a row in the body of a table.

HTML scope Attribute in <th> Tag Syntax:

<th scope = “row | col”> </th>

<th> Tag scope Attribute Values

This attribute has two possible values:

  • row: if the target <th> element is used to represent the head cell of a row; this is the value we set for the scope attribute.
  • col: on the other hand, if the target <th> element is used to represent a cell in the header of a table, then this is the value we use for the scope attribute.

Example: using scope attribute in HTML <th> tag

See the Pen using scope attribute in HTML <th> tag by Omid Dehghan (@odehghan) on CodePen.

Leave a Reply