How to Display Table in HTML Example Explained

Tables are an essential component of HTML, allowing us to present data in an organized and readable format. In this article, we will guide you through displaying tables in HTML and provide practical examples. If you've ever wondered how to create and structure tables in your web pages, this will serve as an comprehensive guide.

HTML Table
HTML Table

Tables in HTML are primarily used for tabular data that needs to be presented in a grid format. They can be used to display data in a structured manner, making it easier for users to understand and navigate. So, let's dive into the details of how to create and display tables in HTML.

HTML Tables Tags Tutorial with Example โ€” TutorialBrain
HTML Tables Tags Tutorial with Example โ€” TutorialBrain

Creating a Basic HTML Table

Every table in HTML begins with the <table> tag and ends with the </table> tag. Within these tags, you add the rows of your table using the <tr> tag, with each cell of your table defined by the <td> tag. The header of your table is defined by the <th> tag.

๐Ÿงพ How to Create Tables in HTML
๐Ÿงพ How to Create Tables in HTML

Here's a simple example of a basic HTML table:

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

Table Rows and Cells

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

The <tr> and <td> tags are used to create the rows and cells of the table, respectively. In the above example, the first <tr> creates a row within the table and the <th> tags within it define the table headers. The second <tr> creates another row and the <td> tags within it define the data cells.

The number of <th> and <td> tags within each <tr> should match. The first row typically contains headers, and subsequent rows contain the data.

Spanning Cells

how to create html table | HTML TABLE TAG
how to create html table | HTML TABLE TAG

Sometimes you may want a header or data cell to span multiple columns or rows. This can be achieved using the colspan or rowspan attributes within the <th> or <td> tags. For example:

<table> <tr> <th>Header 1</th> <th colspan="2">Header 2</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </table>

Styling Tables in HTML

HTML tables can be styled using CSS. You can apply styles to the entire table, specific rows or cells, or even specific cells within a row. By using CSS, we can control the appearance of the table, including colors, font sizes, borders, and more. In the following example, we've added some basic CSS to our table:

Top 9 HTML Table Builders to use Free
Top 9 HTML Table Builders to use Free

<style> table { border-collapse: collapse; width: 50%; } th, td { border: 1px solid black; padding: 8px; text-align: left; } </style> <table> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </table>

This is a simple introduction to creating and styling tables in HTML. HTML tables provide a powerful way to present complex data in a user-friendly manner. They can be used in a variety of situations, from displaying information to creating interactive forms. As you become more familiar with HTML and CSS, you can create more complex and visually appealing tables for your websites.

Remember, the key to effective use of tables is organizing your data in a way that makes sense and using appropriate headers to guide your users. Happy coding, and we hope this guide has given you a strong foundation for working with 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
Display CSV File In HTML Table In Javascript
Display CSV File In HTML Table In Javascript
an image of a table with many lines
an image of a table with many lines
Welcome to SiteRaw
Welcome to SiteRaw
๐Ÿ“Š Combine Table Cells in HTML
๐Ÿ“Š Combine Table Cells in HTML
HOW TO MERGE TABLE CELLS IN HTML
HOW TO MERGE TABLE CELLS IN HTML
the table borders for different types of text
the table borders for different types of text
Tables in HTML
Tables in HTML
CSS Table Layout
CSS Table Layout
The table-layout property in CSS
The table-layout property in CSS
Simple Searchable Table In HTML Javascript
Simple Searchable Table In HTML Javascript
HTML Table Image and Text Align | How To Make Responsive Table Design Using CSS | With Source Code
HTML Table Image and Text Align | How To Make Responsive Table Design Using CSS | With Source Code
an info sheet describing the different types of web pages and how they are used to create them
an info sheet describing the different types of web pages and how they are used to create them
Sortable Table with HTML & Javascript
Sortable Table with HTML & Javascript
Why You Shouldn't Get Caught Using Tables for Web Page Layouts
Why You Shouldn't Get Caught Using Tables for Web Page Layouts
How to use Data tables in HTML code ? - EcomSpark
How to use Data tables in HTML code ? - EcomSpark
Export HTML Table to Excel JavaScript Example
Export HTML Table to Excel JavaScript Example
Fixed Header Table - Free HTML/CSS Table Template 2026 - Colorlib
Fixed Header Table - Free HTML/CSS Table Template 2026 - Colorlib
Table In CSS | How To Create Table In CSS | In Urdu/Hindi | #16 | CSS Tutorials
Table In CSS | How To Create Table In CSS | In Urdu/Hindi | #16 | CSS Tutorials
Table Headers in HTML
Table Headers in HTML

Related Articles

Use Of Html In Web Development C# Examples Pdf Greek Word For Greek H In Ancient Greek Alphabet What Is The Div Tag In Html Used For Html Tutorial For Beginners Codecademy What Is Html Used For Coding Dart List Methods Div Tag Meaning Html Dart Methods