CSS Tutorials

Overview

HTML tables can be styled to a point using tag attributes like border, cell-padding, cell-spacing, and width/height.

<table border="1" cellpadding="5" cellspacing="5" width="300">
    <tr>
        <th></th>
        <th></th>
    </tr>
    <tr>
        <td></td>
        <td></td>
    </tr>
</table>

However this is somewhat limited, and CSS can be used to make your tables look exactly as you intend.

Plus, the styles will apply to all tables site wide, removing the need to style each table individually from within the <table> tag.

Note

The following are basic examples. Towards the bottom of this page you’ll find a complete list of all applicable properties, where you can find more information on the properties discussed, and sometimes find more involved properties not discussed on this page.

Using CSS

Set the width:

table {
    width: 100%;
}

Styling and collapsing the border:

By default a table will have a border around it and each cell will have a border around it, and there is space between these borders creating a double-border effect. By using the border-collapse property, these borders are merged into one making them more pleasing to the eye. And to add to the look, we can set the border color, style, and size.

table, th, td {
    border: red solid thin;
    border-collapse: collapse;
}

Adjusting the text and padding:

th, td {
    color: red;
    font-size: 12px;
    font-weight: bold;
    padding: 10px;
    text-align: left;
}

Table-Specific Properties


CSS Notes:


We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.