Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
W3.CSS Tags
Next article icon

W3.CSS Tables

Last Updated : 10 Aug, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

W3.CSS provides a series of classes that can be used to apply various styling to the tables such as changing the heading appearance, making the rows stripped, adding or removing borders, making rows hoverable, etc. W3.CSS also provides classes for making tables responsive.

Simple Table: The .w3-table class is used to create a simple W3.CSS table. This class name is used with <table> tag to create a table.

Syntax:

<table class="w3-table"> Table Contents... <table>

Example:

HTML
<!DOCTYPE html> <html> <head>      <!-- Adding W3.CSS file through external link -->     <link rel="stylesheet"            href="https://www.w3schools.com/w3css/4/w3.css">        </head> <body>     <!-- w3-container is used to add 16px           padding to any HTML element.  -->     <!-- w3-center is used to set the content           of the element to the center. -->     <div class="w3-container w3-center">          <!-- w3-text-green sets the text              color to green. -->         <!-- w3-xxlarge sets font size to 32px. -->         <h2 class="w3-text-green w3-xxlarge">            GeeksForGeeks         </h2>     </div>          <!-- Adding a table at the center of the page -->     <div class="w3-container w3-center">         <table class="w3-table">               <!-- Table Heading -->             <thead>                   <tr>                       <th>Sr. No.</th>                       <th>Name</th>                       <th>City</th>                       <th>Age</th>                   </tr>               </thead>                              <!-- Table Body or Content -->             <tbody>                   <tr>                       <th>1</th>                       <td>Ajay</td>                       <td>Patna</td>                       <td>20</td>                   </tr>                   <tr>                       <th>2</th>                       <td>Rahul</td>                       <td>Chandigarh</td>                       <td>17</td>                   </tr>                   <tr>                       <th>3</th>                       <td>Parush</td>                       <td>Kolkata</td>                       <td>22</td>                   </tr>               </tbody>           </table>     </div> </body> </html> 

 
 

Output:

Stripped rows: The .w3-stripped class is used to create an alternate dark and light rows. Use the combination of table, w3-table, and w3-stripped classes within the <table> tag to create a stripped table.


 

Syntax:
 

<table class="w3-table w3-stripped"> Table Contents... <table>

Example:

HTML
<!DOCTYPE html> <html> <head>     <!-- Title of the page -->     <title>GeeksForGeeks</title>      <!-- Adding W3.CSS file through external link -->     <link rel="stylesheet"            href="https://www.w3schools.com/w3css/4/w3.css">        </head> <body>     <!-- w3-container is used to add           16px padding to any HTML element.  -->     <!-- w3-center is used to set the          content of the element to the center. -->     <div class="w3-container w3-center">          <!-- w3-text-green sets the text color to green. -->         <!-- w3-xxlarge sets font size to 32px. -->         <h2 class="w3-text-green w3-xxlarge">             GeeksForGeeks         </h2>     </div>          <!-- Adding a table at the center of the page -->     <div class="w3-container w3-center">         <table class="w3-table w3-stripped">               <!-- Table Headings -->             <tr>                   <th>Sr. No.</th>                   <th>Name</th>                   <th>City</th>                   <th>Age</th>               </tr>                <!-- Table Content -->             <tr>                   <th>1</th>                   <td>Ajay</td>                   <td>Patna</td>                   <td>20</td>               </tr>               <tr>                   <th>2</th>                   <td>Rahul</td>                   <td>Chandigarh</td>                   <td>17</td>               </tr>               <tr>                   <th>3</th>                   <td>Parush</td>                   <td>Kolkata</td>                   <td>22</td>               </tr>           </table>     </div> </body> </html> 

 
 

Output:

Bordered Table: The .w3-border is used to add a border across the table. The border only occurs around the table and not in the table. The see this effect use .w3-border together with .w3-table in the table tag.


 

Syntax:

<table class="w3-table w3-border"> Table Contents... <table>

Example: 

HTML
<!DOCTYPE html> <html> <head>     <!-- Title of the page -->     <title>GeeksForGeeks</title>      <!-- Adding W3.CSS file through external link -->     <link rel="stylesheet"            href="https://www.w3schools.com/w3css/4/w3.css">        </head> <body>     <!-- w3-container is used to add 16px           padding to any HTML element.  -->     <!-- w3-center is used to set the           content of the element to the center. -->     <div class="w3-container w3-center">          <!-- w3-text-green sets the text color to green. -->         <!-- w3-xxlarge sets font size to 32px. -->         <h2 class="w3-text-green w3-xxlarge">GeeksForGeeks</h2>     </div>          <!-- Adding a table at the center of the page -->     <div class="w3-container w3-center">         <table class="w3-table w3-border">               <!-- Table Headings -->             <tr>                   <th>Sr. No.</th>                   <th>Name</th>                   <th>City</th>                   <th>Age</th>               </tr>                <!-- Table Content -->             <tr>                   <th>1</th>                   <td>Ajay</td>                   <td>Patna</td>                   <td>20</td>               </tr>               <tr>                   <th>2</th>                   <td>Rahul</td>                   <td>Chandigarh</td>                   <td>17</td>               </tr>               <tr>                   <th>3</th>                   <td>Parush</td>                   <td>Kolkata</td>                   <td>22</td>               </tr>           </table>     </div> </body> </html> 

 
 

Output:
 

If we want a completely bordered table we have to use .w3-bordered class along with .w3-border and w3-table inside the table tag.


 

Example:

HTML
<!DOCTYPE html> <html> <head>      <!-- Adding W3.CSS file through external link -->     <link rel="stylesheet"            href="https://www.w3schools.com/w3css/4/w3.css">        </head>  <body>     <!-- w3-container is used to add           16px padding to any HTML element.  -->     <!-- w3-center is used to set the           content of the element to the center. -->     <div class="w3-container w3-center">          <!-- w3-text-green sets the text color to green. -->         <!-- w3-xxlarge sets font size to 32px. -->         <h2 class="w3-text-green w3-xxlarge">             GeeksForGeeks         </h2>     </div>          <!-- Adding a table at the center of the page -->     <div class="w3-container w3-center">         <table class="w3-table w3-border w3-bordered">               <!-- Table Headings -->             <tr>                   <th>Sr. No.</th>                   <th>Name</th>                   <th>City</th>                   <th>Age</th>               </tr>                <!-- Table Content -->             <tr>                   <th>1</th>                   <td>Ajay</td>                   <td>Patna</td>                   <td>20</td>               </tr>               <tr>                   <th>2</th>                   <td>Rahul</td>                   <td>Chandigarh</td>                   <td>17</td>               </tr>               <tr>                   <th>3</th>                   <td>Parush</td>                   <td>Kolkata</td>                   <td>22</td>               </tr>           </table>     </div> </body> </html> 

 
 

Output:

Hoverable Table: The .w3-hoverable class is used to add a hover effect (change background color to gray when the mouse moves over) on table rows. Use the combination of w3-table and w3-hoverable classes within the <table> tag to create a hover rows table.


Syntax:

<table class="w3-table w3-hoverable"> Table Contents... <table>

Example:
 

HTML
<!DOCTYPE html> <html> <head>     <!-- Title of the page -->     <title>GeeksForGeeks</title>      <!-- Adding W3.CSS file through external link -->     <link rel="stylesheet"            href="https://www.w3schools.com/w3css/4/w3.css"> </head>  <body>     <!-- w3-container is used to add           16px padding to any HTML element.  -->     <!-- w3-center is used to set the           content of the element to the center. -->     <div class="w3-container w3-center">          <!-- w3-text-green sets the text color to green. -->         <!-- w3-xxlarge sets font size to 32px. -->         <h2 class="w3-text-green w3-xxlarge">GeeksForGeeks</h2>     </div>          <!-- Adding a table at the center of the page -->     <div class="w3-container w3-center">         <table class="w3-table w3-hoverable">               <!-- Table Headings -->             <tr>                   <th>Sr. No.</th>                   <th>Name</th>                   <th>City</th>                   <th>Age</th>               </tr>                <!-- Table Content -->             <tr>                   <th>1</th>                   <td>Ajay</td>                   <td>Patna</td>                   <td>20</td>               </tr>               <tr>                   <th>2</th>                   <td>Rahul</td>                   <td>Chandigarh</td>                   <td>17</td>               </tr>               <tr>                   <th>3</th>                   <td>Parush</td>                   <td>Kolkata</td>                   <td>22</td>               </tr>           </table>     </div> </body> </html> 

 
 

Output:


 

Centered Content Table: The .w3-centered class is used to place all the content of the table to the center. Use the combination of w3-table and w3-centered classes within the <table> tag to create this effect.


 

Syntax:

<table class="w3-table w3-centered"> Table Contents... <table>

Example:

HTML
<!DOCTYPE html> <html> <head>      <!-- Adding W3.CSS file through external link -->     <link rel="stylesheet"            href="https://www.w3schools.com/w3css/4/w3.css"> </head>  <body>     <!-- w3-container is used to add            16px padding to any HTML element.  -->     <!-- w3-center is used to set the           content of the element to the center. -->     <div class="w3-container w3-center">          <!-- w3-text-green sets the text color to green. -->         <!-- w3-xxlarge sets font size to 32px. -->         <h2 class="w3-text-green w3-xxlarge">GeeksForGeeks</h2>     </div>          <!-- Adding a table at the center of the page -->     <div class="w3-container w3-center">         <table class="w3-table w3-centered">               <!-- Table Headings -->             <tr>                   <th>Sr. No.</th>                   <th>Name</th>                   <th>City</th>                   <th>Age</th>               </tr>                <!-- Table Content -->             <tr>                   <th>1</th>                   <td>Ajay</td>                   <td>Patna</td>                   <td>20</td>               </tr>               <tr>                   <th>2</th>                   <td>Rahul</td>                   <td>Chandigarh</td>                   <td>17</td>               </tr>               <tr>                   <th>3</th>                   <td>Parush</td>                   <td>Kolkata</td>                   <td>22</td>               </tr>           </table>     </div> </body> </html> 

 
 

Output:

Now, if you want to select all the above effects all together on a table then you can use w3-table-all class. This class is used to select all the properties of the table i.e border, stripped, table,... You have to use this class with table tag to see the effect.


 

Example:

HTML
<!DOCTYPE html> <html> <head>      <!-- Adding W3.CSS file through external link -->     <link rel="stylesheet"            href="https://www.w3schools.com/w3css/4/w3.css"> </head>  <body>      <!-- w3-container is used to add            16px padding to any HTML element.  -->     <!-- w3-center is used to set the            content of the element to the center. -->     <div class="w3-container w3-center">          <!-- w3-text-green sets the text color to green. -->         <!-- w3-xxlarge sets font size to 32px. -->         <h2 class="w3-text-green w3-xxlarge">GeeksForGeeks</h2>     </div>          <!-- Adding a table at the center of the page -->     <div class="w3-container w3-center">         <table class="w3-table-all">               <!-- Table Headings -->             <tr>                   <th>Sr. No.</th>                   <th>Name</th>                   <th>City</th>                   <th>Age</th>               </tr>                <!-- Table Content -->             <tr>                   <th>1</th>                   <td>Ajay</td>                   <td>Patna</td>                   <td>20</td>               </tr>               <tr>                   <th>2</th>                   <td>Rahul</td>                   <td>Chandigarh</td>                   <td>17</td>               </tr>               <tr>                   <th>3</th>                   <td>Parush</td>                   <td>Kolkata</td>                   <td>22</td>               </tr>           </table>     </div> </body> </html> 

 
 

Output:


 


Next Article
W3.CSS Tags
author
aditya_taparia
Improve
Article Tags :
  • Technical Scripter
  • Web Technologies
  • HTML
  • CSS
  • W3.CSS

Similar Reads

  • CSS Tables
    CSS tables are used to style HTML tables, making them look neat and organized for clear data presentation. Add borders, spacing, and colors to enhance table design.Create responsive tables that adjust for all screen sizes.[GFGTABS] HTML <html> <head> <style> table { width: 50%; bor
    6 min read
  • W3.CSS Tags
    The .w3-tag is used to add additional information to the content. For example, some website highlights some sections to be new or when they have updated a section they add updated tag with that division so that user can see that they have updated to added new divisions on their site. This class when
    4 min read
  • W3.CSS Lists
    Lists are very useful in a webpage. It can be used a variety of content as they are flexible and easy to manage. We use .w3-ul class for the list. The default style for the list is borderless but we can use other classes to add a border and other effects to the list. Example: Adding a list on a webp
    5 min read
  • Pure CSS Tables
    Introduction: Before starting with Pure we must know the basics of plain CSS. Basically, Pure CSS is a Cascading Style Sheet framework developed by YAHOO. The main reason for developing Pure CSS is used to develop responsive and reactive websites like Bootstrap which is also compatible with mobile d
    5 min read
  • Primer CSS Tables
    Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by
    2 min read
  • CSS Examples
    CSS Examples showcase various styling techniques for HTML elements. They display properties, selectors, and functions that enhance design and creativity. This section offers categorized programming examples that cover properties, selectors, and functions. It provides multiple solutions for styling H
    2 min read
  • W3.CSS Margin
    W3.CSS has many facilities of classes to easily style elements in HTML. It includes various responsive margin classes for modification of the appearance of the element. The list of margin classes are as follows: Sr. No. Class Name Description 1. w3-margin It adds 16px of margin to all the sides of t
    2 min read
  • Foundation CSS Tables
    Foundation CSS is an open-source and responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing and can be accessible to any device. It is used by many companies such as Facebook, eBay, Moz
    5 min read
  • W3.CSS Padding
    W3.CSS has many facilities of classes to easily style elements in HTML. It includes various responsive padding classes for modification of the appearance of the element. There are two types of padding classes: Numbered Padding ClassesSized Padding Classes Numbered Padding Classes: These classes add
    3 min read
  • Tailwind CSS Table Layout
    This class accepts lots of value in tailwind CSS in which all the properties are covered in class form. By using this class we can set the display of the layout of the table. In CSS, we do that by using the CSS table-layout property. Table Layout classes: table-autotable-fixed table-auto: This class
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences