HTML Tables: Here’s How To Make Your First Table

Short Explanation About HTML Table

  • A table is defined using the <table> element, and contains a number of table cells ( <td>, for “table data” ) which are organized into table rows ( <tr>). The markup (HTML code) for a table is always based on rows, never columns.
  • Table cells which act as column headers or row headers should use the <th> (table header) element.
  • Table cells can be merged using the colspan and rowspan attributes.
  • Tables can be broken into sections using the following elements:
    • <thead> — Table header
    • <tbody> — Table body
    • <tfoot> — Table footer
  • A caption can be added to a table using the <caption> element.
  • You can use <col> and <colgroup> to define table columns for styling. However, there are a number of limitations with this practice.
  1. Table Code Sample: Simple Table

    Here is an example of a simple table. Copy this code into your editor and run it in your browser. If you haven’t got one, check my earlier post about Top 5 PHP Editor (IDE) for Web Developers.

    <table>
    	<tr>
    		<th>Name</th>
    		<th>Favorite Color</th>
    	</tr>
    	<tr>
    		<td>Bob</td>
    		<td>Yellow</td>
    	</tr>
    	<tr>
    		<td>Michelle</td>
    		<td>Purple</td>
    	</tr>
    </table>

  2. Table Code Sample: Complex Table

    <table>
      <caption>A complex table</caption>
      <thead>
        <tr>
          <th colspan="3">Invoice #123456789</th>
          <th>14 January 2025
        
        </tr>
        <tr>
          <td colspan="2"><strong>Pay to:</strong><br> Acme Billing Co.<br> 123
            Main St.<br> Cityville, NA 12345</td>
          <td colspan="2"><strong>Customer:</strong><br> John Smith<br> 321
            Willow Way<br> Southeast Northwestershire, MA 54321</td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>Name / Description</th>
          <th>Qty.</th>
          <th>@</th>
          <th>Cost</th>
        </tr>
        <tr>
          <td>Paperclips</td>
          <td>1000</td>
          <td>0.01</td>
          <td>10.00</td>
        </tr>
        <tr>
          <td>Staples (box)</td>
          <td>100</td>
          <td>1.00</td>
          <td>100.00</td>
        </tr>
      </tbody>
      <tfoot>
        <tr>
          <th colspan="3">Subtotal</th>
          <td>110.00</td>
        </tr>
        <tr>
          <th colspan="2">Tax</th>
          <td>8%</td>
          <td>8.80</td>
        </tr>
        <tr>
          <th colspan="3">Grand Total</th>
          <td>$ 118.80</td>
        </tr>
      </tfoot>
    </table>

What You Can Do Next

There is a CSS template to make a good styled HTML table very easily called Bootstrap. Simply load the bootstrap CSS in your HTML using <link> tag, and then use classes provided by bootstrap to style your table. For example, you can customize color, add striped rows to your table using one single parent class, nicely styled borderless table, hoverable rows, and many more. Try it yourself by reading Bootstrap documentation about tables here.

Keep in mind that example tables in this post is just static tables, meaning that the content inside the tables are hardcoded. When making a table in a site, commonly we must make the data dinamic. For example, the data is taken from database and the content keeps changing. I will explain this in the next post about how to make a dynamic table using PHP and HTML.

6,757 comments

  1. Bookmarks

    Shape’s style software has a big knowing curve.

    My homepage :: Bookmarks

  2. Whitney

    Acquiring blinds online can be fun as well as amazing.

    Feel free to surf to my homepage: kieran lewis rugby league
    (Whitney)

  3. Bookmarks

    Upright Blinds are excellent for covering huge windows.

    my web-site … Bookmarks

  4. Bookmarks

    Purchasing blinds online can be enjoyable and also interesting.

    my web site – Bookmarks

  5. Bookmarks

    Shape’s style software program has a significant discovering curve.

    Also visit my web site: Bookmarks

  6. mobile chandelier west elm

    Have you ever thought about adding a little bit more than just your articles?
    I mean, what you say is valuable and all. But think of if you added some great images or video clips to give
    your posts more, “pop”! Your content is excellent but with images
    and video clips, this website could undeniably be one of the very best
    in its field. Amazing blog!

  7. Bookmarks

    Acquiring blinds online can be enjoyable and exciting.

    Here is my blog; Bookmarks

  8. bai ba ba by parachilna

    I visited various web sites but the audio quality for audio songs existing
    at this web site is really fabulous.

  9. treasure hunt cleopatra hack anroid

    Heya i am for the first time here. I came across this
    board and I find It truly useful & it helped me out much.
    I hope to give something back and aid others like you aided
    me.

  10. mod apk gratis

    Hello, after reading this amazing article i am too cheerful to share
    my familiarity here with colleagues.

  11. 더킹 카지노

    Very good info. Lucky me I came across your site by chance (stumbleupon).
    I’ve saved as a favorite for later!

Leave a Reply

Your email address will not be published. Required fields are marked *