Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape

CSS Tables

CSS Tables

CSS CODES & EXAMPLES

CSS Tables

Learn how to design HTML tables with CSS. Create clean data tables, student result tables, course tables, pricing tables, hover effects, zebra stripes and responsive table layouts.

01

Introduction to CSS Tables

Style HTML table elements

HTML tables are used to display structured information in rows and columns. CSS allows you to control borders, spacing, alignment, colors, typography, hover effects and responsive behavior.

Common elements: <table> <tr> <th> <td> <caption>
02

Table Borders

Add borders to tables

The border property adds a visible border around table elements.

table-border.css
table,
th,
td {
  border: 1px solid #1769d5;
}

th,
td {
  padding: 12px;
}
CourseDuration
CCA6 Months
DCA1 Year
03

border-collapse

Control table border behavior

The border-collapse property controls whether adjacent table borders are separated or combined.

Separate
NameCourse
RahulDCA
Collapse
NameCourse
RahulDCA
border-collapse.css
table {
  border-collapse: collapse;
}
04

Table Width & Height

Control table dimensions
table-size.css
table {
  width: 100%;
}

th,
td {
  height: 45px;
}
SubjectMarks
Computer92
English86
05

Table Alignment

Align table content
StudentCourseScore
PriyaDCA94%
AmitCCA89%
table-align.css
th {
  text-align: left;
}

td {
  text-align: center;
}
06

Table Padding

Create comfortable table spacing

Padding creates space between the table content and its cell border.

table-padding.css
th,
td {
  padding: 15px 20px;
}
CourseLevel
ADCAAdvanced
Web DesigningProfessional
08

Table Headers

Design professional headers
Student IDStudent NameCourseStatus
SN001Rahul KumarDCAActive
SN002Priya SinghCCAActive
SN003Amit YadavADCACompleted
09

Zebra-Stripped Tables

Alternate row backgrounds
#SubjectMarksGrade
1Computer95A+
2English88A
3Mathematics91A+
4Science84A
zebra-table.css
tr:nth-child(even) {
  background: #f3f7fb;
}
10

Hoverable Table Rows

Add interaction to table rows
CourseDurationStudents
CCA6 Months45
DCA1 Year68
ADCA1 Year52
table-hover.css
tbody tr:hover {
  background: #eaf4ff;
  cursor: pointer;
}
11

Responsive Tables

Make tables mobile friendly

Wide tables can overflow on small screens. A common solution is to place the table inside a horizontally scrollable container.

StudentCourseRegistrationAdmission DateModeStatus
Rahul KumarDCASN00115 Aug 2026OnlineActive
Priya SinghADCASN00216 Aug 2026OfflineActive
responsive-table.css
.table-wrapper {
  overflow-x: auto;
}

table {
  min-width: 700px;
  width: 100%;
}
12

Table Captions

Add titles to tables
Popular Computer Courses
CourseDuration
CCA6 Months
DCA1 Year
ADCA1 Year
table-caption.css
caption {
  caption-side: top;
  padding: 12px;
  font-weight: bold;
  color: #1769d5;
}
13

border-spacing

Control space between cells
HTMLCSSJS
StructureDesignInteraction
border-spacing.css
table {
  border-spacing: 8px;
}
14

empty-cells

Control empty table cells
CourseDurationMode
CCA6 Months
DCAOnline
empty-cells.css
table {
  empty-cells: show;
}
16

Course Table

Education website example
CourseLevelDurationCertificate
CCACertificate6 MonthsYes
DCADiploma1 YearYes
ADCAAdvanced Diploma1 YearYes
17

Student Result Table

Academic result example
SubjectMax MarksObtainedGradeResult
Computer10094A+PASS
English10087APASS
Mathematics10091A+PASS
Total300272A+PASS
18

Pricing Table

Course pricing example
STARTER

CCA

₹2,999
  • Computer Fundamentals
  • MS Office
  • Internet Skills
  • Certificate
View Course
ADVANCED

ADCA

₹8,999
  • Advanced Applications
  • Office Automation
  • Web Designing
  • Practical Projects
  • Certificate
View Course
19

Live CSS Table Runner

Experiment with a real table example
LIVE PREVIEW
20

Practice Task

Test your CSS Tables skills

🎯 Your Challenge

Create a professional student result table using HTML and CSS.

  • Create a table with five columns.
  • Add a professional table header.
  • Use border-collapse.
  • Add cell padding.
  • Create zebra-striped rows.
  • Add a hover effect.
  • Display PASS and FAIL badges.
  • Make the table responsive.
21

CSS Table Quick Reference

Important properties
border Adds borders around table elements.
border-collapse Combines or separates table borders.
border-spacing Controls spacing between cells.
padding Controls space inside table cells.
text-align Controls horizontal text alignment.
vertical-align Controls vertical content alignment.
width Controls table or column width.
height Controls table cell height.
caption-side Controls caption position.
empty-cells Controls the appearance of empty cells.
See also  CSS Lists
`;document.getElementById( "sncecTablePreview" ).srcdoc=html;}document.addEventListener( "DOMContentLoaded", function(){sncecTableRun();} );

Leave a Reply

Your email address will not be published. Required fields are marked *