Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML Tables

HTML Tables


HTML tables are composed of

An HTML table is a markup language element used to display structured data.

Each table has several rows (defined by

tags). tags), and each row is divided into several cells (defined by is used to define the header section of the table: in In it, use is used to define the body section of the table: in In it, use The element defines rows, and within each row,
tags). A table can contain a header row ( ) used to define the column headings.

  • tr: tr is short for table row, representing a row in a table.
  • td: td is short for table data, representing a data cell in a table.
  • th: th is short for table header, representing a header cell in a table.

Data cells can contain text, images, lists, paragraphs, forms, horizontal lines, tables, and so on.

HTML Table Generator:https://www.jyshare.com/front-end/7688/。

The following is a simple HTML table example:

Example

 

   

     

     

     

   

 

 

   

     

     

     

   

   

     

     

     

   

 

Column Heading 1

Column Heading 2

Column Heading 3

Row 1, Column 1

Row 1, Column 2

Row 1, Column 3

Row 2, Column 1

Row 2, Column 2

Row 2, Column 3

In the table example code above,

The element defines the column headings. In the example above, the column headings are "Column Heading 1", "Column Heading 2", and "Column Heading 3".

  • the element defines cell data. In the example above, there are two rows of data, each containing three cells.

    By using

    The element represents the entire table, which contains two main sections: and 。 (table footer) andwhich can be used to define summaries, statistics, and other content at the bottom of a table.
    The element defines a column header, allowing it to be displayed in bold in the table to distinguish it from ordinary cells.

    HTML tables can also have other sections, such as

    (table caption), can be used to define a title for the entire table.

    HTML tables also support merging cells, spanning rows/columns, and the application of other styles and attributes to meet various needs.

    We can also use CSS to further customize the style and appearance of the table.


    Online example

    Example

    <

    h4

    One column:

    h4

    <table border="1">
    <tr>
    <td100 td tr table>
    <h4>

    One row with three columns:

    h4

    <
    
    table
    
    border
    
    =
    
    "
    
    1
    
    "
    
    <
    
    tr
    
    <
    
    td
    
    100
    
    td
    
    <
    
    td
    
    200
    
    td
    
    <
    
    td
    
    300
    
    td
    
    tr
    
    table
    
    <
    
    h4

    Two rows with three columns:

    h4

    <
    
    table
    
    border
    
    =
    
    "
    
    1
    
    "
    
    <
    
    tr
    
    <
    
    td
    
    100
    
    td
    
    <
    
    td
    
    200
    
    td
    
    <
    
    td
    
    300
    
    td
    
    tr
    
    <
    
    tr
    
    <
    
    td
    
    400
    
    td
    
    <
    
    td
    
    500
    
    td
    
    <
    
    td
    
    600
    
    td
    
    tr
    
    table

    Try it »

    (More examples can be found at the bottom of this page.)

    Table example

    Example

    <table border="1">
    <tr>
    <td>

    row 1, cell 1

    td

    <

    td

    row 1, cell 2

    td

    tr

    <
    
    tr
    
    <
    
    td

    row 2, cell 1

    td

    <

    td

    row 2, cell 2

    td

    tr

    table

    Displayed in the browser as follows::


    HTML Tables and Border Attributes

    If the border attribute is not defined, the table will not display a border. Sometimes this is useful, but most of the time, we want to display a border.

    Use the border attribute to display a table with a border:

    Example

    <table border="1">
    <tr>
    <td>

    Row 1, cell 1

    td

    <

    td

    Row 1, cell 2

    td

    tr

    table


    HTML Table Headers

    The table header is defined using the

    tag.

    Most browsers display the header as bold, centered text:

    Example

    <table border="1">
    <tr>
    <th>

    Header 1

    th

    <

    th

    Header 2

    th

    tr

    <
    
    tr
    
    <
    
    td

    row 1, cell 1

    td

    <

    td

    row 1, cell 2

    td

    tr

    <
    
    tr
    
    <
    
    td

    row 2, cell 1

    td

    <

    td

    row 2, cell 2

    td

    tr

    table

    Displayed in the browser as follows:


    More examples

    A table without borders
    This example demonstrates a table without a border.

    Headers in a table (Heading)
    This example demonstrates how to display a table header.

    A table with a caption
    This example demonstrates a table with a caption

    Table cells spanning rows or columns
    This example demonstrates how to define table cells that span rows or columns.

    Tags inside a table
    This example demonstrates how to display elements within different elements.

    Cell padding (Cell padding)
    This example demonstrates how to use Cell padding to create space between the cell content and its border.

    Cell spacing (Cell spacing)
    This example demonstrates how to use Cell spacing to increase the distance between cells.

    Beautiful table


    HTML Table Tags

    tag Description
    Defines a table
    Defines a header cell in a table
    Defines a row in a table
    Defines a cell in a table
    Defines a table caption
    Defines a group of columns in a table
    Defines attributes for table columns
    Defines the header section of a table
    Defines the body section of a table
    Defines the footer section of a table