HTML Table
HTML Table
HTML Table
</>
Topics Covered
Introduction to table tag and its Attribute
Simple Tabl
Expanding Cell
Adding Captio
Giving Structure to Table (thead, tfoot, tbody)
For example : Storing tabular data, like a person and their age, or a day of the week, or the timetable for a local
swimming pool.
The HTML table tag has a lot of attributes like bgcolor, bordercolor, cellborder, frame, rules, width, height,
align, valign etc. but majority of them are deprecated in favour of using CSS to style the table.
Simple Table
Lets understand with this one example,
Michael 22 Chicago
Suppose, we want to display the above table in HTML. To construct tables in HTML, we use <table>, <tr>, <th>,
and <td> tags.
table.html
In above example
The <table> element is used to create a table in HTML
The <tr> element represents a row in the table
The <th> element represents a header cell in the table, and is typically used in the first row to label the
columns
The <td> element represents a data cell in the table, and is used to display the actual data in the table.
Expanding Cells
We can expand any table cells across multiple columns and rows using attributes rowspan and colspan,
demo.html
In the above example, the last row 1st cell is expanded across two columns, using colspan=”2” attribute.
Similarly we can expand any cell across multiple rows also, using rowspan attribute.
Adding a caption
To add a caption to your table, simply enclose the caption text within a <caption> element and place it within
the <table> element.
One effective approach is to utilise HTML elements such as <thead>, <tfoot>, and <tbody>, which enable you to
designate a header, footer, and body section for your table, respectively.
demo.html
In above example
<thead>: This element is used to define the header section of a table, which typically contains one or more
rows that serve as labels for the columns of the table
<tbody>: This element is used to group the body content of a table, which includes the actual data rows
<tfoot>: This element is used to define the footer section of a table, which typically contains summary or
aggregate information about the data in the table.
But Wait! There is no difference in browser output after applying structural tags in the products table.
Yes, these elements do not make any semantic or visual difference, they are just used to style different parts of
the table effectively.