- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML Tables
The HTML Table is used to create a table using <table> tag. In table, each row is specified using <tr> tag and a table header is defined using <th> tag. A table data is defined using <td> tag.
Syntax
Following is the syntax −
<table> <tr> <th>Table Header</th> <th>Table Header</th> </tr> <tr> <td>Table data</td> <td>Table data</td> </tr> <tr> <td>Table data</td> <td>Table data</td> </tr> </table>
HTML table attributes
Attribute | Explanation |
---|---|
colspan | It is used to span a table cell across column of a table. |
rowspan | It is used to span a table cell across rows of a table. |
HTML caption element
We can also set caption for a table using HTML caption element.
Syntax
Following is the syntax −
<caption>text</caption>
Example
Let us see an example of HTML Tables:
<!DOCTYPE html> <html> <style> body { color: #000; height: 100vh; background-color: #8BC6EC; background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%); text-align: center; } table { margin: 2rem auto; width: 400px; } caption { color: #fff; font-size: 1.5rem; } </style> <body> <h1>HTML Tables</h1> <table border="2"> <caption>Student Data</caption> <tr> <th>Name</th> <th>Roll No.</th> </tr> <tr> <td>John</td> <td>031717</td> </tr> <tr> <td>Elon</td> <td>051717</td> </tr> </table> </body> </html>
Output
- Related Articles
- How to create tables in HTML?
- Create A Form Using HTML Tables?
- How to Parse HTML pages to fetch HTML tables with Python?
- HTML Tables with Fixed Header on Scroll in CSS
- How to use tables to structurize forms in HTML?
- How to save HTML Tables data to CSV in Python
- Only show tables with certain patterns in MySQL “show tables”?
- How can we see MySQL temporary tables in the list of tables?
- MySQL join two tables?
- Styling Tables with CSS
- Distributed Hash Tables (DHTs)
- HTML5 validity of nested tables
- MySQL count(*) from multiple tables?
- Hash Functions and Hash Tables
- Styling Tables Working with CSS

Advertisements