Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
The <td> tag in HTML is used to define table data, representing a cell within a table row. It plays a crucial role in organizing and displaying data systematically on web pages.
This article will discuss the syntax, types of cells, attributes, and examples of the <td> tag, making it simple for beginners to create well-structured tables.
What is the `<td>` Tag?
The `<td>` tag is an HTML element used to create a standard data cell within a table. It stands for "table data" & is always nested inside a `<tr>` (table row) tag. Each `<td>` represents a single cell in a row, & the content inside it can be text, images, links, or even other HTML elements.
For example, if you’re creating a table to display student marks, each cell containing a student’s score would be defined using the `<td>` tag. For example:
In this code, the `<td>` tags are used to define the cells for student names & their marks. The `<tr>` tags create rows, & each row contains two `<td>` elements.
Note: The `<td>` tag is very useful for structuring data in a tabular format. Without it, tables wouldn’t be able to display information in an organized way. It’s a simple yet powerful tool that forms the foundation of HTML tables.
Syntax of <td> Tag
The <td> tag is used inside a <tr> tag (table row) and is a child of the <table> element. The basic syntax is:
3. align: Aligns the content horizontally. (Deprecated in HTML5; use CSS instead.)
<td align="center">Centered Text</td>
4. valign: Aligns the content vertically. (Deprecated in HTML5; use CSS instead.)
<td valign="top">Top Aligned Text</td>
5. `width` & `height`
These attributes define the width & height of the cell. However, it’s better to use CSS for styling purposes, as these attributes are deprecated in HTML5.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table with Specific Dimensions</title>
</head>
<body>
<table border="1">
<tr>
<td width="100" height="50">Cell with specific dimensions</td>
</tr>
</table>
</body>
</html>
The <td> tag is universally supported by all modern web browsers, including:
Browser
Support
Google Chrome
Yes
Firefox
Yes
Safari
Yes
Edge
Yes
Opera
Yes
There’s no compatibility issue with the <td> tag, making it reliable for web development.
Frequently Asked Questions
What is the difference between <td> and <th>?
<td> defines standard data cells, while <th> defines header cells. Header cells are bold and centered by default.
Can I style a <td> tag using CSS?
Yes, you can apply CSS styles to <td> using inline styles or external CSS files.
Is the <td> tag supported in all browsers?
Yes, all modern browsers support the <td> tag, ensuring compatibility across platforms.
Conclusion
In this article, we discussed the <td> tag, its syntax, and its features for defining table data in HTML. We also learned how to use its attributes, create various cell types, and saw practical examples of merging cells and styling them. The <td> tag is an essential tool for structuring data in web applications.