CSS Tables
CSS allows you to style HTML tables by customizing their layout, spacing, borders, background, and more. This guide covers essential table styling techniques.
1. Basic Table Styling
A. Default Table (Without CSS)
✅ Renders a simple unstyled table.
2. Adding Basic Table Styles
✅ Improves readability by adding borders, spacing, and background color.
3. Table Properties
Property | Description |
---|---|
border-collapse | Merges table borders into a single border (collapse or separate ). |
border-spacing | Defines the space between table cells (only when border-collapse: separate ). |
width | Sets the table width (px , % , auto ). |
text-align | Aligns text inside table cells (left , center , right ). |
vertical-align | Aligns cell content (top , middle , bottom ). |
padding | Adds space inside cells. |
4. Alternating Row Colors (Zebra Stripes)
✅ Enhances readability by adding striped rows.
5. Hover Effect for Rows
✅ Highlights a row when hovered.
6. Responsive Tables (Scroll on Small Screens)
✅ Ensures tables are scrollable on small screens.
7. Full Example
✅ Well-styled, responsive, and interactive table.
8. Browser Support
✅ Fully supported in all modern browsers.