Open In App

How place a checkbox into the center of a table cell?

Last Updated : 15 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

To center a checkbox in a table cell, use CSS to align it horizontally and vertically within the cell.

Below are the approaches to place a checkbox in the center of a table cell:

Using FlexBox Property

In this method, we are using the display FlexBox property to center the checkbox in the cell of the table. 

Note: This method will not make the text after the checkbox be treated as the block element and text entered after the check will be visible

Example: The example below shows how place a checkbox into the center of a table cell using Using FlexBox property.

html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    /* Stylesheet*/
    table {
        border-collapse: collapse;
        padding: 20px;
    }

    td {
        border: 1px solid #000;
        padding: 20px;
    }

    .checkbox {
        width: 200px;
        background-color: #098043;
        color: #fff;
        margin: auto;
    }

    input {
        margin: auto;
        /*setting margin to auto of the cheeckbox*/
        display: flex;
        /*Flex box property*/
    }
</style>

<body>
    <!-- Table start-->
    <table>
        <!-- row start-->
        <tr>
            <!-- column start-->
            <td class="checkbox">Geeks for Geeks</td>
            <td class="checkbox">Geeks for Geeks</td>
            <!-- Column closed-->
        </tr>
        <!-- row closed-->
        <tr>
            <td class="checkbox">
                <input type="checkbox">
            </td>
            <td class="checkbox">
                <input type="checkbox">
            </td>
        </tr>
    </table>

</body>

</html>

Output:

Using Text align center Property

In this method, we will be using Text align center property of the CSS to center the checkbox in the cell.

Note: This method will center everything in the td of the table.

Example: The example below shows how place a checkbox into the center of a table cell using Text align center property.

html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    table,
    td {
        border-collapse: collapse;
        border: 1px solid #000;
        padding: 10px;
    }

    .checkbox {
        text-align: center;
        /*Centering the text in a td of the table*/
    }
</style>

<body>
    <table>
        <tr>
            <td>
                Geeks for Geeks
            </td>
            <td>
                Geeks for Geeks
            </td>
        </tr>
        <tr>
            <td class="checkbox">
                <input type="checkbox">
            </td>
            <td class="checkbox">
                <input type="checkbox">
            </td>
        </tr>
    </table>

</body>

</html>

Output:


Similar Reads