CHAPTER 19

CSS Tables

Learn how to style HTML tables using borders, spacing, alignment, colors and hover effects.

01. What is CSS Tables?

HTML tables display structured information in rows and columns.
CSS can make tables cleaner and easier to read.
Table styling is useful for student records, fees, attendance and reports.

02. Syntax

table { border-collapse: collapse; } th, td { border: 1px solid #ccc; padding: 10px; }

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>

<style>

table {

    width: 100%;

    border-collapse: collapse;

}

th,
td {

    border: 1px solid #cbd5e1;

    padding: 12px;

    text-align: left;

}

th {

    background: #2563eb;

    color: white;

}

tr:hover {

    background: #eff6ff;

}

</style>

</head>

<body>

<table>

<tr>

    <th>Course</th>
    <th>Duration</th>

</tr>

<tr>

    <td>ADCA</td>
    <td>12 Months</td>

</tr>

<tr>

    <td>Web Development</td>
    <td>12 Months</td>

</tr>

</table>

</body>
</html>

04. Important Points

✓ border-collapse: collapse creates cleaner table borders.
✓ Padding improves table readability.
✓ Header cells should be visually distinguishable.
✓ Responsive tables should be considered for mobile devices.

05. Common Mistakes

⚠ Using tables for complete webpage layouts.
⚠ Creating tables that overflow on mobile.
⚠ Using very small text inside tables.
⚠ Poor contrast between table headers and content.

06. Real World Use

Tables are useful for student records, fee details, attendance reports, course comparisons and admin dashboards.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Create a Student Table

Create a table with Student Name, Course, Fee and Status columns. Add borders, padding and a hover effect.