×

CSS Table

CSS table provides better look and feel. There are various properties of CSS table that are given below.
  • border
  • border-collapse
  • padding
  • width
  • height
  • text-align
  • color
  • background-color

CSS Table Border

You can set the border of the table by using table tag th and td. Example
<!DOCTYPE>  
<html>    
<head>  
<style>    
table, th, td {    
    border: 1px solid black;    
}    
</style>    
</head>  
<body>    
<table>    
<tr><th>NAME</th><th>CLASS</th><th>ROLL NO</th></tr>    
<tr><td>Rahul</td><td>PHD</td><td>1</td></tr>    
<tr><td>James</td><td>MBBS</td><td>2</td></tr>    
<tr><td>Frank</td><td>MCA</td><td>3</td></tr>    
<tr><td>Jack</td><td>BCA</td><td>4</td></tr>    
</table>    
</body>  
</html>
Try Now

Collapse Table Borders

You can collapse the table border by using its property. Example
<!DOCTYPE html>  
<html>  
<head>  
<style>  
table {  
    border-collapse: collapse;  
}  
table, td, th {  
    border: 1px solid black;  
}  
</style>  
</head>  
<body>  
<h2> Example borders collapse</h2>  
<table>  
  <tr>  
    <th>Firstname</th>  
    <th>Lastname</th>  
    <th>Address</th>  
  </tr>      
  <tr>  
    <td>ABC</td>  
    <td>DEM</td>  
    <td>Noida</td>  
  </tr>  
  <tr>  
    <td>Lois</td>  
    <td>Griffin</td>  
   <td>Delhi</td>  
   </tr>  
</table>  
</body>  
</html>
Try Now

CSS Table Padding

You can specify the padding of table header and table data by using CSS padding property.
<!DOCTYPE>  
<html>    
<head>  
<style>    
table, th, td {    
    border: 1px solid black;    
    border-collapse: collapse;    
}    
th, td {  
    padding: 7px;  
}  
</style>    
</head>  
<body>    
<table>    
<tr><th>Product_Name</th><th>Price(rs)</th><th>Total_Product</th></tr>    
<tr><td>TV</td><td>35,000</td><td>60</td></tr>    
<tr><td>Computer</td><td>56.000</td><td>80</td></tr>    
<tr><td>Laptop</td><td>3,500</td><td>82</td></tr>    
<tr><td>Cooler</td><td>20,000</td><td>72</td></tr>    
</table>    
</body>  
</html>
Try Now

Responsive table

A responsive table is used to create responsive table. It will display horizontal scroll bar if the screen is too small. You should use only overflow-x: auto properties.
<!DOCTYPE html>  
<html>  
<head>  
<style>  
table {  
    border-collapse: collapse;  
    width: 100%;  
}  
th, td {  
    text-align: left;  
    padding: 8px;  
}  
tr:nth-child(even){background-color: #f2f2f2}  
</style>  
</head>  
<body>    
<div style="overflow-x:auto;">  
  <table>  
    <tr>  
      <th>Reg No</th>  
      <th>Fname</th>  
      <th>Lname</th>  
      <th>Address</th>  
      <th>Pin</th>  
    </tr>  
    <tr>  
       <td>1</td>  
       <td>Jill</td>  
       <td>Smith</td>  
       <td>Noida</td>  
      <td>50</td>  
    </tr>  
    <tr>  
    <td>2</td>  
      <td>Eve</td>  
      <td>Jackson</td>  
       <td>Delhi</td>  
      <td>94</td>  
   </tr>  
    <tr>  
     <td>3</td>  
      <td>Adam</td>  
      <td>Johnson</td>  
       <td>Patna</td>  
      <td>67</td>  
    </tr>  
  </table>  
</div>  
</body>  
</html>
Try Now

CSS Table Properties

Property Description
Border It is used to set the border properties in one declaration.
border-collapse It specifies whether table borders should be collapsed.
border-spacing It specifies the distance between the borders of adjacent cells.
Caption-side It specifies the placement of a table caption.
Empty-cells It specifies the borders and background on empty cells in a table.
Table-layout It is used to set the layout algorithm to be used for a table.

Related Topics

How to change the font in CSS

How to change the font in CSS? Professionals can't deny typefaces — how users organize and style text — if we want to completely customize the website's design. One may wish...

4 minutes read.

CSS calc()

CSS calc(): The CSS calc() function is a CSS function of inbuilt type, which permits us to implement calculations. It is used for calculating the angle, integer frequency, number, time,...

3 minutes read.

What is CSS

CSS stands for Cascading Style Sheet. It gives an additional style to the HTML document. A cascading style sheet is a language that is designed to define the document formatting...

3 minutes read.

CSS Width

CSS Width The width property in CSS sets the content width of area of the element. These properties do not provide margin and border features. It is used to set the...

1 minute read.

CSS Filter

CSS Filter CSS filter is used to apply visual effects on the images, text, and other factors of the webpage. This filter property in CSS allows us to admit the effects like...

7 minutes read.

CSS Font

CSS Font: CSS has font property, which makes the text more attractive. We can alter the entire look by changing font color, font size, font style, and much more. In...

5 minutes read.

How To Use CSS

You can use CSS(Cascading Style Sheet) in four ways. These are given below: The given above CSS type, in which various technique will be used. These are different from each other and...

2 minutes read.

CSS Important

CSS Important: CSS !important property is used to provide more importance, as compared to other CSS properties. The meaning of this property is “This is important.” This property enables CSS...

2 minutes read.

CSS Background-clip

CSS Background-clip: The background-clip property describes the background’s painting area. It limits an area where the image or color of the background appears by using any clipping box. Everything will...

2 minutes read.

CSS Display

CSS Display: The CSS Display property is one of an essential property among all other properties of CSS. The display property specifies how the HTML elements should be displayed on...

4 minutes read.

Grid Vs Flexbox in CSS

Grid: - CSS Grid Layout is a 2D grid-based matrix-based layout method with columns and rows that simplifies web pages created by eliminating the need for floats and placement. A grid layout, like...

4 minutes read.

CSS Table

CSS table provides better look and feel. There are various properties of CSS table that are given below. border border-collapse padding width height text-align color background-color CSS Table Border You can set...

4 minutes read.

CSS Tutorial

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

9 minutes read.

CSS Variables

CSS Variables These variables of CSS are applied to add the custom property values to our various web-pages. The custom properties are often called as CSS variables or cascading variables. Various...

4 minutes read.

CSS translate() Function

Translate() CSS function This function in CSS is a CSS in-built function. It relocates the element in the horizontal direction or in the vertical direction. It can move the items from...

2 minutes read.

How to center a button in CSS

How to center a button in CSS? In the tutorial, we will learn how to center a button in CSS. CSS (Cascading Style Sheets) gives an HTML web page the greatest possible...

4 minutes read.

CSS Float

CSS Float: The float property of CSS is the positioning property. This property is applied to elements to push them either to left or right. It permits for wrapping facility...

4 minutes read.

CSS @keyframes rule

CSS @keyframes rule It describes the rule of animation that depicts the properties of CSS for the components at every state along with the timeline. We may make the properties of complex...

4 minutes read.

CSS Opacity

The CSS Opacity property is used to set the clarity of the image. It is defined as degree and specify the transparency of an element. Note: Opacity value will be less...

1 minute read.

CSS Reference

The CSS Reference lists all of the basic standard CSS properties, pseudo-classes, pseudo-elements, and data types, for all intents and purposes functional notations, and at-rules alphabetically.  The site also includes...

5 minutes read.