5.3 Formatting a Data Table: Borders, Alignment, and Padding

In this section, we’ll describe how to format data tables in terms of their borders, cell alignment, and cell padding. Before HTML5, older versions of HTML allowed you to specify those presentation features using HTML attributes. But in sticking to its goal of keeping content and presentation separate, HTML5 has made those attributes obsolete. The solution? As usual, you should use CSS for presentation.

To specify whether or not you want borders for a table, you should use CSS’s border-style property. To specify the border’s width, you should use CSS’s border-width property. For example, here’s the CSS type selector rule used in the Wind Disasters web page:

table, th, td {border: ...

Get Web Programming with HTML5, CSS, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.