Table Types
🎨 Table Styling — Table Ko Sundar Banao
table { border-collapse: collapse; } th, td { padding: 12px; }
Default HTML tables BAHUT UGLY hain — no borders, no padding, no colors, koi personality nahi. CSS unhe professional, readable data tables mein transform karta hai jo log actually dekhna chahte hain.
Key CSS: border-collapse: collapse double borders hataata hai, padding breathing room add karta hai, nth-child(even) striped rows banata hai, :hover rows highlight karta hai, aur text-align alignment control karta hai.
Default vs Styled: Default table jaise raw Excel file — data hai par padhna dardnak. Styled table jaise polished report — borders, spacing, headers highlighted, zebra stripes. Same data, completely different experience.
Code Example
HTML — Table Styling — Table Ko Sundar Banao
/* Professional table styling */
table.styled {
width: 100%;
border-collapse: collapse;
font-size: 14px;
}
table.styled th,
table.styled td {
padding: 12px 16px;
text-align: left;
border-bottom: 1px solid #e5e7eb;
}
table.styled thead th {
background: #f8fafc;
font-weight: 600;
color: #1a1a1a;
border-bottom: 2px solid #e2e8f0;
position: sticky;
top: 0;
}
/* Zebra stripes */
table.styled tbody tr:nth-child(even) {
background: #f8fafc;
}
/* Hover highlight */
table.styled tbody tr:hover {
background: #eff6ff;
}
/* First column bold */
table.styled td:first-child {
font-weight: 600;
color: #1a1a1a;
}
/* Right-aligned numbers */
table.styled td:last-child {
text-align: right;
font-family: 'JetBrains Mono', monospace;
font-size: 13px;
}
/* Border around entire table */
table.bordered {
border: 1px solid #e5e7eb;
border-radius: 8px;
overflow: hidden;
}
table.bordered th,
table.bordered td {
border: 1px solid #e5e7eb;
}
/* Compact table */
table.compact th,
table.compact td {
padding: 6px 12px;
font-size: 13px;
}
/* Card-style table */
table.card-style {
border-collapse: separate;
border-spacing: 0;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
table.card-style thead th {
background: #1a1a1a;
color: white;
}
table.card-style td {
border-bottom: 1px solid #f1f5f9;
}
table.card-style tbody tr:last-child td {
border-bottom: none;
}border-collapsecollapse = single borders, separate = double borders with gappaddingCells ke andar space — readability ke liye zaroorinth-child(even)Zebra stripes — alternate row backgroundstr:hoverMouse hover pe row highlightposition: stickyScroll pe headers visible rehte hainborder-spacing: 0border-collapse: separate ke saath, cells ke beech gap controlborder-radiusTable ke outer edges pe rounded corners✅ When to Use
- Website pe koi bhi visible table — default styling kabhi kaafi nahi hoti
- Dashboard data tables
- Pricing comparison tables
- Timetables aur schedules
- Report tables
❌ When NOT to Use
- Layout tables jo users se hidden hain (visual styling ki zaroorat nahi)
- Print stylesheets ko alag styling ho sakti hai
Hamesha `border-collapse: collapse` use karo — default `separate` mode double borders banata hai jo bahut ugly lagti hain. Card-style tables ke liye `separate` use karo `border-spacing: 0` aur table element pe `border-radius` lagao.