Module: M2-R5: Web Design & Publishing
Chapter: Ch1 Computer Intro
W3.CSS provides several classes to create responsive, colorful, and styled tables easily.
w3-table)A simple table with default W3.CSS styling.
<table class="w3-table w3-bordered">
<tr><th>Name</th><th>Age</th></tr>
<tr><td>John</td><td>25</td></tr>
<tr><td>Jane</td><td>30</td></tr>
</table>
| Name | Age |
|---|---|
| John | 25 |
| Jane | 30 |
w3-striped)Add alternating row colors for readability.
<table class="w3-table w3-striped w3-bordered">
<tr><th>Product</th><th>Price</th></tr>
<tr><td>Book</td><td>$10</td></tr>
<tr><td>Pen</td><td>$2</td></tr>
</table>
| Product | Price |
|---|---|
| Book | $10 |
| Pen | $2 |
w3-hoverable)Rows highlight when hovered.
<table class="w3-table w3-hoverable w3-bordered">
<tr><th>City</th><th>Country</th></tr>
<tr><td>Paris</td><td>France</td></tr>
<tr><td>Tokyo</td><td>Japan</td></tr>
</table>
| City | Country |
|---|---|
| Paris | France |
| Tokyo | Japan |
w3-table w3-bordered w3-teal)Add background color to the table header or table rows.
<table class="w3-table w3-bordered">
<tr class="w3-teal"><th>Course</th><th>Duration</th></tr>
<tr><td>HTML</td><td>3 Weeks</td></tr>
<tr><td>CSS</td><td>2 Weeks</td></tr>
</table>
| Course | Duration |
|---|---|
| HTML | 3 Weeks |
| CSS | 2 Weeks |