📊

How to Create Tables in HTML

HTML/CSSBeginner

Build structured data tables with proper HTML markup.

Code Example

HTML/CSS
<!DOCTYPE html>
<html>
<head>
  <style>
    body { font-family: sans-serif; padding: 20px; }
    table {
      border-collapse: collapse;
      width: 100%;
      max-width: 600px;
      margin: 20px auto;
    }
    th, td {
      border: 1px solid #ddd;
      padding: 12px;
      text-align: left;
    }
    th {
      background-color: #3b82f6;
      color: white;
    }
    tr:nth-child(even) {
      background-color: #f9fafb;
    }
    tr:hover {
      background-color: #f3f4f6;
    }
    caption {
      font-size: 1.2em;
      margin-bottom: 10px;
      font-weight: bold;
    }
  </style>
</head>
<body>
  <table>
    <caption>Employee Directory</caption>
    <thead>
      <tr>
        <th>Name</th>
        <th>Department</th>
        <th>Email</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Alice Johnson</td>
        <td>Engineering</td>
        <td>alice@example.com</td>
      </tr>
      <tr>
        <td>Bob Smith</td>
        <td>Marketing</td>
        <td>bob@example.com</td>
      </tr>
      <tr>
        <td>Charlie Brown</td>
        <td>Design</td>
        <td>charlie@example.com</td>
      </tr>
    </tbody>
  </table>
</body>
</html>

Explanation

HTML tables use <table>, <tr> (row), <th> (header), and <td> (data). Use <thead>, <tbody> for structure. CSS styles make tables readable.

Related Tutorials