Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
HTML Table
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. HTML Tutorials
  3. HTML Table

HTML Tutorial

Basic HTML Fundamentals

  • HTML Table Content
  • Introduction To HTML
  • What Is HTML
  • HTML Tags
  • HTML Formatting
  • HTML Heading
  • HTML Paragraph
  • HTML Anchor
  • HTML Image
  • HTML Table
  • HTML Lists
  • HTML Ordered List
  • HTML Unordered List
  • HTML Description List
  • HTML Form

HTML Tags

  • Marquee HTML
  • HTML Textarea
  • HTML Quotes
  • HTML Style
  • HTML Title Or HTML Doctype
  • HTML Div Tag
  • HTML Pre Tag
  • HTML Code Tag
  • HTML Label Tag
  • HTML Input Tag
  • HTML Button Tag
  • HTML Hr Tag
  • HTML Br Tag
  • HTML Script Tag
  • HTML NoScript Tag
  • HTML Bold Tag

HTML Table

HTML Table

HTML table tag is used to display data in tabular form (row * column). There can be many columns in a row.

HTML tables are used to manage the layout of the page e.g. header section, navigation bar, body content, footer section etc. But it is recommended to use div tag over table to manage the layout of the page .

HTML Table Tags

Tag Description
<table> It defines a table.
<tr> It defines a row in a table.
<th> It defines a header cell in a table.
<td> It defines a cell in a table.
<caption> It defines the table caption.
<colgroup> It specifies a group of one or more columns in a table for formatting.
<col> It is used with <colgroup> element to specify column properties for each column.
<tbody> It is used to group the body content in a table.
<thead> It is used to group the header content in a table.
<tfooter> It is used to group the footer content in a table.

HTML Table Example


Example of HTML table tag. It output is shown above.

<table> 
<tr><th>Name</th><th>Marks</th></tr> 
<tr><td>Sania</td><td>60</td></tr> 
<tr><td>Shiya</td><td>80</td></tr> 
<tr><td>Shivani</td><td>82</td></tr> 
<tr><td>Suhail</td><td>72</td></tr> 
</table> 

Output:

Name Marks
Sonia 60
Shiya 80
Shivani 82
Suhail 72

HTML Table with BorderIn the above html table, there are 5 rows and 2 columns = 5 * 2 = 10 values.

There are two ways to specify border for HTML tables.

  • By border attribute of table in HTML
  • By border property in CSS

HTML Border attribute

You can use border attribute of table tag in HTML to specify border. But it is not recommended now.

<table border="1"> 
<tr><th>Name</th><th>Marks</th></tr> 
<tr><td>Sania</td><td>60</td></tr> 
<tr><td>Shiya</td><td>80</td></tr> 
<tr><td>Shivani</td><td>82</td></tr> 
<tr><td>Suhail</td><td>72</td></tr> 
</table> 

Output:

Name Marks
Sonia 60
Shiya 80
Shivani 82
Suhail 72

CSS Border property

It is now recommended to use border property of CSS to specify border in table.

<style> 
table, th, td { 
   border: 1px solid black; 
} 
</style> 


You can collapse all the borders in one border by border-collapse property.

<style> 
table, th, td { 
   border: 2px solid black; 
   border-collapse: collapse; 
} 
</style> 


HTML Table with cell padding

You can specify padding for table header and table data by two ways:

  • By cellpadding attribute of table in HTML
  • By padding property in CSS

The cellpadding attribute of HTML table tag is obselete now. It is recommended to use CSS. So let's see the code of CSS.

<style> 
table, th, td { 
   border: 1px solid pink; 
   border-collapse: collapse; 
} 
th, td { 
   padding: 10px; 
} 
</style> 

Output:

Name Marks
Sonia 60
Shiya 80
Shivani 82
Suhail 72

HTML Table with colspan

If you want to make a cell span more than one column, you can use the colspan attribute.

Example that span two columns.

CSS code:

<style> 
table, th, td { 
   border: 1px solid black; 
   border-collapse: collapse; 
} 
th, td { 
   padding: 5px; 
} 
</style> 

HTML code:

<table style="width:100%"> 
  <tr> 
   <th>Name</th> 
   <th colspan="2">Mobile No.</th> 
  </tr> 
  <tr> 
   <td>Shiya</td> 
   <td>9874563210</td> 
   <td>9874563210</td> 
  </tr> 
</table> 

Output:

Name Mobile No.
Shiya 9874563210 9874563210

HTML Table with rowspan

If you want to make a cell span more than one row, you can use the rowspan attribute.

Example that span two rows.

CSS code:

<style> 
table, th, td { 
   border: 1px solid black; 
   border-collapse: collapse; 
} 
th, td { 
   padding: 10px; 
} 
</style> 

HTML code:

<table>  
<tr><th>Name</th><td>Shivani</td></tr>  
<tr><th rowspan="2">Mobile No.</th><td>9874563210</td></tr>  
<tr><td>9874563210</td></tr>  
</table>  

Output:

Name Mobile No. 9874563210
Shiya 9874563210

HTML table with caption

HTML caption is diplayed above the table. It must be used after table tag only.

<table>  
<caption>Student Records</caption>
<tr><th>Name</th><th>Marks</th></tr>  
<tr><td>Sania</td><td>60</td></tr>  
<tr><td>Shiya</td><td>80</td></tr>  
<tr><td>Shivani</td><td>82</td></tr>  
<tr><td>Suhail</td><td>72</td></tr>  
</table>  

Styling HTML table even and odd cells

CSS code:

<style> 
table, th, td { 
   border: 1px solid black; 
   border-collapse: collapse; 
} 
th, td { 
   padding: 10px; 
} 
table#alter tr:nth-child(even) { 
   background-color: #eee; 
} 
table#alter tr:nth-child(odd) { 
   background-color: #fff; 
} 
table#alter th { 
   color: white; 
   background-color: gray; 
} 
</style> 

Output:

Name Marks
Sonia 60
Shiya 80
Shivani 82
Suhail 72
Series: HTML Tutorials Hub
All Topics
Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group
Related Topics:
HTML table tag HTML table How to Create Tables in HTML html table style html table attributes html table border html table colspan table html generator

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.