top of page
Writer's pictureWeb Coding

How to create a table

Today I will be teaching you how to create a simple table using only HTML and CSS


HTML

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Document</title>
 <link rel="stylesheet" href="style.css">
</head>
<body>
 <table>
 <tr>
 <th id="col1">Month</th>
 <th id="col2">Sales</th>
 <th>Expenses</th>
 <th>Net Income</th>
 <th>Tax</th>
 </tr>
 <tr>
 <td id="col1">Jan</td>
 <td id="col2">100,000</td>
 <td>50,000</td>
 <td>50,000</td>
 <td>10,000</td>
 </tr>
 <tr>
 <td id="col1">Feb</td>
 <td id="col2">150,000</td>
 <td>75,000</td>
 <td>75,000</td>
 <td>15,000</td>
 </tr>
 <tr>
 <td id="col1">Mar</td>
 <td id="col2">120,000</td>
 <td>60,000</td>
 <td>60,000</td>
 <td>12,000</td>
 </tr>
 <tr>
 <td id="col1">April</td>
 <td id="col2"> 20,000</td>
 <td>20,000</td>
 <td>0</td>
 <td>0</td>
 </tr>

 </table>
</body>
</html>

CSS

body{
 min-height100vh;
 displayflex;
 align-itemscenter;
 justify-contentcenter;
 background-color#222;
}

table{
 background-color#e3e3e3;
 border-collapsecollapse;
 width55%;
 text-aligncenter;
}

thtd{
 border-bottom1px solid black;
}

th{
 height50px;
 background-color#c60021;
 font-size24px;
}

td{
 height40px;
 font-size20px;
}

tr:nth-child(odd){
 background-color#a6a6a6;
}

tr:hover{
 background-colorrgba(0000.5);
}

If you found this blog post helpful don’t forget to check out my other projects and if you want more content follow me on


YouTube: https://www.youtube.com/channel/UC2nxqB2usQIS2c8zwVZKWEQ

Instagram: https://www.instagram.com/coding_for_the_web/

Twitter: https://twitter.com/LearnWebCoding


5 views

Comments


bottom of page