Table Border in HTML is used to display a border around the table contents. This can be set around the table by specifying values like 0 for no border is showing around the table cells, whereas value 1 is set to display a border around the table cells. Table width can be set in number values to define how much thick border users want to give around their table. One can set border either to the whole table or to a specific row or column or only for the table head; everything is possible.
Syntax of the Table Border in HTML
There are multiple ways for defining table-border; let’s see the syntax for them one by one:
1. General Table border:This is generally used to define a simple border around the table like:
Copy after login
Example:
table, th, td{ border:1px solid blue; }
Copy after login
2. Collapsible Table border:This property is used to set a collapsible border in a single line around our table using the border-collapse property.
3. The border around the table:This property allows us to add table border only at outside edges, not to each individual table cells, simply as :
table { border : 1px; }
Copy after login
4. Dotted table border:one can simply add a dotted outline as a border to their table by using simply the following syntax as :
table{ border : 1px; dotted color-name; }
Copy after login
5. Dashed table border:Like dotted, we can set the dashed border around our table or table cells. This could be thin or thick as per user choice by setting value.
table{ border : 3px; dashed color-name; }
Copy after login
6. Double table border:If we want to add a double outline to our table, then it also possible by setting a property within CSS code and give a double border around the table.
table{ border : 1px; double color-name; }
Copy after login
7. Table border around table cells:This syntax helps us give a border around the individual cells or any specific table cell with your favorite color code. In this syntax, we want to add border code value with each cell separately.
8. Table border with CSS classes:rather than setting the border to each individual table cells, CSS classes helps us to give common border code to our table. This can be done by using the following syntax:
Copy after login
9. Table bottom border:This property of the table border is used to give horizontal dividers among the table’s th and td tag as follows:
th, td{ border-bottom: value color-name; }
Copy after login
10. Rounded table border: It will show rounded corners to the table border.
table{ border-radius: value; border: value color-name; }
Copy after login
Examples of Table Border in HTML
Following are the examples of Table Border
Example #1
The following example is showing two different tables with different borders. The first table is showing a normal border around the table, whereas the second table is an example of a collapsible table border format.
HTML code:
Genral Table Border
SR.NO
NAME
Education
AGE
1
Dinesh
BCA
26
2
Raj
CA
30
3
Deepti
ME
28
4
Akhilesh
B.com
21
5
Sara
MBA
26
Collapsible Table Border
Emp Code
Emp Name
Job Title
Salary(LPA)
911
Zoya Shaikh
Developer
3.6
912
Lisa Dev
Tester
2.8
913
Deepak Jadeja
Digital Marketing
5.2
914
Aditi Yewale
Developer
4
915
Simren Rao
HR
5.6
Copy after login
Output:
Example #2
This example is showing how to set the border to the table only for the outside part with different table border types:
HTML code:
Table with outside border
Index
Seasons
Durations
1
Summer
4 months
2
Rainy Seasons
4 months
3
Winter
4 months
Table with dotted border
Index
Seasons
Durations
1
Summer
4 months
2
Rainy Seasons
4 months
3
Winter
4 months
Table with dashed border
Index
Seasons
Durations
1
Summer
4 months
2
Rainy Seasons
4 months
3
Winter
4 months
Table with double border
Index
Seasons
Durations
1
Summer
4 months
2
Rainy Seasons
4 months
3
Winter
4 months
Copy after login
Output:This output showing a table with dotted, dashed and double border to the outside of the table.
Example #3
Example showing table cells bordered in different color individual as:
HTML code:
Table border around Cell
First Name
Last Name
City
Rita
Mishra
Mumbai
Rashmi
Patil
Nagpur
Kartik
Dev
Pune
Copy after login
Output:
Example #4
Another table rounded border with a border as the horizontal divider
HTML code:
Table border around Cell
Cake
Weight
Price
Chocalate
1/2 kg
400/-
Rasmalai
1 kg
850/-
Copy after login
Output:
Conclusion
The table border in HTML is set by assigning value 1 to display a border around the table, whereas 0 to hide a border around the table.
One can set a border around the table in various types like simple thick or thin border, collapsible, dotted, double, dashed borders.
The above is the detailed content of Table Border in HTML. For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn