- Home
- /
- Tutorials
- /
- CSS Tutorial
- /
- Modern Form Styling
CSS Accessibility
Modern Form Styling
Style native controls without discarding their states, platform behavior, or accessibility. The examples style inherited typography, borders, accent-color, validation, disabled controls, focus, autofill, and the risks of appearance: none.
Form controls come with a lot of built-in behavior: keyboard use, autofill, validation, screen reader support. Good form styling keeps all of that and changes the look, starting with two simple steps: inherit the page font, and set an accent color.
The basics of styling forms are in CSS Form Styling and CSS Input Fields. This lesson covers the newer tools.
Start here
Example
css
button,
input,
select,
textarea {
font: inherit;
color: inherit;
}
input,
select,
textarea {
border: 1px solid #94a3b8;
border-radius: 0.4rem;
padding: 0.65rem 0.75rem;
}
input[type="checkbox"] {
accent-color: #0f766e;
}By default, buttons and inputs do not use your page font; they use a small system font. font: inherit fixes that in one line. accent-color then recolors checkboxes, radio buttons, range sliders and progress bars to your brand color while keeping them fully native.
Style every state
Example
css
.field:has(:user-invalid) {
color: #991b1b;
}
input:disabled {
cursor: not-allowed;
opacity: 0.65;
}:user-invalid turns a field red only after the user has interacted with it, not the moment the page loads, which is what people expect. A disabled field gets a "not allowed" cursor and is faded.
Check every state, not just the resting look: hover, focus, disabled, read-only, checked, invalid, and the yellow or blue background browsers add when they autofill. A design that looks good only when empty is not finished.
Fields that grow with their content
Example
css
input,
textarea,
select {
field-sizing: content;
min-inline-size: 8rem;
max-inline-size: 100%;
}field-sizing: content makes a textarea grow as you type, and an input as wide as its text. Always give it a minimum and maximum, so an empty field is still visible and a long entry cannot break the layout. Not every browser supports it yet; where it is missing, fields keep their normal size.
Form Control Properties
| Property or selector | Purpose | Example |
|---|---|---|
| appearance | Controls platform-native control styling. | appearance: none |
| accent-color | Sets the accent used by supported controls. | accent-color: rebeccapurple |
| caret-color | Sets the insertion caret color. | caret-color: currentColor |
| :user-invalid | Targets an invalid control after user interaction. | input:user-invalid |
Complete Example
Complete runnable example
html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Modern Form Styling example</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 2rem;
font-family: system-ui, sans-serif;
line-height: 1.5;
}
main { max-width: 70rem; margin-inline: auto; }
article, section, aside, form, .card, .panel {
padding: 1rem;
border: 1px solid #cbd5e1;
border-radius: 0.6rem;
}
button,
input,
select,
textarea {
font: inherit;
color: inherit;
}
input,
select,
textarea {
border: 1px solid #94a3b8;
border-radius: 0.4rem;
padding: 0.65rem 0.75rem;
}
input[type="checkbox"] {
accent-color: #0f766e;
}
.field:has(:user-invalid) {
color: #991b1b;
}
input:disabled {
cursor: not-allowed;
opacity: 0.65;
}
input,
textarea,
select {
field-sizing: content;
min-inline-size: 8rem;
max-inline-size: 100%;
}
</style>
</head>
<body>
<main><form><label>Email <input type="email" required value="invalid"></label><label><input type="checkbox" checked> Subscribe</label><label>Topic <select><option>CSS</option><option>HTML</option></select></label><button>Submit</button></form></main>
</body>
</html>Browser Support
Feature | Chrome | Edge | Firefox | Safari |
|---|---|---|---|---|
| accent-color | 93 | 93 | 92 | 15.4 partial; 26.2 full |
| :user-invalid | 119 | 119 | 88 | 16.5 |
Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8. A partial-support note is included where it changes how the example behaves.
Good to know
appearance: noneremoves the native look completely. After that, you are responsible for every state, including focus and checked. Use it only when you really need a custom control, and test it thoroughly.- Keep real
<label>elements and error messages in the HTML. Placeholders and generated content are not a substitute.
Modern Form Styling exercises
Tint the checkbox
Color the checkbox teal with accent-color.
The HTML your code works on
<form>
<input class="check" type="checkbox">
<input class="field" type="text">
<select class="sel">
<option>A</option>
</select>
</form>Result
