{"id":60,"date":"2022-03-19T09:56:53","date_gmt":"2022-03-19T09:56:53","guid":{"rendered":"https:\/\/staging.brightwhiz.com\/?post_type=topic&p=60"},"modified":"2022-03-19T09:56:53","modified_gmt":"2022-03-19T09:56:53","slug":"html-tables","status":"publish","type":"topic","link":"http:\/\/local.tutorials\/topic\/html-tables\/","title":{"rendered":"HTML – Tables"},"content":{"rendered":"\n

HTML tables are used to arrange HTML-supported data into rows and columns of cells.<\/p>\n\n\n\n

HTML tables are created using the <table><\/code> tag. Within the tags, you typically use the <tr><\/code> tag to create table rows. Tr stands for table row. Inside the <tr><\/code> tag, you can use the <td><\/code> tag to create data cells. Td stands for table data. The content is placed under the <td><\/code> tag.<\/p>\n\n\n\n

Example:<\/p>\n\n\n\n

<!DOCTYPE html>\n<html>\n   <head>\n      <title>HTML Tables Example<\/title>\n   <\/head>\n   <body>\n      <table border="1">\n         <tr>\n            <td>Row 1, Column 1<\/td>\n            <td>Row 1, Column 2<\/td>\n            <td>Row 1, Column 3<\/td>\n         <\/tr>\n         <tr>\n            <td>Row 2, Column 1<\/td>\n            <td>Row 2, Column 2<\/td>\n            <td>Row 2, Column 3<\/td>\n         <\/tr>\n         <tr>\n            <td>Row 3, Column 1<\/td>\n            <td>Row 3, Column 2<\/td>\n            <td>Row 3, Column 3<\/td>\n         <\/tr>\n      <\/table>\n      \n   <\/body>\n<\/html><\/code><\/pre>\n\n\n\n

The above code will produce a table such as this:<\/p>\n\n\n\n

Row 1, Column 1<\/td>Row 1, Column 2<\/td>Row 1, Column 3<\/td><\/tr>
Row 2, Column 1<\/td>Row 2, Column 2<\/td>Row 2, Column 3<\/td><\/tr>
Row 3, Column 1<\/td>Row 3, Column 2<\/td>Row 3, Column 3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

We’ve used the border attribute to give the table and cells a border of 1 pixel.<\/p>\n\n\n\n

Table Heading<\/h2>\n\n\n\n

You can use the <th><\/code> tag to define a table heading. <th><\/code> tags replace <td><\/code> tags in rows where you want to specify a heading. Typically they would be used on the first row even though they can appear on any row.<\/p>\n\n\n\n

Example<\/p>\n\n\n\n

This HTML table uses table headings on the first row.<\/p>\n\n\n\n

<table>\n  <tr>\n    <th>Company<\/th>\n    <th>Owner<\/th>\n    <th>Country<\/th>\n  <\/tr>\n  <tr>\n    <td>Acme Corporation<\/td>\n    <td>Martin Acmes<\/td>\n    <td>England<\/td>\n  <\/tr>\n  <tr>\n    <td>Merlin Fisheries<\/td>\n    <td>Peter Chenney<\/td>\n    <td>Australia<\/td>\n  <\/tr>\n  <tr>\n    <td>Max Agri Tools<\/td>\n    <td>Fred Hammad<\/td>\n    <td>United States<\/td>\n  <\/tr>\n<\/table><\/code><\/pre>\n\n\n\n

The above code will produce a table such as this:<\/p>\n\n\n\n

Company<\/th>Owner<\/th>Country<\/th><\/tr>
Acme Corporation<\/td>Martin Acmes<\/td>England<\/td><\/tr>
Merlin Fisheries<\/td>Peter Chenney<\/td>Australia<\/td><\/tr>
Max Agri Tools<\/td>Fred Hammad<\/td>United States<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

Table Height and Width<\/h2>\n\n\n\n

Use the width and height attributes to set the table size. The dimensions can be set using either pixels or a percentage of the available screen area.<\/p>\n\n\n\n

<table border="1" width="480" height="320">\n   ...\n<\/table><\/code><\/pre>\n\n\n\n

Table Background and Border Color<\/h2>\n\n\n\n

You can set table background color and border color using one of the following attributes depending on what you want to achieve.<\/p>\n\n\n\n

  • bgcolor attribute<\/strong> \u2212 Use this to set the background color for the whole table or if used as a attribute then it will apply to just one cell.<\/li>
  • background attribute<\/strong> \u2212 Use this to set a background image for the whole table or if used as a attribute then it will apply to just one cell.<\/li>
  • bordercolor attribute<\/strong> – Use this to set a border color for the whole table.<\/li><\/ul>\n\n\n\n

    Note <\/strong>\u2212 The bgcolor<\/code>, background<\/code>, and bordercolor<\/code> attributes were deprecated in HTML5. Do not use these attributes. Instead, use the style<\/code> attribute or external CSS styles.<\/p>\n\n\n\n

    Cell Padding and Cell Spacing<\/h2>\n\n\n\n

    You can use the following attributes to control white space within and surrounding cells. The value of these attributes is in pixes.<\/p>\n\n\n\n

    • cellpadding attribute<\/strong> – use this attribute in the <td><\/code> tag to set the white space between the content and the edge of the cell<\/li>
    • cellspacing attribute<\/strong> – Use this attribute in the <td><\/code> tag to set the white space between surrounding cells<\/li><\/ul>\n\n\n\n
      <table border="1" cellpadding="7" cellspacing="7">\n   <tr>\n      <th>Name<\/th>\n      <th>Age<\/th>\n   <\/tr>\n   <tr>\n      <td>Zawadi Amani<\/td>\n      <td>50<\/td>\n   <\/tr>\n   <tr>\n      <td>Mumbi Gichui<\/td>\n      <td>35<\/td>\n   <\/tr>\n<\/table><\/code><\/pre>\n\n\n\n

      The above code will produce a table such as this:<\/p>\n\n\n\n

      Name<\/th>Age<\/th><\/tr>
      Zawadi Amani<\/td>50<\/td><\/tr>
      Mumbi Gichui<\/td>35<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

      Column Spans and Row Spans<\/h2>\n\n\n\n

      You can use the following attributes in the <td><\/code> tags as follows:<\/p>\n\n\n\n

      • colspan attribute – use this attribute to merge cells horizontally<\/li>
      • rowspan attribute – use this attribute to merge cells vertically<\/li><\/ul>\n\n\n\n

        Example<\/p>\n\n\n\n

        colspan and rowspan attributes usage:<\/p>\n\n\n\n

        <table border="1">\n   <tr>\n      <th>Column 1<\/th>\n      <th>Column 2<\/th>\n      <th>Column 3<\/th>\n   <\/tr>\n   <tr>\n      <td colspan="3">Row 1 Cell 1<\/td>\n   <\/tr>\n   <tr>\n      <td rowspan="2">Row 2 Cell 1<\/td>\n      <td>Row 2 Cell 2<\/td>\n      <td>Row 2 Cell 3<\/td>\n   <\/tr>\n   <tr>\n      <td>Row 3 Cell 2<\/td>\n      <td>Row 3 Cell 3<\/td>\n   <\/tr>\n<\/table><\/code><\/pre>\n\n\n\n

        The above code will produce a table such as this:<\/p>\n\n\n\n

        Column 1<\/th>Column 2<\/th>Column 3<\/th><\/tr>
        Row 1 Cell 1<\/td><\/tr>
        Row 2 Cell 1<\/td>Row 2 Cell 2<\/td>Row 2 Cell 3<\/td><\/tr>
        Row 3 Cell 2<\/td>Row 3 Cell 3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

        Table Header, Body, and Footer<\/h2>\n\n\n\n

        HTML tables can be divided into three logical sections namely a header, a body, and a footer.<\/p>\n\n\n\n

        The three elements for sectioning the header, body, and footer of a table are:<\/p>\n\n\n\n

        • <thead><\/code> \u2212 used to create a separate table header.<\/li>
        • <tbody><\/code> \u2212 used to indicate the main body of the table.<\/li>
        • <tfoot><\/code> \u2212 used to create a separate table footer.<\/li><\/ul>\n\n\n\n

          The content within the <thead><\/code> is always displayed at the top of the table while the content within the <tfoot> tag is always at the end of the table. These tags work similarly to the header and footer of a Word Processor where the content in those sections is displayed on every page. A table can have more than one <tbody><\/code> tag. These can act as different pages or groups of data.<\/p>\n\n\n\n

          Example<\/p>\n\n\n\n

          Table showing the use of <thead><\/code>, <tbody><\/code>, <tfoot><\/code> tags:<\/p>\n\n\n\n

          <table>\n  <thead>\n    <tr>\n      <th colspan="2">This is the table header<\/th> \n    <\/tr>\n  <\/thead>\n\n  <tfoot>\n    <tr>\n      <td colspan="2">This is the table footer<\/td> \n    <\/tr>\n  <\/tfoot>\n\n  <tbody>\n    <tr>\n      <td>January<\/td>\n      <td>$100<\/td>\n    <\/tr>\n    <tr>\n      <td>February<\/td>\n      <td>$80<\/td>\n    <\/tr>\n  <\/tbody>\n<\/table><\/code><\/pre>\n\n\n\n

          The above code will produce a table such as this:<\/p>\n\n\n\n

          This is the table header<\/th><\/tr><\/thead>
          January<\/td>$100<\/td><\/tr>
          February<\/td>$80<\/td><\/tr><\/tbody>
          This is the table footer<\/td><\/tr><\/tfoot><\/table><\/figure>\n\n\n\n

          Nested Tables<\/h2>\n\n\n\n

          Tables can be nested within other tables as long as the child table is placed inside a <td><\/code> tag.<\/p>\n\n\n\n

          Example<\/p>\n\n\n\n

          <table border="1" width="100%">\n   <tr>\n     <td>Column 1<\/td>\n     <td>Column 2<\/td>\n   <\/tr>\n   <tr>\n      <td colspan="2">\n         <table border = "1" width = "100%">\n            <tr>\n               <th>Month<\/th>\n               <th>Profit<\/th>\n            <\/tr>\n            <tr>\n               <td>January<\/td>\n               <td>$5000<\/td>\n            <\/tr>\n            <tr>\n               <td>February<\/td>\n               <td>$7000<\/td>\n            <\/tr>\n         <\/table>\n      <\/td>\n   <\/tr>\n<\/table><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

          HTML tables are used to arrange HTML-supported data into rows and columns of cells. HTML tables are created using the <table> tag. Within the tags, you typically use the <tr> tag to create table rows. Tr stands for table row. Inside the <tr> tag, you can use the <td> tag to create data cells. Td […]<\/p>\n","protected":false},"featured_media":43,"comment_status":"open","ping_status":"closed","template":"","meta":[],"categories":[2],"tags":[],"subject":[7,8],"yoast_head":"\nLearn HTML - Tables<\/title>\n<meta name=\"description\" content=\"HTML tables are elements in the HTML that can be used to display content presented in columns and rows with various formatting\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/local.tutorials\/topic\/html-tables\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn HTML - Tables\" \/>\n<meta property=\"og:description\" content=\"HTML tables are elements in the HTML that can be used to display content presented in columns and rows with various formatting\" \/>\n<meta property=\"og:url\" content=\"http:\/\/local.tutorials\/topic\/html-tables\/\" \/>\n<meta property=\"og:site_name\" content=\"Brightwhiz.com Tutorials and Courses\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/brightwhiz\" \/>\n<meta property=\"og:image\" content=\"http:\/\/local.tutorials\/wp-content\/uploads\/2022\/03\/tutorial-html5.png\" \/>\n\t<meta property=\"og:image:width\" content=\"640\" \/>\n\t<meta property=\"og:image:height\" content=\"360\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/local.tutorials\/topic\/html-tables\/\",\"url\":\"http:\/\/local.tutorials\/topic\/html-tables\/\",\"name\":\"Learn HTML - Tables\",\"isPartOf\":{\"@id\":\"http:\/\/local.tutorials\/#website\"},\"datePublished\":\"2022-03-19T09:56:53+00:00\",\"dateModified\":\"2022-03-19T09:56:53+00:00\",\"description\":\"HTML tables are elements in the HTML that can be used to display content presented in columns and rows with various formatting\",\"breadcrumb\":{\"@id\":\"http:\/\/local.tutorials\/topic\/html-tables\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/local.tutorials\/topic\/html-tables\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/local.tutorials\/topic\/html-tables\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/local.tutorials\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"http:\/\/local.tutorials\/topic\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"HTML – Tables\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/local.tutorials\/#website\",\"url\":\"http:\/\/local.tutorials\/\",\"name\":\"Brightwhiz.com Tutorials and Courses\",\"description\":\"\",\"publisher\":{\"@id\":\"http:\/\/local.tutorials\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/local.tutorials\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/local.tutorials\/#organization\",\"name\":\"Brightwhiz.com\",\"url\":\"http:\/\/local.tutorials\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.tutorials\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/staging.brightwhiz.com\/wp-content\/uploads\/2022\/03\/brightwhiz-com-logo-orange.png\",\"contentUrl\":\"https:\/\/staging.brightwhiz.com\/wp-content\/uploads\/2022\/03\/brightwhiz-com-logo-orange.png\",\"width\":706,\"height\":135,\"caption\":\"Brightwhiz.com\"},\"image\":{\"@id\":\"http:\/\/local.tutorials\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/brightwhiz\",\"https:\/\/twitter.com\/brightwhizmag\",\"https:\/\/www.instagram.com\/glamorglaze\/\",\"https:\/\/www.pinterest.com\/sobbayi\/\",\"https:\/\/www.youtube.com\/c\/Sobbayi\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn HTML - Tables","description":"HTML tables are elements in the HTML that can be used to display content presented in columns and rows with various formatting","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/local.tutorials\/topic\/html-tables\/","og_locale":"en_US","og_type":"article","og_title":"Learn HTML - Tables","og_description":"HTML tables are elements in the HTML that can be used to display content presented in columns and rows with various formatting","og_url":"http:\/\/local.tutorials\/topic\/html-tables\/","og_site_name":"Brightwhiz.com Tutorials and Courses","article_publisher":"https:\/\/www.facebook.com\/brightwhiz","og_image":[{"width":640,"height":360,"url":"http:\/\/local.tutorials\/wp-content\/uploads\/2022\/03\/tutorial-html5.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@brightwhizmag","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/local.tutorials\/topic\/html-tables\/","url":"http:\/\/local.tutorials\/topic\/html-tables\/","name":"Learn HTML - Tables","isPartOf":{"@id":"http:\/\/local.tutorials\/#website"},"datePublished":"2022-03-19T09:56:53+00:00","dateModified":"2022-03-19T09:56:53+00:00","description":"HTML tables are elements in the HTML that can be used to display content presented in columns and rows with various formatting","breadcrumb":{"@id":"http:\/\/local.tutorials\/topic\/html-tables\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/local.tutorials\/topic\/html-tables\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/local.tutorials\/topic\/html-tables\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/local.tutorials\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"http:\/\/local.tutorials\/topic\/"},{"@type":"ListItem","position":3,"name":"HTML – Tables"}]},{"@type":"WebSite","@id":"http:\/\/local.tutorials\/#website","url":"http:\/\/local.tutorials\/","name":"Brightwhiz.com Tutorials and Courses","description":"","publisher":{"@id":"http:\/\/local.tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/local.tutorials\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/local.tutorials\/#organization","name":"Brightwhiz.com","url":"http:\/\/local.tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/staging.brightwhiz.com\/wp-content\/uploads\/2022\/03\/brightwhiz-com-logo-orange.png","contentUrl":"https:\/\/staging.brightwhiz.com\/wp-content\/uploads\/2022\/03\/brightwhiz-com-logo-orange.png","width":706,"height":135,"caption":"Brightwhiz.com"},"image":{"@id":"http:\/\/local.tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/brightwhiz","https:\/\/twitter.com\/brightwhizmag","https:\/\/www.instagram.com\/glamorglaze\/","https:\/\/www.pinterest.com\/sobbayi\/","https:\/\/www.youtube.com\/c\/Sobbayi"]}]}},"_links":{"self":[{"href":"http:\/\/local.tutorials\/wp-json\/wp\/v2\/topic\/60"}],"collection":[{"href":"http:\/\/local.tutorials\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"http:\/\/local.tutorials\/wp-json\/wp\/v2\/types\/topic"}],"replies":[{"embeddable":true,"href":"http:\/\/local.tutorials\/wp-json\/wp\/v2\/comments?post=60"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/local.tutorials\/wp-json\/wp\/v2\/media\/43"}],"wp:attachment":[{"href":"http:\/\/local.tutorials\/wp-json\/wp\/v2\/media?parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/local.tutorials\/wp-json\/wp\/v2\/categories?post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/local.tutorials\/wp-json\/wp\/v2\/tags?post=60"},{"taxonomy":"subject","embeddable":true,"href":"http:\/\/local.tutorials\/wp-json\/wp\/v2\/subject?post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}