Which of the following HTML code will affect the vertical alignment of the…
2017
Which of the following HTML code will affect the vertical alignment of the table content?
- A. <td style="vertical-align:middle"> Text Here </td>
- B. <td valign="centre"> Text Here </td>
- C. <td style="text-align:center"> Text Here </td>
- D. <td align="middle"> Text Here </td>
Attempted by 348 students.
Show answer & explanation
Correct answer: A
Correct approach: Use CSS vertical-align or the historical valign attribute (deprecated) to control vertical alignment of table cell content.
Example that correctly affects vertical alignment: <td style="vertical-align:middle"> Text Here </td> — This uses CSS and vertically centers the cell content. This is the recommended modern method.
Legacy attribute note: <td valign="centre"> Text Here </td> — This attempts to use the deprecated valign attribute, but the value 'centre' is invalid. If written as valign="middle" (or valign="top"/"bottom"), older browsers would adjust vertical alignment, but the attribute is deprecated in HTML5.
Horizontal alignment vs vertical: <td style="text-align:center"> Text Here </td> centers content horizontally, not vertically.
Incorrect use of align attribute: <td align="middle"> Text Here </td> tries to use an attribute for horizontal alignment; 'middle' is not the standard value (use 'center'). The align attribute is deprecated; use CSS instead.
Conclusion: The CSS example using vertical-align (for example, <td style="vertical-align:middle">) correctly affects vertical alignment and is the preferred solution today. The valign attribute with a correct value like 'middle' would work in older HTML but is deprecated.