10 HTML table-related tags

10 HTML table-related tags
In fact many people will say “I’ve seen that tables should never be used”, but this is absolutely wrong! This advice is only for using HTML tables to define the layout of your web page, but tables are perfect for conveniently arranging rows and columns of information, and if you absolutely must display tabular data on a page, you have to use them! why not? However, in this case, some people ignore the existence of certain HTML tags for tables and don’t know how to use them correctly.

HTML has 10 table-related tags. Here is a list with a brief introduction, but first, the document should be properly defined in HTML 4.01/XHTML 1 or HTML 5:

  • <caption> defines the table title (4, 5)
  • <col> defines attributes for table columns (4, 5)
  • <colgroup> defines the grouping of table columns (4, 5)
  • <table> defines a table (4, 5)
  • <tbody> defines the table body (4, 5)
  • <td> defines a cell (4, 5)
  • <tfoot> defines the footer of the table (4, 5)
  • <th> defines the table header (4, 5)
  • <thead> defines the table header (4, 5)
  • <tr> defines the rows of the table (4, 5)

A basic table structure is as follows:

Re-understanding table

It contains a title, header, body, and footer. The correct order of HTML elements is:

  1. <table>
  2. <caption>
  3. <thead>
  4. <tfoot>
  5. <tbody>

You can also use <col> and <colgroup> to define table columns or group columns:

  1. <table>
  2. <caption>
  3. <colgroup>
  4. <col>
  5. <thead>
  6. <tfoot>
  7. <tbody>

The following is an example of a correct table structure:

Copy code
The code is as follows:

<table border="1">
<caption>Table caption here</caption>
<colgroup span="1" style="background:#DEDEDE;"/>
<colgroup span="2" style="background:#EFEFEF;"/>
<!-- Table Header-->
<thead>
<tr>
<th>Head 1</th>
<th>Head 2</th>
<th>Head 3</th>
</tr>
</thead>
<!-- Table Footer-->
<tfoot>
<tr>
<td>Foot 1</td>
<td>Foot 2</td>
<td>Foot 3</td>
</tr>
</tfoot>
<!-- Table Body-->
<tbody>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
<tr>
<td>D</td>
<td>E</td>
<td>F</td>
</tr>
</tbody>
</table>

The result in the browser is shown below:
Re-understanding table

Some tips about tables

  • According to the explanation and usage of w3schools, in a table definition, the <tfoot> element must appear before the <tbody> so that the browser can render the table footer before receiving all the data. Additionally, if it is not in this order, it will fail W3C HTML4 and XHTML validation, no matter which DTD you declare.
  • In HTML 4.01, the table attributes align and bgcolor were deprecated, so there are no longer any table attributes supported in HTML 5 (in fact, the "align" and "bgcolor" attributes are no longer supported in XHTML 1.0 Strict DTD);
  • All major browsers support the <colgroup> tag, but Firefox, Chrome, and Safari only support the span and width attributes of the colgroup element;
  • empty-cells:show|hide in CSS can set whether empty cells display borders. Note that this needs to be set in the table rather than in the td/th element . This problem is more likely to occur in IE6;
  • border-collapse:collapse | separate in CSS can set whether the borders of the table are merged into one border;
  • The border-spacing property in CSS is equivalent to the cellspacing property of table.

In order to achieve the currently advocated development model of separation of presentation and structure, Front-end Observation recommends that all presentation-related things on the page be controlled by CSS, instead of using HTML's own attributes to control the presentation of the page. Tables are the most easily overlooked ones.

For more details about tables, see the W3C document: w3 Introduction to tables

Finally, I leave you with a very simple question. Which CSS property is equivalent to the cellpadding property of the table?

<<:  Detailed explanation of mixed inheritance in Vue

>>:  How to invert the implementation of a Bezier curve in CSS

Recommend

Steps to use autoconf to generate Makefile and compile the project

Preface Under Linux, compilation and linking requ...

Three networking methods and principles of VMware virtual machines (summary)

1. Brigde——Bridge: VMnet0 is used by default 1. P...

How to safely shut down MySQL

When shutting down the MySQL server, various prob...

Solve the problem of not finding NULL from set operation to mysql not like

An interesting discovery: There is a table with a...

How to use flat style to design websites

The essence of a flat website structure is simpli...

HTML form tag tutorial (5): text field tag

<br />This tag is used to create a multi-lin...

Solution to interface deformation when setting frameset height

Currently I have made a project, the interface is ...

Introduction to MySQL isolation level, lock and MVCC

This article aims to clarify the relationship bet...

MySQL FAQ series: When to use temporary tables

Introduction to temporary tables What is a tempor...

JavaScript file loading and blocking issues: performance optimization case study

Let me start with a question: When writing an HTM...

Detailed steps to build the TypeScript environment and deploy it to VSCode

Table of contents TypeScript environment construc...

Detailed example of using useState in react

useState useState adds some internal state to a c...

Take you to understand MySQL character set settings in 5 minutes

Table of contents 1. Content Overview 2. Concepts...

idea combines docker to realize image packaging and one-click deployment

1. Install Docker on the server yum install docke...