
To style HTML tables with CSS, you can use the border-collapse property to control the space between rows. This property can be set to either collapse or separate, depending on the desired outcome.
Using border-collapse: separate will create a space between rows, while border-collapse: collapse will remove the space.
In the example table, setting border-collapse: separate adds a 2px space between rows. The border-spacing property can also be used to control the space between rows, with a default value of 2px.
You might like: How to Separate Header from Body in Html
Adding Space Between Rows
Adding space between rows is a crucial aspect of HTML table design. You can use CSS classes to achieve this.
One method is to add an empty row of cells between each row, like this:. This is especially useful when combined with CSS pseudo classes to target the empty cells.
You can also use the border-spacing property to add space between rows. For example, border-spacing: 20px 0 will add a 20px gap between rows, while border-spacing: 10px 20px will add 10px horizontal and 20px vertical spacing. However, keep in mind that this property has no effect if you apply the border-collapse: collapse property on the table.
Here are some common methods to add space between rows:
Using Empty Rows

You can create space between table rows by adding an empty row of cells. This can be done by adding a tag with empty tags.
The empty row can be targeted using CSS pseudo class to apply styles such as removing the border and setting a specific height.
For example, you can use the following code to target the empty cells:
border: none;
height: 10px;
}
This will add a 10-pixel height to the empty row, creating space between the table rows.
Alternatively, you can use the tag with a specific height to create space between rows, like this:
This method can be useful when you need to mimic a margin between table rows.
Take a look at this: Adding a Chart to Html
Table Row Spacing
Table row spacing is a crucial aspect of creating visually appealing tables. You can create space between table rows by adding an empty row of cells.
There are several methods to achieve this, including using CSS pseudo classes to target empty cells. One way to do this is by adding a tag with empty tags, like this:. You can then use CSS to style these empty cells, such as by setting their border and height.
Alternatively, you can use the border-spacing property to set the distance between the borders of neighboring table cells. For example, you can set border-spacing: 10px 20px to create 10px of horizontal spacing and 20px of vertical spacing between cells.
Expand your knowledge: Html Table Merge Cells

If you want to add padding to an entire row, you can use the padding property in CSS. This will add equal padding to all cells within that row. You can also use the border-collapse property with its "separate" value to achieve this effect.
To create a more subtle effect, you can use the padding property to push the content inside the cell further away from the border. However, be aware that this will also push the border further away from the element, so you may not see any space between the rows.
If you prefer a more manual approach, you can use inline styles to apply padding directly within the HTML. However, this approach can become cumbersome for larger tables.
Here are some key CSS properties to keep in mind when working with table row spacing:
- border-spacing: sets the distance between the borders of neighboring table cells
- padding: adds padding to all cells within a row
- border-collapse: collapse: sets the border-collapse property to "collapse", which can affect the border-spacing property
- display: block: sets the display property to "block", which can help the border-spacing property work as intended
CSS Properties for Spacing
The border-spacing property is used to change the space between table cells. It's specified as either one or two values.
When one value is specified, it defines both the horizontal and vertical spacings between cells.
When two values are specified, the first value defines the horizontal spacing between cells, and the second value defines the vertical spacing between cells.
The CSS for border-spacing can be written as border-spacing: 30px, which means the spacing between cells is 30px.
To make space between rows of a table, we can use the padding property or the border-spacing property.
The border-collapse property has no effect on the cells of the table if it's set to collapse.
Here's a summary of the CSS properties for spacing:
You can use the border-spacing property to set the distance between the borders of neighbouring table cells.
The border-spacing property can be used with the border-collapse property set to separate.
The border-spacing property has no effect if the border-collapse property is set to collapse.
Worth a look: Html Value Property
You can use the padding property to add space between the cell content and the cell border.
The padding property can be used to push the content inside the cell and make space between rows.
You can use the border-spacing property to set the horizontal and vertical spacings between cells.
The border-spacing property can be used to create space between table rows.
You can use the padding property to add space between the cell content and the cell border.
The padding property can be used to push the content inside the cell and make space between rows.
Broaden your view: Is Html Used to Create Web Pages
Alternative Methods
If you're looking for alternative methods to add space between rows in an HTML table, one option is to use the extra tag. This can be done by adding a with a specified height between each of your table rows.
You can style the extra with a height to control the amount of space it adds. For example, the article suggests setting the height to 20px like this: . This will add a 20px gap between each row.
By using this method, you can keep the border close to the element and mimic the margin. It's a simple yet effective way to add space between rows in your HTML table.
If this caught your attention, see: Html Line Height
Creating and Applying Spacing
You can add space between table rows using various methods. One way is to use the CSS padding property, which will add equal padding to all cells within that row.
The padding property can be applied to an entire row, adding space between the cells. This is a simple and effective way to create space between rows.
You can also use the border-spacing property to create space between cells. This property takes two values, one for horizontal spacing and one for vertical spacing.
Here are some key points to keep in mind when using border-spacing:
- border-spacing: 10px 20px will create horizontal and vertical spacing of 10px and 20px respectively.
- If you apply the border-collapse: collapse property on the table, border-spacing will have no effect on the cells.
To keep the border close to the element and mimic the margin, you can use the extra tag between each row. This will add a small gap between the rows without affecting the border.
Using Inline Styles
Using Inline Styles can become cumbersome for larger tables, but it's a straightforward approach to apply padding directly within the HTML.
You can utilize inline styles to apply padding to your table by adding the style attribute directly to the table element.
If you prefer to keep the border close to the element and mimic the margin, put another between each of your table's like so – , but inline styles are more direct.
This approach is great for small adjustments, but for larger tables, using external or internal CSS might be more efficient.
Related reading: Html Inline Js
Specific Spacing Topics
Cell spacing is the space between each cell in a table, and by default, it's 2 pixels. You can change this using the CSS border-spacing property on the table element.
To specify the cell spacing, you can use either one or two values. If you use one value, it defines both the horizontal and vertical spacings between cells. If you use two values, the first value defines the horizontal spacing, and the second value defines the vertical spacing.
Readers also liked: Html Table Center Text in Cell
For example, using the CSS border-spacing property with one value, you can set the spacing between cells to 30px.
The border-spacing property can be used to control the space between cells, and it's a more modern and flexible approach than using the cellpadding attribute.
Here's a summary of how to specify the cell spacing:
- One value: defines both horizontal and vertical spacings
- Two values: first value defines horizontal spacing, second value defines vertical spacing
You can use the following CSS to set the spacing between cells to 30px:
```css
table {
border-spacing: 30px;
}
```
This will add a 30px spacing between each cell in the table.
Wrapping Up with CSS
Applying CSS for table spacing not only modernizes your HTML code but also enhances its maintainability and readability. The use of border-collapse, padding, and border-spacing properties allows for precise control over the table layout.
You can replace the cellpadding and cellspacing attributes with CSS properties like border-collapse and border-spacing. For example, set the border-collapse property to "separate" and use the border-spacing property to set the distance between the borders of neighbouring table cells.
For another approach, see: Html Property Attribute
Using CSS for table spacing is a more elegant and flexible solution compared to traditional HTML attributes. This is because CSS allows you to make space between rows, as we learned earlier.
To achieve the same effects as cellpadding and cellspacing, use the border-collapse property with its "separate" value for the table, and the border-spacing property to set the distance between the borders of neighboring table cells.
Here's a quick rundown of the key CSS properties to use:
- border-collapse: separate;
- border-spacing: [insert value];
- background-color: [insert value];
- color: [insert value];
- width: [insert value];
- padding: [insert value];
- text-align: center;
- border: [insert value];
- border-width: [insert value];
- border-style: [insert value];
- border-color: [insert value];
Featured Images: pexels.com


