Working code for Tables in HTML

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example of HTML Table</title>
    <style>
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            border: 1px solid black;
            padding: 8px;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
    <h1>HTML Table Example</h1>
    <table>
        <caption>Employee Contact Information</caption>
        <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Age</th>
        </tr>
        <tr>
            <td>Joy</td>
            <td>johndoe@example.com</td>
            <td>30</td>
        </tr>
        <tr>
            <td>Jane</td>
            <td>janedoe@example.com</td>
            <td>25</td>
        </tr>
    </table>
</body>
</html>

Explanation of the Code
HTML Structure: The <!DOCTYPE html> and <html> tags, with the language attribute set to English, are the conventional beginnings of the document.

Head Section:

  • Meta Tags: Viewport settings and character sets for responsive design are included.
  • Title Tag: Defines the webpage's title.
  • Style Tag: This tag has the very minimum of CSS to style the table. It guarantees that the table makes use of the whole width that is available, borders the cells to clearly demarcate them, and utilizes a background color to set the header apart.

Body Section:

  • header: A brief header that provides context for the table.

Table Structure:

  • Caption: Gives the table a title and improves accessibility by placing the shown data in context.
  • Table Rows (<tr>): Arrange the information in rows.
  • Header Cells (<th>): These cells are used to specify what data each column represents in the column headers.
  • Data Cells (<td>): Contains real data.

logo

HTML

Working code for Tables in HTML

Beginner 5 Hours

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example of HTML Table</title>
    <style>
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            border: 1px solid black;
            padding: 8px;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
    <h1>HTML Table Example</h1>
    <table>
        <caption>Employee Contact Information</caption>
        <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Age</th>
        </tr>
        <tr>
            <td>Joy</td>
            <td>johndoe@example.com</td>
            <td>30</td>
        </tr>
        <tr>
            <td>Jane</td>
            <td>janedoe@example.com</td>
            <td>25</td>
        </tr>
    </table>
</body>
</html>

Explanation of the Code
HTML Structure: The <!DOCTYPE html> and <html> tags, with the language attribute set to English, are the conventional beginnings of the document.

Head Section:

  • Meta Tags: Viewport settings and character sets for responsive design are included.
  • Title Tag: Defines the webpage's title.
  • Style Tag: This tag has the very minimum of CSS to style the table. It guarantees that the table makes use of the whole width that is available, borders the cells to clearly demarcate them, and utilizes a background color to set the header apart.

Body Section:

  • header: A brief header that provides context for the table.

Table Structure:

  • Caption: Gives the table a title and improves accessibility by placing the shown data in context.
  • Table Rows (<tr>): Arrange the information in rows.
  • Header Cells (<th>): These cells are used to specify what data each column represents in the column headers.
  • Data Cells (<td>): Contains real data.

Similar Data Science Tutorials

Related tutotials

Frequently Asked Questions for html

line

Copyrights © 2024 letsupdateskills All rights reserved