HTML Tables
HTML Tables
Last Updated Jul 21, 2015, 12:00:06 PM
Tables in HTML
can be used for structuring and formatting tabular data, similar to the display capabilities of spreadsheet software. Tables are useful for organizing and relating quantitative and qualitative data sets
Ideally, tables should only ever be used for tabular data. Once you learn about tables, it might be tempting to use them for page layout, but you shouldn't ever do this unless you have to. Page layout should be a combination of well-structured HTML combined with CSS.
Example HTML Table
Try It Now
HTML Table with Border(Bad Practice)
You can specify the border of a table using the border property, however using specifying the border property like below is not a good practice and it is recommended not to use like below by w3c
Try It Now
border
<table>
element should be styled using CSS. To give an effect similar to the border
attribute, use the CSS properties border, border-color
, border-width and border-style should be used..HTML Table with Border(Good Practice)
CSSTry It Now
HTML Table with Cell Padding(Bad Practice)
This attribute defines the space between the content of a cell and the border, displayed or not, of it. If it is a pixel length, this pixel-sized space will be applied on all four sides; if it is a percentage length, the content will be centered, and the total vertical space (top and bottom) will represent this percentage. The same is true for the total horizontal space (left and right).
ExampleTry It Now
If you do not specify a padding, the table cells will be displayed without padding.
Cellpadding
table
element should be styled using CSS. To give an effect similar to the border attribute, use the CSS property border-collapse
with the value collapse on the <table>
element itself, and the property padding
on the <td>
.HTML Tables Cell Padding(Good Practice)
It is the developers best practice to keep the styles and paddings of html table in between the css tyles tags. Recommanded practice by the w3c
HTML
One | Two | Three |
---|---|---|
HTML | CSS | JavaScript |
Markup Language | Style sheet | Scripting Language |
Try It Now
HTML Table Headings (Bad Practice)
Table headings are defined with the <th>
tag.
By default, all major browsers display table headings as bold and centered:
Company | Country | Founder |
---|---|---|
Microsoft | USA | Bill Gates |
Apple | USA | Steve Jobs |
USA | Mark Zuckerburg |
Try It Now
HTML Table Headings (Good Practice)
CSSHTML
Company | Country | Founder |
---|---|---|
Microsoft | USA | Bill Gates |
Apple | USA | Steve Jobs |
USA | Mark Zuckerburg |
Try It Now
HTML Table with Rows
HTML table can have any no of rows to display the data in rows and columns
Employee | Number | Salary |
---|---|---|
Mike | 5165 | $2000 |
Tim | 556 | $2300 |
Bob | 557 | $2400 |
Adelly | 568 | $4500 |
Christy | 596 | $6300 |
Mary | 656 | $2600 |
Try It Now
HTML Tables with Colors
As we alraedy know, that we can style the html elements with different colors, we can also style the html tables with different colors
Browser Support
Property | |||||||
---|---|---|---|---|---|---|---|
Tables | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Practice with Our Interactive Live Code Editor and Take your HTML Skills to the next level
Exercise 1 Exercise 2 Exercise 3 Exercise 4 Exercise 5
Sources and Credits
The source of the content has been referred and updated with Mozilla Foundation and w3C
Last Updated Jul 21, 2015, 12:00:06 PM
Learn HTML in One Month - from OneMonth
Build Your First Website with HTML and CSS -Udemy
Basic and Advanced HTML Lessons-Udemy