- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <td> Tag
HTML <td> tag is used to define the data cell of the table and used as a child element of <tr> element. The <td> tag may contain text, a form, an image, a table, etc.
By default, the content inside it is positioned to the left. There are exactly the same amount of cells in each row of the table as there are in the longest row. If there are less cells in a row, the browser will automatically fill the row, adding empty cells at the end of it.
Each data cell must be added as a separate <td> element for presenting tabular data in tables.
Syntax
<table> <tr> <td>..</td> <td>..</td> ... </tr> </table>
Attribute
Attribute | Value | Description |
---|---|---|
colspan | number | Specifies the number of columns. |
headers | header_id | Specifies one or more header cells a cell is related to. |
rowspan | number | Specifies the number of rows a cell should take. |
Examples of HTML td Tag
Bellow examples will illustrate the usage of td tag. Where, when and how to use td tag and how to style the table cell part of a table.
Creating a Simple Table
Let's consider the following example, where we are going to use the <td> tag.
<!DOCTYPE html> <html> <style> table, th, td { border: 2px solid #5DADE2; } </style> <body> <table> <tr> <td>1</td> <td>2</td> </tr> <tr> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> </tr> </table> </body> </html>
Set background-color on Table Cell
Considering another scenario where we are going to apply the background-color to the <td> tag.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.5px solid #A569BD; } </style> <body> <table> <tr> <th>Stundent</th> <th>Age</th> </tr> <tr> <td style="background-color:#BFC9CA">Ram</td> <td style="background-color:#F9E79F ">23</td> </tr> <tr> <td style="background-color:#BFC9CA ">Raju</td> <td style="background-color:#F9E79F ">22</td> </tr> </table> </body> </html>
Align Table Cell
In the following example, we are going to align the <td> tag to the center using the CSS.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.5px solid #DE3163; } </style> <body> <table style="width:100%"> <tr> <th>Cars</th> <th>Country</th> </tr> <tr> <td>Toyota</td> <td style="text-align:center">Japan</td> </tr> <tr> <td>Nissan</td> <td style="text-align:center">France</td> </tr> <tr> <td>Kia</td> <td style="text-align:center">South Korea</td> </tr> </table> </body> </html>
Setting Width of Table cell
Following is an example where we are going to adjust the width of a table cell using CSS.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.5px solid #8E44AD; } </style> <body> <table style="width:100%"> <tr> <th>Student</th> <th>Department</th> </tr> <tr> <td style="width:40%">Ram</td> <td style="width:60%">Information Technology</td> </tr> <tr> <td>Rahul</td> <td>Voice Process</td> </tr> <tr> <td>Maya</td> <td>Non-Voice Process</td> </tr> </table> </body> </html>
Supported Browsers
Tag | |||||
---|---|---|---|---|---|
tbody | Yes | Yes | Yes | Yes | Yes |