HTML tables can be styled to a point using tag attributes like border, cell-padding, cell-spacing, and width/height.
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.
Using CSS
Setting 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 Text and Padding
th, td {
color: red;
font-size: 12px;
font-weight: bold;
padding: 10px;
text-align: left;
}
Table-Specific Properties
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.
Why 1SMARTchicken?
See More →
Thanks for your support!
CSS Books
All are affiliate links. Thank you for your support!
CSS NOTES:
- The “inherit”, “initial” and “unset” keywords can be used with any CSS property to set its value
- In CSS there are many ways to express a color value in a property
Feedback
If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.