The Wayback Machine - https://web.archive.org/web/20240620113656/https://www.geeksforgeeks.org/space-between-two-rows-in-a-table-using-css/
Open In App

Space between two rows in a table using CSS?

Last Updated : 03 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The space between two rows in a table can be done using CSS border-spacing and border-collapse property. The border-spacing property is used to set the spaces between cells of a table and border-collapse property is used to specify whether the border of table is collapse or not. The border-spacing attribute can only be used if border-collapse attribute is set to separate.

Example: 

html




<!DOCTYPE html>
<html>
 
<head>
    <style>
        table {
            border-collapse: collapse;
        }
        th {
            background-color:green;
            Color:white;
        }
        th, td {
            width:150px;
            text-align:center;
            border:1px solid black;
            padding:5px
         
        }
        .geeks {
            border-right:hidden;
        }
        .gfg {
            border-collapse:separate;
            border-spacing:0 15px;
        }
        h1 {
            color:green;
        }
    </style>
</head>
 
<body>
    <center>
        <h1>GeeksforGeeks</h1>
        <h2>Row spacing in a table</h2>
        <table>
            <tr>
                <th>Employee ID</th>
                <th>Name</th>
                <th>Gender</th>
                <th>Age</th>
            </tr>
        </table>
        <table class="gfg">
            <tr>
                <td class="geeks">10001</td>
                <td>Thomas</td>
                <td>M</td>
                <td>32</td>
            </tr>
            <tr>
                <td class="geeks">10002</td>
                <td>Sally</td>
                <td>F</td>
                <td>28</td>
            </tr>
            <tr>
                <td class="geeks">10003</td>
                <td>Anthony</td>
                <td>M</td>
                <td>24</td>
            </tr>
        </table>
    </center>
</body>
 
</html>


Output: row spacing in table

CSS is the foundation of webpages, is used for webpage development by styling websites and web apps. You can learn CSS from the ground up by following this CSS Tutorial and CSS Examples.



Previous Article
Next Article

Similar Reads

How to Reduce Space Between Two Columns in HTML Table ?
In HTML, we can create tables with multiple columns to display data in an organized manner. Sometimes, we may want to reduce the space between two adjacent columns in a table. We can achieve this by applying CSS properties to the table elements. In this article, we will see the different approaches to reducing the space between two columns in an HT
3 min read
What are the space-x and space-y Classes in Tailwind CSS ?
In Tailwind CSS, space-x and space-y classes are used to add spacing between child elements along the horizontal (x-axis) and vertical (y-axis) directions, respectively. These classes are beneficial in flex container scenarios for managing the spacing between flex items. Syntax:&lt;div class="flex space-x-4"&gt; &lt;!-- Child elements with horizont
2 min read
How to Add Top Space Between Rows in Twitter Bootstrap ?
Twitter Bootstrap is a popular front-end development framework that provides a set of tools and features to help developers create responsive and mobile-first websites quickly and easily. One of the features offered by Bootstrap is the ability to add top space between rows. This allows developers to create better layouts and improve the overall app
2 min read
Which table property specifies the width that should appear between table cells in CSS ?
In this article, we will see how to specify the width that should appear between table cells. CSS provides the border-spacing property that can be used to set the distance between the borders of neighboring cells in the Table. This property works only when the border-collapse property is set to no-collapse separate. Syntax: border-spacing: length|i
2 min read
How to apply CSS page-break to print a table with lots of rows?
When printing a table with lots of rows the problem can arise in keeping the data together when the page ends. Since the data presented continuously makes more sense. Here we will track down ways by which one can print contents of a table with lots of rows when the situation of page-break is encountered. The most logical property that can be used f
3 min read
How to make a div span two rows in a grid using CSS ?
Suppose we have 5 elements in a row and the task to put a bigger element in the middle of a row. How to make a DIV span the 2 rows of the grid with the help of CSS. Approach 1: First get the height of the outer DIV of ID('outer'). We know the height of the outer element now design can be achieved using CSS Flexbox with flex-direction: column and fl
2 min read
How to sort rows in a table using JavaScript ?
Since JavaScript doesn't provide any inbuilt functions to sort a table we will be required to use native methods to sort a given table. We will look into the methods in this article. Approach: A basic algorithm and a similar approach will be used for both of the following examples. Loop the program to switch and sort the elements until it is sorted
4 min read
How to delete all table rows except first one using jQuery?
Given an HTML document containing an HTML table and the task is to delete the table row except the first one using jQuery. Approach: First, we create a table using &lt;table&gt; tag and add a button containing btn id. When a user clicks on the button, then the jQuery function is called. The jQuery function removes all the rows except the first one
1 min read
How to select all even/odd rows in table using jQuery ?
In this article, we will see how to make a table by selecting the alternate rows i.e. selecting the even or odd rows by clicking on the respective buttons. This feature can be useful at the time of selecting the specific data/elements of either of the rows or to highlight the table of data for display from the large data set. This enables us to qui
3 min read
How to create Dynamic Drag and Drop table rows using jQuery Ajax ?
In this article, we will discuss the method of How to create Dynamic and Drop table rows using JQuery Ajax. We will use jQuery and HTML CSS to perform the operations of Drag and Drop on the table row. First to perform the operations of the Drag and Drop table row we need two jQuery libraries without these libraries we can't perform the Drag and Dro
4 min read