Sample HTML Code for Table: Easy Examples and SEO Tips

When it comes to organizing and presenting data effectively on a webpage, few tools are as versatile and straightforward as the HTML table. It enables you to structure complex data in an easy-to-understand and user-friendly format. Let's explore some basic HTML code for tables, highlighting how to create, format, and manipulate them.

Responsive HTML Table With Rounded Corners
Responsive HTML Table With Rounded Corners

Before delving into the specifics, understand that an HTML table is created using the `

`, ``, `
`, and `` tags. The `` tag defines the table, the `` tag defines the rows, and the `
` tag defines the table cells (table data) within each row. The `` tag, on the other hand, is used to define table headers.

HTML Table
HTML Table

Creating a Basic HTML Table

To create a simple table, follow this basic structure:

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

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

Understanding Table Headers

HTML Basic Tables
HTML Basic Tables

The `

` tag allows you to specify the headers of your table. Headers are typically bold and centered by default, aiding readability. Here's an example:

<table> <tr> <th>Countries</th> <th>Capitals</th> </tr> ... </table>

Spanning Columns and Rows

Responsive Table V1 - Free HTML/CSS Table Template 2026 - Colorlib
Responsive Table V1 - Free HTML/CSS Table Template 2026 - Colorlib

HTML tables also allow you to span columns and rows for merged cells using the `colspan` and `rowspan` attributes. This can be useful for presenting complex data cleanly. Here's an example:

<table> <tr> <th>Day</th> <th>Event</th> <th>Location</th> </tr> <tr> <td>Monday</td> <td>Birthday</td> <td>Home</td> </tr> <tr> <td rowspan="2">Tuesday</td> <td>Meeting</td> <td>Office</td> </tr> <tr> <td>Lunch</td> </tr> </table>

Formatting HTML Tables

an image of a table with many lines
an image of a table with many lines

HTML offers a range of attributes for styling tables, including `width`, `height`, `cellpadding`, `cellspacing`, and `border`. For example, you could specify the width of a table as 500 pixels like so: `

`. Be wary, though, excessive use of these attributes can lead to an unwieldy and unreadable design.

Aligning Table Content

Top 9 HTML Table Builders to use Free
Top 9 HTML Table Builders to use Free
๐Ÿงพ How to Create Tables in HTML
๐Ÿงพ How to Create Tables in HTML
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
an image of a table with numbers and symbols on the top right hand corner that says tables
an image of a table with numbers and symbols on the top right hand corner that says tables
EFI Autos: Your Ultimate Destination for Car Repairs & ECU Knowledge
EFI Autos: Your Ultimate Destination for Car Repairs & ECU Knowledge
40 Best CSS Table Templates For Creating Appealing Tables 2026
40 Best CSS Table Templates For Creating Appealing Tables 2026
Write the HTML code for the following table:
Write the HTML code for the following table:
how to create html table | HTML TABLE TAG
how to create html table | HTML TABLE TAG
the table borders for different types of text
the table borders for different types of text
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
๐Ÿ“Š Combine Table Cells in HTML
๐Ÿ“Š Combine Table Cells in HTML
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
HTML Table Styler ๐Ÿ“… CSS Generator
HTML Table Styler ๐Ÿ“… CSS Generator
CSS Table Layout
CSS Table Layout
a table that has some type of text in red and black on the bottom right hand corner
a table that has some type of text in red and black on the bottom right hand corner
Student Registration Form in HTML with CSS | Completely Free
Student Registration Form in HTML with CSS | Completely Free
30 Best Free HTML/CSS Table Templates Templates 2026 - Colorlib
30 Best Free HTML/CSS Table Templates Templates 2026 - Colorlib
A Detailed Guide to HTML Tables | Simplilearn
A Detailed Guide to HTML Tables | Simplilearn
Welcome to SiteRaw
Welcome to SiteRaw
The table-layout property in CSS
The table-layout property in CSS

The `align` attribute allows you to align text within table cells. You can set it to `left`, `right`, or `center`. Here's an example:

<table> <tr> <td>Align left</td> <td align="right">Align right</td> <td align="center">Align center</td> </tr> </table>

Using the `

` and `` Elements for Broad Column Formatting

These elements allow you to specify styles for entire columns, rather than cell by cell. For instance, you could set a particular column's width and background color. Here's an example:

<colgroup> <col width="100" style="background-color:red"> <col> </colgroup> <table>...</table>

The use of HTML tables goes beyond simple data presentation, seeping into areas like layouts, navigation menus, and more. Mastering their use allows you to improve the functionality and usability of your webpages. Don't shy away from experimenting with various examples and exploring the myriad possibilities that HTML tables offer. Happy coding!