Styling Tables

The table-related properties:

PropertyDescriptionValues
border-collapseSpecifies how borders on adjacent cells are handled.collapse separate
border-spacingSpecifies the spacing between adjacent cell borders. 1 or 2 <length>
caption-sideSpecifies the location of the caption element.top bottom
empty-cellsSpecifies how borders are drawn on empty cells.hide show
table-layoutSpecifies the layout style for the table.auto fixed

Collapsing Table Borders

The border-collapse property controls how to draw borders for the table element. The browser draws a border around the table plus a border around each cell. You can address this by applying the border-collapse property.

 
<!DOCTYPE HTML> 
<html> 
    <head> 
        <title>Example</title> 
        <style> 
            table { 
                border-collapse: collapse; 
            } 
            th, td { 
                padding: 2px; 
            } 
        </style> 
    </head> 
    <body> 
        <table border="1"> 
            <thead> 
                <tr> 
                    <th>Name</th><th>Value</th>
                </tr> 
            </thead> 
            <tbody> 
                <tr> 
                    <th>A</th><td>B</td>
                </tr> 
                <tr> 
                    <th>B:</th><td>C</td>
                </tr> 
            </tbody> 
        </table> 
    </body> 
</html>
  
Click to view the demo
Home 
  HTML CSS Book 
    CSS  

Table Style:
  1. Styling Tables
  2. Configuring Separated Borders
  3. Dealing with Empty Cells
  4. Positioning the Caption
  5. Specifying the Table Layout
Related: