CSS Tables CSS
- CSS Introduction
- CSS Selectors
- How To Add CSS
- CSS Colors
- CSS Backgrounds
- CSS Borders
- CSS Margins
- CSS Padding
- CSS Height and Width
- CSS Outline
- CSS Text
- CSS Fonts
- CSS Links
- CSS Lists
- CSS Tables
- CSS Layout - The display Property
- CSS Layout - CSS position
- CSS Layout - display: inline-block
- CSS Layout - Horizontal & Vertical Align
- CSS Combinators
- CSS Opacity / Transparency
- CSS Dropdowns
- Image Gallery
- CSS Attribute Selectors
- CSS Counters
- CSS Media Queries
CSS Tables
Table Borders
To specify table borders in CSS, use the border
property.
The example below specifies a black border for <table>, <th>, and <td> elements:
Firstname | Lastname |
---|---|
Deepak | Kumar |
Meenakshi | Nirman |
Notice that the table in the example above has double borders. This is because both the table and the <th> and <td> elements have separate borders.
Collapse Table Borders
The border-collapse
property sets whether the table borders should be collapsed into a single border:
Table Width and Height
Width and height of a table are defined by the width
and height
properties.
The example below sets the width of the table to 100%, and the height of the <th> elements to 50px:
Firstname | Lastname | Savings |
---|---|---|
Deepak | Chahar | $100 |
Meenakshi | Nirman | $150 |
Table Padding
To control the space between the border and the content in a table, use the padding
property on <td> and <th> elements:
Horizontal Dividers
Add the border-bottom
property to <th> and <td> for horizontal dividers:
Example
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
width: 100%;
}th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
</style>
</head>
<body><h2>Bordered Table Dividers</h2>
<p>Add the border-bottom property to th and td for horizontal dividers:</p><table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Savings</th>
</tr>
<tr>
<td>Deepak</td>
<td>Chahar</td>
<td>$100</td>
</tr>
<tr>
<td>Meenakshi</td>
<td>Nirman</td>
<td>$150</td>
</tr>
</table></body>
</html>