
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
How to create tables in HTML?
HTML tables allow us to arrange data into rows and columns on the web page.
We use the <table> tag, to create table in HTML. A table consist of rows and columns. Table heading, row and column and table data can be set using one or more <th>, <tr>, and <td> elements.
A table row is defined by the <tr> tag. To set table header,we use <th> tag. To insert data in table cell, use the <td> tag.
A table in HTML consists of table cells inside rows and columns of the table.
Table heading is defined by the <th>...</th>. Data inside the <th> are the headings of the column of a table.
Each table cell is defined by a <td>...</td> tag. Data inside the <td> tag are the content of the table rows and columns.
Each table row starts with a <tr> ....</tr> tag.
We use style sheet to create border for the table.
Example
Following is an example program to create table in HTML.
<!DOCTYPE html> <html> <style> table, th, td { border:1px solid green; } </style> <body> <h2>Count</h2> <table> <tr> <th>Monday</th> <th>Tuesday</th> <th>Wednesday</th> <th>Thursday</th> <th>Friday</th> <th>Saturday</th> <th>Sunday</th> </tr> <tr> <td>12</td> <td>28</td> <td>28</td> <td>28</td> <td>28</td> <td>28</td> <td>28</td> </tr> <tr> <td>35</td> <td>21</td> <td>34</td> <td>00</td> <td>8</td> <td>75</td> <td>24</td> </tr> </body> </html>
Example
Following is another example program to create table in HTML.
<!DOCTYPE html> <html> <style> table, th, td { border:1px solid black; } </style> <body> <h2>Tables in HTML</h2> <table> <tr> <th>Name</th> <th>RollNo</th> </tr> <tr> <td>Jason</td> <td>28</td> </tr> <tr> <td>Yadav</td> <td>22</td> </tr> <tr> <td>Abdul</td> <td>25</td></tr> </tr> <tr> <td>Abdul</td> <td>25</td></tr> </tr> </table> </body> </html>
Now we try to extend our table to our browser tab size using style attribute.
Example
Following is the example program to extend our table to our browser tab size using style attribute.
<!DOCTYPE html> <html> <style> table, th, td { border:1px solid black; } </style> <body> <h2>Tables in HTML</h2> <table style="width: 100%"> <tr> <th>Name</th> <th>RollNo</th> </tr> <tr> <td>Jason</td> <td>28</td> </tr> <tr> <td>Yadav</td> <td>22</td> </tr> <tr> <td>Abdul</td> <td>25</td></tr> </tr> <tr> <td>Abdul</td> <td>25</td></tr> </tr> </table> </body> </html>
- Related Articles
- How to create nest tables within tables in HTML?
- Create A Form Using HTML Tables?
- How to use tables to structurize forms in HTML?
- How to Parse HTML pages to fetch HTML tables with Python?
- HTML Tables
- How to save HTML Tables data to CSV in Python
- How to create multi-column layout in HTML5 using tables?
- How to create and populate Java array of Hash tables?
- How to create headings in HTML page?
- How to create Paragraphs in HTML Page?
- How to create table header in HTML?
- How to create table border in HTML?
- How to create hidden comments in HTML?
- How to create conditional comments in HTML?
- How to create table footer in HTML?
