Style forms and tables
W3C CSS Snapshot 2026
Use spacing and focus styles to make fields usable, and align table values for easy comparison.
On this page
Style fields and keep focus visible
Use font: inherit for controls to match surrounding text. Add padding for a comfortable target. :focus-visible lets keyboard users see which control is active.
How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Style fields and keep focus visible</title>
<style>
form { display: grid; gap: 8px; max-width: 300px; }
input, button { font: inherit; padding: 8px; border: 1px solid #497676; border-radius: 6px; }
button { background: #006767; color: white; }
:focus-visible { outline: 3px solid #a13a00; outline-offset: 2px; }
</style>
</head>
<body>
<form><label for="name">Order name</label><input id="name" name="name"><button type="button">Continue</button></form>
</body>
</html>
What to expect Click inside the preview, then use Tab to move between the field and button and see the outline.
Align prices and stripe table rows
border-collapse: collapse merges adjacent borders. tbody tr:nth-child(even) selects every second row in the table body. Right-align prices so their digits line up.
How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Align prices and stripe table rows</title>
<style>
table { width: 100%; max-width: 360px; border-collapse: collapse; }
th, td { padding: 8px; text-align: left; border-bottom: 1px solid #888; }
tr > :last-child { text-align: right; }
tbody tr:nth-child(even) { background: #def5f5; }
</style>
</head>
<body>
<table><caption>Product price list</caption>
<thead><tr><th scope="col">Product</th><th scope="col">Price (MMK)</th></tr></thead>
<tbody><tr><td>Pen</td><td>1,500</td></tr><tr><td>Desk Lamp</td><td>2,500</td></tr></tbody></table>
</body>
</html>
What to expect The second product row is colored and both prices line up at the right.