HTML Obsolete Attributes: CSS Migration
Move presentation into reusable rules
Legacy bgcolor and align attributes are not a modern way to style pages. Replace an old body bgcolor with background-color and an old paragraph align with text-align. Keep the original text and choose class names by purpose, so the theme can change without editing the content.
<style> body { background-color: #f0f9ff; } .intro { text-align: center; }</style><p class="intro">Welcome to the guide.</p>The body and paragraph receive their styles through CSS.
Migrate table appearance without changing relationships
Replace obsolete table attributes such as cellpadding and cellspacing with cell padding and border-spacing. Spacing between cells is effective with separate borders. Keep caption, th, scope, rowspan and colspan where they express actual table relationships; not every old attribute is obsolete.
<style> .data { border-collapse: separate; border-spacing: 4px; } .data th, .data td { padding: 8px; }</style><table class="data"> <caption>Stock</caption> <tr> <th scope="col">Item</th> <th scope="col">Count</th> </tr> <tr> <td>Books</td> <td>12</td> </tr></table>Cell spacing changes; header associations are retained.
Keep legitimate intrinsic dimensions
An old iframe frameborder attribute can be replaced with CSS border. In contrast, width and height on img remain conforming and can reserve aspect ratio space before decoding. Do not mechanically remove every presentational-looking attribute. Use CSS for responsive display sizing.
<style>.preview { border: 0; }</style><iframe class="preview" title="Reading preview" sandbox="" srcdoc="<p>Preview</p>"></iframe>The frame border is controlled by CSS.
Common mistakes and practice
Use the non-conforming features list in the HTML Standard to check each element-attribute pair. A property name can be valid in one context and invalid in another. Test computed styles, table headers and responsive layout, not just screenshot similarity. Avoid using inline style as a mechanical replacement across a large site; prefer shared rules.
The standard also distinguishes obsolete but conforming features from nonconforming ones. For example, style type="text/css" is obsolete but conforming and normally unnecessary; cellpadding on table is nonconforming. Review warnings and errors separately.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Obsolete Attributes: CSS Migration — Knowledge Check
Apply the legacy migration and compatibility concepts taught in this lesson.
Which CSS property replaces body bgcolor?
Which property replaces cellpadding?
Which property replaces cellspacing with separate borders?
Should scope on a table header be removed during migration?
Why retain valid img width and height?