Which of the following HTML5 codes will affect the horizontal as well as…

2018

Which of the following HTML5 codes will affect the horizontal as well as vertical alignment of the table content ?

  1. A.

    <td align=”middle” valign = center; vertical-align: middle;”>BASH</td>

  2. B.

    <td style=”horizontal-align: center; vertical-align: middle;”>BASH</td>

  3. C.

    <td style= “text-align: center; vertical-align: middle;”>BASH</td>

  4. D.

    <td halign=”middle” valign = “center”>BASH</td>

Attempted by 304 students.

Show answer & explanation

Correct answer: C

Solution:

The correct answer is Option C:

✔️ <td style="text-align: center; vertical-align: middle;">BASH</td>

Explanation:

In HTML5, presentation-related attributes like align and valign are deprecated. Instead, CSS is used to control the layout and alignment of content.

  • text-align: center; is a valid CSS property that controls the horizontal alignment of text or inline content inside the <td> element.

  • vertical-align: middle; is used to align the content vertically at the center within the table cell.

Together, these two properties ensure that the content (“BASH”) is centered both horizontally and vertically.

Why other options are incorrect:

  • Use of align, valign, or halign → deprecated or invalid in HTML5

  • Incorrect values like "middle" for align → invalid

  • Invalid CSS property like horizontal-align → does not exist

  • Mixing HTML attributes with CSS improperly → incorrect syntax

Conclusion:
Option C is correct because it follows modern HTML5 standards by using CSS within HTML to achieve both horizontal and vertical alignment in a standards-compliant way.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Tpsc Assistant Technical Officer