
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
Collapsing Table Borders in CSS
The CSS border-collapse property is used to specify whether <table>elements have shared or separate borders. It can take two values: separate and collapse.
Syntax
The syntax of CSS border-collapse property is as follows −
Selector { border-collapse: /*value*/ }
The following examples illustrate CSS border-collapse −
Example
<!DOCTYPE html> <html> <head> <style> #cdemo { border-collapse: collapse; } #sdemo { border-collapse: separate; } table { display: inline-table; margin: 30px; } th,td { border: 3px ridge orange; } td { border-color: red; } caption { box-shadow: 0px -5px 4px 3px green; } </style> </head> <body> <h2>Employee Records</h2> <table id="sdemo"> <caption> Employee Details (Separate Border) </caption> <tr> <th>Employee</th> <th>Department</th> </tr> <tr> <td>Tim</td> <td>Operations</td> </tr> <tr> <td>Nathan</td> <td>Finance</td> </tr> <tr> <td>John </td> <td>Marketing</td> </tr> </table> <table id="cdemo"> <caption> Employee Details (Collapse Border) </caption> <tr> <th>Employee</th> <th>Department</th> </tr> <tr> <td>Tim</td> <td>Operations</td> </tr> <tr> <td>Nathan</td> <td>Finance</td> </tr> <tr> <td>John </td> <td>Marketing</td> </tr> </table> </body> </html>
Output
This gives the following output −
Example
<!DOCTYPE html> <html> <head> <style> table { border-collapse: separate; empty-cells: hide; display: inline-table; margin: 30px; } table+table { border-collapse: collapse; empty-cells: hide; } td { border: 3px ridge lightblue; } caption { box-shadow: 0px -5px 4px 3px grey; } </style> </head> <body> <h2>Demo Tables</h2> <table> <caption>Demo caption</caption> <tr> <td>demo</td> <td>demo</td> </tr> <tr> <td>demo</td> <td>demo</td> </tr> <tr> <td>demo</td> <td>demo</td> <td></td> </tr> </table> <table> <caption>Demo caption</caption> <tr> <td>demo</td> <td>demo</td> </tr> <tr> <td>demo</td> <td>demo</td> </tr> <tr> <td>demo</td> <td>demo</td> <td></td> </tr> </table> </body> </html>
Output
This gives the following output −
- Related Articles
- Collapsing Table Borders using CSS
- Outlines Vs Borders in CSS
- Adding Borders to Tables in CSS
- Add borders to pagination using CSS
- Adding Borders to Tables using CSS
- How do you keep parents of floated elements from collapsing in CSS?
- Create a link button with borders using CSS
- How to create and style borders using CSS?
- How can I create a table with borders in Android?
- Effect of Color Property on Borders and Outlines in CSS
- Set the color of the four borders using CSS
- How to eliminate blue borders around linked images using CSS?
- Add rounded borders to first and last link in the pagination using CSS
- Controlling Table Layout in CSS
- Controlling Table Layout using CSS

Advertisements