HTML td

Content Within HTML <td> Elements

Adding Text Content to a Table Cell

To add text content to a table cell, use the <td> tag within a table row (<tr>).

Example:

<tr>
  <td>Sample Text</td>
</tr>

Adding Images to a Table Cell

To insert an image within a table cell, use the <img> tag inside the <td> tag.

Example:

<td><img src="image.jpg" alt="Description"></td>

Including Links and Buttons in a Table Cell

To include links, use the <a> tag, and for buttons, use the <button> tag within a <td> element.

Example:

<td><a href="https://example.com">Visit</a></td>
<td><button>Click Me</button></td>

What is an HTML <td> Tag?

The HTML <td> tag is part of the HTML table structure and defines a single cell within a table. It can contain various types of content like text, images, links, or even nested tables. The <td> tag can be styled using CSS properties.

Purpose of the HTML <td> Tag

The <td> tag is used to create cells in an HTML table, helping to organize and present tabular data in a structured format. The <td> tag supports attributes like colspan and rowspan to merge cells for flexible table design.

Basic Usage of HTML <td>

The <td> tag is placed within a <tr> tag to create individual cells in a table row. It can contain different HTML elements such as text, images, and links.

Example:

<table>
  <tr>
    <td>Cell 1</td>
    <td>Cell 2</td>
  </tr>
</table>

Syntax of the HTML <td> Tag

The basic syntax for the <td> tag involves placing it inside a <tr> tag to create table cells.

<tr>
  <td>Content</td>
</tr>

Attributes for the HTML <td> Tag

  • colspan: Merges cells horizontally.
  • rowspan: Merges cells vertically.
  • align: Aligns content horizontally.
  • valign: Aligns content vertically.
  • bgcolor: Sets the background color.

Example:

<td colspan="2" rowspan="2" align="center" valign="middle" bgcolor="lightblue">Merged Cell</td>

Styling HTML <td> Elements

You can style <td> elements using inline CSS or external stylesheets.

Example:

<td style="color: blue; font-weight: bold;">Styled Text</td>

By understanding and utilizing the <td> tag and its attributes, you can create well-structured and visually appealing tables in your web pages.

Create a free account to access the full topic

“It has all the necessary theory, lots of practice, and projects of different levels. I haven't skipped any of the 3000+ coding exercises.”
Andrei Maftei
Hyperskill Graduate