Computer >> Computer tutorials >  >> Programming >> HTML

How do we display a table cell in HTML


e the <td> tag to display a table cell. The HTML <td> tag is used for specifying a cell or table data within a table.

It supports the following attributes −

Attribute
Value
Description
abbr
abbreviated_textDeprecated− Specifies an abbreviated version of the content in a cell.
align
right left center justify charDeprecated − Visual alignment.
axis
nameDeprecated− Specifies a category for this td. This can potentially be used to perform queries against the table data and can be beneficial in the context of a speech browser
bgcolor
rgb(x,x,x) #hexcode colornameDeprecated− Specifies the background color of the table cell.
char
characterDeprecated − Specifies which character to align text on. Used when align = "char"
charoff
pixels or %Deprecated − Specifies an alignment offset (either in pixels or percentage value) against the first character as specified with the char attribute. Used when align = "char"
colspan
numberSpecifies the number of columns the current cell spans across.
header
idSpecifies a space-separated list of header cells that contain information about this cell. The value needs to correspond with the id of the header cell (which is set using the id attribute). This attribute is useful for non-visual browsers.
height
pixelsDeprecated − Specifies the height of the table cell.
nowrap
nowrapDeprecated − Prevents text from automatically wrapping.
rowspan
numbersSpecifies the number of rows the current cell spans across.
scope
col colgroup row rowgroupDeprecated − This attribute is used on header cells and specifies the cells that will use this header's information.
valign
top middle bottom baselineDeprecated − Vertical alignment.
widthpixels or %Deprecated − Specifies the width of the table cell

Example

You can try to run the following code to display a table cell in HTML −

<!DOCTYPE html>
<html>
   <head>
      <style>
         table, th, td {
            border: 1px solid black;
         }
      </style>
   </head>
   <body>
      <h3>Result</h3>
      <table>
         <th>Marks</th>
         <th>Student</th>
         <tr>
            <td>600</td>
            <td>Amit</td>
         </tr>
         <tr>
            <td>400</td>
            <td>Anil</td>
         </tr>
      </table>
   </body>
</html>