CSS table padding
CSS Tutorial » CSS table padding
In this chapter we show you:How do you add padding to a table in CSS?
Can I add padding to table?
How do you set a table padding?
CSS tables padding can adjust dimensions inside the cells. If cell padding property is not apply then it will be set as default value. The cell padding is used to define the spaces between the cells and its border.
We can add padding CSS Style as:Inline - by using the style attribute in HTML elements
Internal - by using a <style> element in the <head> section
External - by using an external CSS Style file as style.css
Inline CSS and HTML Syntax:
Internal CSS and HTML Syntax:
<style>
th, td { padding: value; }
</style>
<body>
<table>
<tr>
<th>title_text</th> <!-- each line one column -->
...
...
...
</tr>
<tr>
<td>content</td> <!-- each line one column -->
...
...
...
</tr>
</table>
</body>
<html>
By using an external CSS Style file as style.css where we add CSS Style .selector_name { property: value; }
External CSS and HTML Syntax:
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<table>
<tr>
<th>title_text</th> <!-- each line one column -->
...
...
...
</tr>
<tr>
<td>content</td> <!-- each line one column -->
...
...
...
</tr>
</table>
</body>
<html>
How do you add padding to a table in CSS?
ID | Nombre | Apellido | |
---|---|---|---|
1 | Clark | Kent | clarkkent@mail.com |
2 | John | Carter | johncarter@mail.com |
3 | Peter | Parker | peterparker@mail.com |
Browser Support CSS cell padding
Element | ![]() Chrome |
![]() IE |
![]() Firefox |
![]() Opera |
![]() Safari |
Browser Support option | Yes | Yes | Yes | Yes | Yes |
CSS table cell padding
Cell padding is the space between content and the cell edges.
By default the cell padding is set to 0 value.
To add padding on table cells, we use CSS padding property:
For a better understanding we present an example:
<!DOCTYPE html>
<html>
<head><title>Cell padding</title>
<style>
.tr_head1{background:#0C6; padding:8px}
.tr_head2{border:thin #FFF; background: #CCC}
.tr_line{padding:8px;}
</style>
</head>
<body>
<h1>Cell padding</h1>
<table align="center" style="width:99%">
<thead>
<tr class="tr_head1">
<th class=" tr_line">ID</th>
<th class=" tr_line">Nombre</th>
<th class=" tr_line">Apellido</th>
<th class=" tr_line">Email</th>
</tr>
</thead>
<tbody>
<tr class="tr_head2 ">
<td class=" tr_line">1</td>
<td class=" tr_line">Clark</td>
<td class=" tr_line">Kent</td>
<td class=" tr_line">clarkkent@mail.com</td>
</tr>
<tr>
<td class=" tr_line">2</td>
<td class=" tr_line">John</td>
<td class=" tr_line">Carter</td>
<td class=" tr_line">johncarter@mail.com</td>
</tr>
<tr class="tr_head2">>
<td class=" tr_line">3</td>
<td class=" tr_line">Peter</td>
<td class=" tr_line">Parker</td>
<td class=" tr_line">peterparker@mail.com</td>
</tr>
</tbody>
</table>
</body>
</html>
Related subjects:
CSS table
CSS table border
Padding top bottom left right
CSS table padding border
Can you add padding to a border in CSS?
No, that's not possible. Padding, margin and border are all parts of elements, you can't give a border padding or a margin a border.
How do you add padding to a table in CSS?
Cell padding is the space between content and cell borders. To set cell padding in HTML, use the style attribute.
How to Remove Spacing Between Table Borders with CSS
When you use CSS to put a border on your <th> and <td> tags, you will notice that you get space between them. In the old days, you would remove that space using the now-deprecated cellspacing attribute.
<!DOCTYPE html>
<html>
<head><title>Cell padding</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
.tr_head1{background:#0C6; padding:15px}
.tr_head2{border:thin #FFF; background: #CCC}
.tr_line{padding:15px;}
</style>
</head>
<body>
<h1>Cell padding and border</h1>
<table align="center" style="width:99%">
<thead>
<tr class="tr_head1">
<th class=" tr_line">ID</th>
<th class=" tr_line">Nombre</th>
<th class=" tr_line">Apellido</th>
<th class=" tr_line">Email</th>
</tr>
</thead>
<tbody>
<tr class="tr_head2 ">
<td class=" tr_line">1</td>
<td class=" tr_line">Clark</td>
<td class=" tr_line">Kent</td>
<td class=" tr_line">clarkkent@mail.com</td>
</tr>
<tr>
<td class=" tr_line">2</td>
<td class=" tr_line">John</td>
<td class=" tr_line">Carter</td>
<td class=" tr_line">johncarter@mail.com</td>
</tr>
<tr class="tr_head2">>
<td class=" tr_line">3</td>
<td class=" tr_line">Peter</td>
<td class=" tr_line">Parker</td>
<td class=" tr_line">peterparker@mail.com</td>
</tr>
</tbody>
</table>
</body>
</html>
TAGS:css table padding between rows, betweens columns, left, spacing, outside, border, margin, not working, bottom, between cells
css table padding between columns, betwwen rows, not working, cellpadding, cellc spacinf and cell padding
CSS table spacing between rows
How to Add Space Between Rows in the Table
The space between two rows in a table can be done using CSS border-spacing and border-collapse property.
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
}
th {
background-color:blue;
Color:white;
}
th, td {
width:150px;
text-align:center;
border:1px solid red;
padding:5px
}
.border_my_table {
border-right:hidden;
}
.Border_tab {
border-collapse:separate;
border-spacing:0 15px;
}
h2 {
color:blue;
}
</style>
</head>
<body>
<center>
<h2>CSS and HTML table spacing between rows</h2>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Gender</th>
<th>Age</th>
</tr>
</table>
<table class = "Border_tab">
<tr>
<td class = "border_my_table">a1</td>
<td>NickM</td>
<td>M</td>
<td>29</td>
</tr>
<tr>
<td class = "border_my_table">a2</td>
<td>SandyB</td>
<td>F</td>
<td>31</td>
</tr>
<tr>
<td class = "border_my_table">a3</td>
<td>StwartW</td>
<td>M</td>
<td>28</td>
</tr>
</table>
</center>
</body>
</html>
css table padding between columns, betwwen rows, not working, cellpadding, cellc spacinf and cell padding
CSS table padding - css tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.