The rowspan attribute is a hypertext markup language (HTML) feature that enables a table cell in a web page to extend over multiple rows. HTML is one of the main ways in which web pages are created. Typically, a web browser decodes HTML sent by a website and displays the results on a computer screen in a readable format. HTML incorporates the concept of a table to organize the contents on a page.
A table has multiple rows and columns that vertically and horizontally organize information. When displaying an HTML table, one often would like a single content item to apply or spread over multiple rows. In a table, rowspan=N – where N is a number such as 2, 3, etc. – indicates that the cell spreads over that many rows.
Consider an example where sales data is shown as a table with three column headings: the sales region, the person heading the region, and the sales amount. The South region had a change of head during the recording period; the respective amounts are to be attributed to both people. The following code achieves this.
<tr><td rowspan="2">South</td> <td>Lilian</td><td>$1,180</td></tr>
In this example, a table is created. The headings Region, Head person, and Sales are specified followed by four rows of data. Each cell in the table is indicated by the table data (td) attribute. The data for South goes across two rows, so, by specifying rowspan=2, the word South extends across two rows. The next row has just two td attributes and not three as in all the other rows.
One can copy this code into a text file and bring it up in a browser to view the effect. Blank spaces have been added in this code to easily identify the sales heads, but they are not necessary. The following is a slightly different example where one person, Lilian, heads two regions: South and West.
A web page may not need to show data in a tabular form. It could have a header such as the company name and logo, one or more menus on top or at the side, main information in the middle, and so on. In creating such a web page, a table structure often is used underneath without the reader being aware of it. To give a smooth effect, the rowspan attribute is used whenever some of the content spreads over multiple rows.
One may want to create a personal web page, for instance, that includes three columns of information: Family, Career, and Community. Each column can have a brief introduction, a photo, and details. In order to make the page look better, a band of color could be used along the right-hand side. In this case, the rowspan feature can be utilized to indicate that the band of color spans all rows.