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.

8,764 comments

  1. Titanium inife

    I have been browsing online greater than three hours lately, but I never found any attention-grabbing article like yours.
    It is beautiful worth enough for me. In my opinion, if all web owners and bloggers made just right content as you probably did, the
    web might be much more useful than ever before.

  2. best serge mouille Replica

    Wow, superb weblog format! How lengthy have you been running a blog
    for? you made blogging glance easy. The whole glance of your site is magnificent,
    let alone the content material!

  3. tai mau binh

    I am truly grateful to the holder of this web page who has shared
    this enormous piece of writing at at this place.

  4. 카지노사이트

    I am extremely impressed with your writing skills as well
    as with the layout on your weblog. Is this a paid theme or did you modify it yourself?
    Anyway keep up the nice quality writing, it’s rare to see a nice blog like this one nowadays.

  5. Titanium Glasses

    It’s impressive that you are getting ideas from this article as
    well as from our discussion made here.

  6. オンラインカジノ

    At this time it sounds like Expression Engine
    is the top blogging platform out there right now. (from what I’ve read) Is that what you’re using on your blog?

  7. titanium rings

    I have been exploring for a little for any high quality articles or blog posts on this kind of house .
    Exploring in Yahoo I finally stumbled upon this website.
    Reading this information So i am glad to convey that I’ve an incredibly
    excellent uncanny feeling I discovered just what I needed.
    I so much surely will make certain to do not disregard this web site and provides it a glance on a continuing basis.

  8. minh chính keno

    Hiya! Quick question that’s entirely off topic.
    Do you know how to make your site mobile friendly? My blog
    looks weird when browsing from my iphone 4. I’m trying to
    find a theme or plugin that might be able to resolve this issue.

    If you have any suggestions, please share. Thanks!

  9. kèo nhà cái

    Good day! This is kind of off topic but I need some advice from an established blog.
    Is it very hard to set up your own blog? I’m not very techincal but
    I can figure things out pretty quick. I’m thinking about setting
    up my own but I’m not sure where to begin. Do you have any tips or suggestions?
    Appreciate it

  10. 더나인카지노

    What’s up colleagues, good paragraph and fastidious
    urging commented here, I am really enjoying by
    these.

  11. roulette online

    Just want to say your article is as astounding. The clarity on your publish is simply nice and i
    can suppose you’re knowledgeable in this subject. Fine with your permission allow me
    to seize your feed to keep up to date with imminent post.
    Thanks a million and please keep up the rewarding work.

  12. ジパング カジノ 登録 ボーナス

    Hello, There’s no doubt that your web site could be having web browser compatibility issues.

    Whenever I take a look at your blog in Safari, it
    looks fine however, when opening in IE, it has some overlapping issues.
    I just wanted to give you a quick heads up! Besides that,
    wonderful blog!

  13. trực tuyến

    What’s up everybody, here every one is sharing these kinds of knowledge, therefore it’s good to
    read this webpage, and I used to go to see this web site daily.

  14. bắn cá club

    If you would like to get a great deal from this paragraph
    then you have to apply these strategies to your won blog.

  15. 퍼스트카지노

    Hi! This is kind of off topic but I need some help from an established blog.

    Is it difficult to set up your own blog? I’m not very techincal but I can figure things out pretty fast.
    I’m thinking about creating my own but I’m not sure where to start.
    Do you have any points or suggestions? Thanks

  16. 더킹 카지노

    After going over a number of the blog posts on your web site,
    I honestly like your way of blogging. I saved as a favorite
    it to my bookmark website list and will be checking back in the near future.
    Please check out my web site too and let me know what you think.

  17. 샌즈카지노

    Simply want to say your article is as astounding.

    The clearness in your post is simply spectacular and i can assume you’re an expert on this subject.
    Fine with your permission allow me to grab your RSS feed to keep updated with forthcoming post.
    Thanks a million and please keep up the gratifying
    work.

  18. baccarat

    This is my first time pay a visit at here and i am really pleassant to read all at one place.

  19. 우리카지노

    Fantastic goods from you, man. I’ve understand your stuff previous to and you’re just extremely wonderful.
    I really like what you have acquired here,
    certainly like what you’re stating and the way in which you say it.
    You make it enjoyable and you still take care of to keep it smart.
    I cant wait to read far more from you. This is actually a great website.

  20. blackjack online

    I know this if off topic but I’m looking into starting my own blog
    and was wondering what all is needed to get set up?
    I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very web smart so I’m not 100% certain. Any
    suggestions or advice would be greatly appreciated.
    Kudos

  21. 블랙잭

    I savour, cause I discovered exactly what I was looking for.
    You have ended my 4 day long hunt! God Bless you man. Have a great day.
    Bye

  22. cược online

    If you are going for best contents like I do, only pay a visit this
    website daily for the reason that it gives quality contents,
    thanks

  23. 솔레어카지노

    Pretty! This was an extremely wonderful post. Thanks for supplying these details.

  24. ワイルドジャングルカジノ

    Wonderful work! This is the type of info that are supposed to be shared around the internet.
    Shame on Google for now not positioning this publish upper!
    Come on over and discuss with my web site . Thank you =)

  25. trực tiếp m88

    Great beat ! I wish to apprentice while you amend your website,
    how could i subscribe for a blog web site? The account helped me a acceptable deal.
    I had been a little bit acquainted of this your broadcast provided bright
    clear idea

Leave a Reply

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