I've just discovered <center>
is obsolete in HTML5, but it works fine in IE9 with <!DOCTYPE html>
:
http://www.w3.org/TR/html5/obsolete.html#obsolete
The alternative is to use CSS text-align, but I get conflicting results:
<body>
<table style="text-align:center">
<tr>
<th>Column</th>
</tr>
<tr>
<td>Data</td>
</tr>
</table>
<p style="text-align:center">Text</p>
</body>
Any suggestions on how to center both the table
content and the p
content within the page? (I can't see what's so bad with <center>
anyway).
If it isnt in the spec, or is marked obsolete then how it is interpreted and whether it is supported becomes increasingly up to the vendor.
As of Oct 28th 2014
center
appears underYou may being using
center
now and it 'works', but in the next version of your browser, all support may be droppped, leaving you with a page that doesnt render as intended.text-align:center
will center your text, in exactly the same way. However any additional styling applied to thecenter
element by browsers (each has a default set of CSS styles often derived from the w3c recommendation) will not be present.The conflicting results you note arent due to the use of
center
vstext-align
they are because the text is being aligned within elements of varying widths. If you set the width of your table to100%
, the alignments will be similar.