- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- 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 - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- 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 Code Builder
- HTML References
- 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
In an HTML table, the <td> tag designates a common data cell. It must be used as a child element of <tr>, which designates a table row. The <th> tag is used to define a header cell. 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
Following is the syntax for HTML <td> −
<table> <tr> <td> ...... </td> </tr> </table>
Example
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>
On running the above code, the output window will pop up, displaying the table on the webpage.
Example
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>
When we execute the above code, it will generate an output consisting of the table along with a background color added to the data that comes under the <td> tag displayed on the webpage.
Example
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>
On running the above code, the output window will pop up, displaying the data that comes under the <td> tag displayed at the center inside the table.
Example
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>
When we execute the above code, it will generate an output consisting of the table of different width displayed on the webpage.
To Continue Learning Please Login
Login with Google