HTML - Working code for Tables in HTML

HTML - Working Code for Tables in HTML

HTML tables are one of the most essential components in web development. They allow developers to display structured data in a grid layout using rows and columns. Whether creating data reports, dashboards, invoices, pricing charts, comparison tables, or schedules, HTML tables are crucial for both beginners and advanced developers. In this detailed 1500+ word guide, we explore how to create functional HTML tables, table components, table styling, responsive table techniques, accessibility best practices, and multiple working code examples with outputs.

To improve search reach and impressions, this document includes SEO-friendly keywords such as HTML tables tutorial, working table code, table tags in HTML, creating rows and columns, HTML table formatting, responsive tables, table header, table borders, table styling, HTML table examples, table accessibility, rowspan, colspan, advanced table features.

Introduction to HTML Tables

HTML tables are created using the <table> element which contains multiple rows (<tr>) and cells that can be table headers (<th>) or data cells (<td>). Tables help organize information in a structured way and are widely used in admin dashboards, documentation pages, product listings, financial reports, and academic result sheets.

 Structure of an HTML Table

The basic structure includes:

  • <table> – container for the table
  • <tr> – defines a table row
  • <th> – defines a table header cell
  • <td> – defines a table data cell

 HTML Table


Name Age Country
John 28 USA
Maria 25 Canada

Output

Name Age Country
John 28 USA
Maria 25 Canada

Table Tags and Attributes

HTML provides many tags and attributes to improve table structure, readability, accessibility, and styling.

 HTML Table Tags

  • <thead> – groups header rows
  • <tbody> – groups body rows
  • <tfoot> – groups footer rows
  • <caption> – adds a title for the table
  • <colgroup> – applies formatting to columns
  • <col> – defines column properties

Using thead, tbody, tfoot


Employee Details
Name Department Salary
Alice IT $5000
Bob HR $4500
Data updated monthly

Output

Employee Details
Name Department Salary
Alice IT $5000
Bob HR $4500
Data updated monthly

Rowspan and Colspan in HTML Tables

colspan merges cells horizontally, while rowspan merges cells vertically. These properties help create complex layouts like calendars, schedules, and fee structures.

Using Colspan


Student Report
Name Marks Grade
Rohit 92 A+

Output

Student Report
Name Marks Grade
Rohit 92 A+

Using Rowspan


Product Price Quantity
$20 5

Output

Product Price Quantity
$20 5

 Table with Borders


Item Price
Pen $2

Output

Item Price
Pen $2

Example: Styled Table with CSS




ID Name Status
1 Arun Active
2 Neha Inactive

Output

ID Name Status
1 Arun Active
2 Neha Inactive

Responsive Tables in HTML

Responsive tables adjust to different screen sizes. On mobile screens, horizontal scrolling is commonly used.

Example: Responsive Table (Scrollable)


Product Category Price Stock
Laptop Electronics $600 20
Chair Furniture $80 50

Output

Product Category Price Stock
Laptop Electronics $600 20
Chair Furniture $80 50



HTML tables are powerful components that allow clear presentation of structured data. With support for rowspan, colspan, custom styling, accessibility improvements, and responsive techniques, tables play an important role in modern web design. Understanding how to build and style HTML tables correctly helps developers create dashboards, comparison charts, data grids, academic reports, pricing tables, and more. Mastering the table elements, attributes, and CSS styling covered in this document allows you to implement highly functional and visually appealing HTML tables for any project.

logo

HTML

Beginner 5 Hours

HTML - Working Code for Tables in HTML

HTML tables are one of the most essential components in web development. They allow developers to display structured data in a grid layout using rows and columns. Whether creating data reports, dashboards, invoices, pricing charts, comparison tables, or schedules, HTML tables are crucial for both beginners and advanced developers. In this detailed 1500+ word guide, we explore how to create functional HTML tables, table components, table styling, responsive table techniques, accessibility best practices, and multiple working code examples with outputs.

To improve search reach and impressions, this document includes SEO-friendly keywords such as HTML tables tutorial, working table code, table tags in HTML, creating rows and columns, HTML table formatting, responsive tables, table header, table borders, table styling, HTML table examples, table accessibility, rowspan, colspan, advanced table features.

Introduction to HTML Tables

HTML tables are created using the <table> element which contains multiple rows (<tr>) and cells that can be table headers (<th>) or data cells (<td>). Tables help organize information in a structured way and are widely used in admin dashboards, documentation pages, product listings, financial reports, and academic result sheets.

 Structure of an HTML Table

The basic structure includes:

  • <table> – container for the table
  • <tr> – defines a table row
  • <th> – defines a table header cell
  • <td> – defines a table data cell

 HTML Table

Name Age Country
John 28 USA
Maria 25 Canada

Output

Name Age Country
John 28 USA
Maria 25 Canada

Table Tags and Attributes

HTML provides many tags and attributes to improve table structure, readability, accessibility, and styling.

 HTML Table Tags

  • <thead> – groups header rows
  • <tbody> – groups body rows
  • <tfoot> – groups footer rows
  • <caption> – adds a title for the table
  • <colgroup> – applies formatting to columns
  • <col> – defines column properties

Using thead, tbody, tfoot

Employee Details
Name Department Salary
Alice IT $5000
Bob HR $4500
Data updated monthly

Output

Employee Details
Name Department Salary
Alice IT $5000
Bob HR $4500
Data updated monthly

Rowspan and Colspan in HTML Tables

colspan merges cells horizontally, while rowspan merges cells vertically. These properties help create complex layouts like calendars, schedules, and fee structures.

Using Colspan

Student Report
Name Marks Grade
Rohit 92 A+

Output

Student Report
Name Marks Grade
Rohit 92 A+

Using Rowspan

Product Price Quantity
$20 5

Output

Product Price Quantity
$20 5

 Table with Borders

Item Price
Pen $2

Output

Item Price
Pen $2

Example: Styled Table with CSS

ID Name Status
1 Arun Active
2 Neha Inactive

Output

ID Name Status
1 Arun Active
2 Neha Inactive

Responsive Tables in HTML

Responsive tables adjust to different screen sizes. On mobile screens, horizontal scrolling is commonly used.

Example: Responsive Table (Scrollable)

Product Category Price Stock
Laptop Electronics $600 20
Chair Furniture $80 50

Output

Product Category Price Stock
Laptop Electronics $600 20
Chair Furniture $80 50



HTML tables are powerful components that allow clear presentation of structured data. With support for rowspan, colspan, custom styling, accessibility improvements, and responsive techniques, tables play an important role in modern web design. Understanding how to build and style HTML tables correctly helps developers create dashboards, comparison charts, data grids, academic reports, pricing tables, and more. Mastering the table elements, attributes, and CSS styling covered in this document allows you to implement highly functional and visually appealing HTML tables for any project.

Frequently Asked Questions for HTML

  • HTML stands for HyperText Markup Language.
  • It is used to create the structure of web pages and web applications.
  • HTML defines elements such as headings, paragraphs, links, images, and other content.

  • Block-level elements (like <div>, <p>, <h1>) start on a new line and take full width.
  • Inline elements (like <span>, <a>, <strong>) stay within the flow of the text.
  • Understanding this helps with layout and styling.

  • A basic HTML page includes a <!DOCTYPE html> declaration, followed by <html>, <head>, and <body>.
  • The <head> section contains metadata like the title and links to stylesheets.
  • The <body> section contains all the visible content of the webpage.

  • The <meta> tag provides metadata such as page description, keywords, and author.
  • It helps browsers and search engines understand the content of the page.
  • One common use is specifying the character encoding: <meta charset="UTF-8">.

  • Forms collect user input using the <form> tag.
  • Inside a form, use <input>, <textarea>, <select>, and <button>.
  • The action attribute specifies where to send the form data.

  • The <label> tag defines a label for an input element.
  • It improves accessibility and allows users to click the label to focus the input.
    Example: <label for="email">Email:</label><input id="email">.

Comments in HTML are written between <!-- and -->.

Example:
<!-- This is a comment -->.
Comments are not displayed on the webpage and are used for documentation.

HTML entities are used to display reserved or special characters.

For example, &lt; displays < and &amp; displays &.
Use them to avoid confusion with actual HTML syntax.