Best Html Table Code Example For Beginners With Live Demo

An HTML table is a organizational layout of data in rows and columns, often used to present large amounts of data in a structured and easy-to-understand format. Today, we're going to delve into the world of HTML tables, exploring their basic structure, attributes, and some practical examples.

HTML Table
HTML Table

HTML tables can be incredibly useful when it comes to arranging and presenting data on a webpage. They can be used for displaying a matrix of numbers, a lineup of players and scoring stats, or even a sitemap for a website. Before we dive into the examples, let's quickly review the basic structure of an HTML table.

HTML Basic Tables
HTML Basic Tables

HTML Table Structure

Every HTML table is surrounded by the

tag. Each row of data is contained within the (table row) tag, and each cell (or column) within the
(table data) tag. A table header, often used to specify column headings, is placed within the (table header) tag. Here's a simple representation:

๐Ÿš€ Day 5 of Learning HTML โ€” Tables, Forms & Semantic Tags
๐Ÿš€ Day 5 of Learning HTML โ€” Tables, Forms & Semantic Tags

<table> <tr> <th>Column 1</th> <th>Column 2</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </table>

Attributes of
๐Ÿท๏ธ HTML Tags Cheat Sheet | Essential Tags Every Beginner Should Know
๐Ÿท๏ธ HTML Tags Cheat Sheet | Essential Tags Every Beginner Should Know

HTML tables support various attributes, including width and border. The width attribute specifies the width of the table, while border defines the thickness of the table's border. Here's an example:

<table style="width:100%; border:1px solid black"> <tr> <th>Column 1</th> <th>Column 2</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </table>

Spanning Columns and Rows

the table borders for different types of text
the table borders for different types of text

You can use the colspan attribute to span a cell across other columns, or the rowspan attribute to span a cell across other rows. Here's an example:

<table> <tr> <th>Column 1</th> <th>Column 2</th> </tr> <tr> <td>Data 1</td> <td colspan="2">Spanning cell</td> </tr> </table>

Creating Responsive Tables

HTML input types
HTML input types

In responsive design, tables can be a bit tricky. The cap-style: none CSS property can prevent cells from collapsing when the table becomes too narrow. Here's an example:

<style> table, th, td { border: 1px solid black; } table { table-layout: fixed; } td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } </style> <table> <tr> <th>Very long column heading</th> <th>Second Column</th> </tr> <tr> <td>Very long cell data</td> <td>Second Cell</td> </tr> </table>

Responsive HTML Table With Rounded Corners
Responsive HTML Table With Rounded Corners
tables in html table with text and images on the page, which is displayed below
tables in html table with text and images on the page, which is displayed below
a black and orange poster with text that says,'html chat sheet'on it
a black and orange poster with text that says,'html chat sheet'on it
an image of a text description with the words html tables in red and blue on it
an image of a text description with the words html tables in red and blue on it
HTML Tables Tags Tutorial with Example โ€” TutorialBrain
HTML Tables Tags Tutorial with Example โ€” TutorialBrain
CSS Table Layout
CSS Table Layout
an image of a computer screen with the text, table headings and tables headings
an image of a computer screen with the text, table headings and tables headings
๐Ÿ’ป HTML Intermediate Notes & Quick Reference
๐Ÿ’ป HTML Intermediate Notes & Quick Reference
the table borders for different types of text
the table borders for different types of text
CSV To HTML Table In Javascript
CSV To HTML Table In Javascript
HTML Cheat Sheet ๐Ÿ“„โœจ Quick Guide for Beginners
HTML Cheat Sheet ๐Ÿ“„โœจ Quick Guide for Beginners
a computer screen with the text html and an image of a web page on it
a computer screen with the text html and an image of a web page on it
Quick HTML Tags Cheat Sheet
Quick HTML Tags Cheat Sheet
Welcome to SiteRaw
Welcome to SiteRaw
The table-layout property in CSS
The table-layout property in CSS
an image of a computer screen with text
an image of a computer screen with text
๐Ÿงพ How to Create Tables in HTML
๐Ÿงพ How to Create Tables in HTML
HTML Cheat Sheet ๐Ÿ“š | Essential HTML Tags Every Web Developer Should Know
HTML Cheat Sheet ๐Ÿ“š | Essential HTML Tags Every Web Developer Should Know
29 Free CSS3 & HTML Table Templates 2026 - Colorlib
29 Free CSS3 & HTML Table Templates 2026 - Colorlib
Display CSV As HTML Table In PHP
Display CSV As HTML Table In PHP

Understanding HTML tables is a crucial step in web development. It enables you to present complex data in a simple, organized manner. Whether you're building a portfolio or an e-commerce website, tables can be an invaluable tool. So, start practicing, and happy coding!