CSS Border Spacing

The CSS border-spacing property specifies the space between the borders of adjacent cells in a table. It only applies when the table's border-collapse property is set to "separate." This property helps in achieving a clean and structured look for tabular data.

Key Points on CSS Border Spacing:

Syntax for CSS Border Spacing:

Syntax Example

/* Single value for uniform spacing */
        .table {
            border-spacing: 10px;
               }
        
        /* Two values for horizontal and vertical spacing */
        .table {
            border-spacing: 15px 20px; /* Horizontal: 15px, Vertical: 20px */
               }

Examples of CSS Border Spacing:

The following examples demonstrate the usage of the border-spacing property:

Code Example: Uniform Border Spacing


            .table {
            border-spacing: 10px;
            border: 1px solid black;
                   }

Output

Cell 1 Cell 2
Cell 3 Cell 4

Code Example: Horizontal and Vertical Border Spacing


            .table {
            border-spacing: 20px 15px; /* Horizontal: 20px, Vertical: 15px */
            border: 1px solid black;
                   }

Output

Cell 1 Cell 2
Cell 3 Cell 4

Common Use Cases:

When using border-spacing, ensure the table structure is consistent and does not interfere with the overall design of the webpage. For tables with collapsing borders, consider alternatives like padding.