Article image Styling Tables in CSS

Styling Tables in CSS

Page 14 | Listen in audio

Tables are key elements on many websites, as they allow you to organize information in a clear and concise way. However, tables can often look disorganized and unattractive, which can detract from the user experience. Fortunately, CSS provides many options for styling tables and making them more attractive and readable. To start with, it's important to define some basic table properties using HTML tags. The `

` tag is used to create the table itself, while the `` tag is used to define each table row and the `` tag to define the table header and the `` tag to define the table body. One of the simplest ways to style a table is by using the `border` property, which defines the width and color of the table border and cells. For example, to set a 1-pixel black border for the entire table and cells, we can use the following CSS code: ```css table, th, td { border: 1px solid black; } ``` Furthermore, it is possible to use the `padding` property to define the internal space of the table cells. For example, to set an inner spacing of 10 pixels for all table cells, we can use the following CSS code: ```css all { padding: 10px; } ``` Another interesting option is to use the `background-color` property to define the background color of the table cells. For example, to set a light gray background color for all table cells, we can use the following CSS code: ```css all { background-color: #f2f2f2; } ``` It is also possible to use the `text-align` property to align the contents of table cells. For example, to align all cell contents to the left, we can use the following CSS code: ```css all { text-align: left; } ``` Another interesting option is to use the `border-collapse` property to define whether the table and cell borders should be merged or separated. For example, to merge table and cell borders, we can use the following CSS code: ```css table { border-collapse: collapse; } ``` Finally, you can use the `font-weight` property to define the weight of the font used in the table cells. For example, to set a bold font for all table cells, we can use the following CSS code: ```css all { font-weight: bold; } ``` In summary, styling tables in CSS can be a simple and effective task, as long as the correct properties are used. Using the `border`, `padding`, `background-color`, `text-align`, `border-collapse` and `font-weight` properties, you can create more attractive and readable tables for users.

Now answer the exercise about the content:

_Which CSS property is used to define the background color of table cells?

You are right! Congratulations, now go to the next page

You missed! Try again.

Article image Form Styling in CSS

Next page of the Free Ebook:

15Form Styling in CSS

2 minutes

Earn your Certificate for this Course for Free! by downloading the Cursa app and reading the ebook there. Available on Google Play or App Store!

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text

` tag is used to define each table cell. Additionally, you can use the `