[フレーム]

W3.CSS Tables

Tables

W3.CSS provides classes for creating clean and responsive HTML tables.

Tables can have stripes, borders, colors, hover effects, and more.

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67
Bo Nilsson 50
Mike Ross 35

Table Classes

Class Description
w3-table Basic table
w3-striped Adds stripes to the table rows
w3-bordered Adds borders between table rows
w3-border Adds a border around the table
w3-table-all All classes above set
w3-hoverable Adds a hover effect to table rows
w3-centered Centers table content
w3-responsive Makes wide tables scroll on small screens

Basic Table

Use the w3-table class to create a basic table.

Product Category Price
Laptop Computers 999ドル
Phone Mobile 699ドル
Tablet Mobile 499ドル
Monitor Computers 299ドル

Example

<table class="w3-table">
<tr>
<th>Product</th>
<th>Category</th>
<th>Price</th>
</tr>
<tr>
<td>Laptop</td>
<td>Computers</td>
<td>999ドル</td>
</tr>
<tr>
<td>Phone</td>
<td>Mobile</td>
<td>699ドル</td>
</tr>
<tr>
<td>Tablet</td>
<td>Mobile</td>
<td>499ドル</td>
</tr>
<tr>
<td>Monitor</td>
<td>Computers</td>
<td>299ドル</td>
</tr>
</table>
Try it Yourself »

Striped Tables

Add w3-striped to make alternate rows different colors.

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67

Example

<table class="w3-table w3-striped">
...
</table>
Try it Yourself »

Table Borders

The w3-bordered class adds a bottom border to each table row:

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67

Example

<table class="w3-table w3-bordered">
...
</table>
Try it Yourself »

Colored Table Headers

Use any W3.CSS color class on a table row to create a colored header.

Product Category Price
Laptop Computers 999ドル
Phone Mobile 699ドル
Tablet Mobile 499ドル
Monitor Computers 299ドル

Example

<table class="w3-table w3-bordered">
<tr class="w3-blue">
<th>Product</th>
<th>Category</th>
<th>Price</th>
</tr>
...
</table>
Try it Yourself »

w3-bordered adds borders between rows.

w3-border adds a border around the table.


Striped Bordered Table

Combine the w3-striped class and the w3-bordered class to create a striped bordered table:

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67

Example

<table class="w3-table w3-striped w3-bordered">
...
</table>
Try It Yourself »

Border Around a Table

The w3-border class is used to display a border around a table:

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67

Example

<table class="w3-table w3-striped w3-border">
...
</table>
Try It Yourself »

Note

The w3-border class is not only for tables. It can be used on any HTML element!


Combine Table Classes

Table classes can be combined to create the style you want.

Product Category Price
Laptop Computers 999ドル
Phone Mobile 699ドル
Tablet Mobile 499ドル
Monitor Computers 299ドル

Example

<table class="w3-table w3-striped w3-bordered w3-border">
...
</table>
Try it Yourself »

Combining All

The w3-table-all class combines all of the classes above:

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67

Example

<table class="w3-table-all">
...
</table>
Try It Yourself »

Flipping the Stripes

To flip the stripes (start with the light-grey color), add a <thead> element around the table header row. You must also define a color to be used for the table header row:

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67
Bo Nilson 35

Example

<thead>
<tr class="w3-light-grey">
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
</tr>
</thead>
Try It Yourself »

Hoverable Tables

The w3-hoverable class highlights a row when the mouse moves over it.

Product Category Price
Laptop Computers 999ドル
Phone Mobile 699ドル
Tablet Mobile 499ドル
Monitor Computers 299ドル

Example

<table class="w3-table w3-bordered w3-hoverable">
...
</table>
Try it Yourself »


Responsive Tables

Wide tables can be difficult to view on small screens.

Place the table inside a w3-responsive container to allow horizontal scrolling when needed.

Resize the screen to see the effect on the table below:

First Name Last Name Points Points Points Points Points Points Points Points Points Points Points
Jill Smith 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000
Eve Jackson 9400 9400 9400 9400 9400 9400 9400 9400 9400 9400 9400
Adam Johnson 6700 6700 6700 6700 6700 6700 6700 6700 6700 6700 6700

Example

<div class="w3-responsive">
<table class="w3-table-all">
...
</table>
</div>
Try it Yourself »

A responsive table stays unchanged when there is enough space.

On smaller screens, the table can scroll horizontally instead of overflowing the page.


Table as a Card

Add a card class to make the table stand out from the page.

Product Category Price
Laptop Computers 999ドル
Phone Mobile 699ドル
Tablet Mobile 499ドル
Monitor Computers 299ドル

Example

<table class="w3-table w3-striped w3-card">
...
</table>
Try it Yourself »

Different Table Sizes

Font-size classes can also be used on tables.

Class Size
w3-tiny Tiny
w3-small Small
w3-large Large
w3-xlarge Extra large
w3-xxlarge Extra extra large
w3-xxxlarge Extra extra extra large
w3-jumbo Jumbo

Examples

<table class="w3-table-all w3-tiny">
Try It Yourself »
<table class="w3-table-all w3-small">
Try It Yourself »
<table class="w3-table-all w3-large">
Try It Yourself »
<table class="w3-table-all w3-xlarge">
Try It Yourself »
<table class="w3-table-all w3-xxlarge">
Try It Yourself »
<table class="w3-table-all w3-xxxlarge">
Try It Yourself »
<table class="w3-table-all w3-jumbo">
Try It Yourself »

What You Have Learned

  • w3-table creates a basic styled table
  • w3-striped adds alternating row colors
  • w3-bordered adds borders between rows
  • w3-border adds a border around a table
  • w3-hoverable adds a row hover effect
  • Color classes can be used on table rows
  • w3-responsive helps wide tables fit small screens

More Examples

Explore more ways to style W3.CSS tables.


Colored Table

Use any of the w3-color classes to display a colored table:

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67

Example

<table class="w3-table w3-blue">
Try It Yourself »

Right Align one Table Column

The w3-right-align class right aligns the content of a column:

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67

Example

<table class="w3-table-all">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th class="w3-right-align">Points</th>
</tr>

Try It Yourself »

Centering one Column

The w3-center class centers the content of a column:

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67

Example

<table class="w3-table-all">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th class="w3-center">Points</th>
</tr>
Try It Yourself »

Centering Table Content

The w3-centered class centers the content of the table:

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67

Example

<table class="w3-table-all w3-centered">
Try It Yourself »

Custom Hover Colors

If you want a specific hover color, add any of the w3-hover-color classes to each <tr> element:

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67

Example

<tr class="w3-hover-green">
Try It Yourself »
Product Price
Laptop 999ドル
Phone 699ドル
Tablet 499ドル


New

W3Schools Adventure App

Coding fundamentals as a game. Bite-sized lessons and challenges.

Ready to start your journey? Your streak is waiting.
+60 XP
W3Schools Adventure tutor
W3Schools Adventure map
×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

FORUM ABOUT ACADEMY
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

AltStyle によって変換されたページ (->オリジナル) /