Most demos need a newer browser

They use :has() and container queries. Update your browser, or on an iPhone update iOS to 16.4 or later.

CSS Form Examples

Forms are where a page stops being a document and starts being a tool, and they are also where most people reach for JavaScript first. Much of that reaching is unnecessary. A checkbox already holds a boolean. A radio group already holds one choice out of several. The :checked pseudo-class reads that state back out, and the sibling combinators let anything else in the same container respond to it.

What follows are the controls a real form needs, each one built on that idea. Every example is a working control rather than a picture of one, so it can be reached with the keyboard and announced by a screen reader. Where a technique has an accessibility cost, the example page says so instead of hiding it.

No examples match these filters yet. Turn on another level or pick another category.

Type, paste or delete in the headline

Your browser can't run this demo

It needs :has(), color-mix(), trigonometric functions and field-sizing, which this browser doesn't support yet. It works in Chrome 123+, Edge 123+, Firefox 152+ and Safari 26.2+.

Needs :has(), color-mix(), trigonometric functions and field-sizing

Up to 30 characters

Character Counter

Advanced

Count typed characters in a monospace field with container query units reading the field's width.

The digits roll when the plan changes

Your browser can't run this demo

It needs :has() and the lh unit, which this browser doesn't support yet. It works in Chrome 109+, Edge 109+, Firefox 121+ and Safari 16.4+.

Needs :has() and the lh unit

$29 a month

$14 a month, billed yearly

Rolling Price Toggle

Advanced

Digits roll like a slot machine when the plan changes, using lh units and :has() for no-script price switching.

Type in either field

Min 2 characters Max 40
Min 20 characters Max 160

Character Count Indicator

Intermediate

Input border changes color based on validity using :user-invalid and :user-valid with minlength/maxlength.

Two swatch groups

Pick a color

Product variant

Color Swatch Picker

Beginner

Radio buttons styled as color circles with a :checked ring indicator, and no JavaScript.

Number field and stepper row

Your browser can't run this demo

It needs :has(), which this browser doesn't support yet. It works in Chrome 105+, Edge 105+, Firefox 121+ and Safari 15.4+.

Needs :has()

B. Radio buttons, 0 to 10

A restyles the browser's own arrows through ::-webkit-inner-spin-button. It works for any range and allows typing. B uses radio buttons with minus and plus labels for a fixed range of 0 to 10. It renders consistently across browsers and dims the end buttons, but typing is not allowed.

Number Input Stepper

Beginner

Two script-free steppers: a number field with the browser's own arrows restyled, or radio buttons with minus and plus labels.

Two styled date fields

Styled Date Input

Beginner

Custom styling for <input type="date"> including the calendar icon via CSS pseudo-elements.

Two styled selects

Styled Select Dropdown

Beginner

Custom <select> appearance using appearance:none and an inline SVG background arrow.

Move between steps

1. Your Info 2. Details 3. Done

Your Info

Details

All done!

✓ Form submitted, zero JavaScript used!

Multi-Step Form

Intermediate

Radio inputs control which step panel is visible, with no JavaScript and no page reload.

Type in a field and tab away

Enter a valid email address
At least 3 characters required

CSS Input Validation

Intermediate

Real-time form validation feedback using :valid, :invalid, and :user-invalid.

Styled track and thumb

Your browser can't run this demo

It needs :has(), round() and scroll-driven animations, which this browser doesn't support yet. It works in Chrome 125+, Edge 125+, Firefox 159+ and Safari 26+.

Needs :has(), round() and scroll-driven animations

Styled Range Slider

Intermediate

A custom-styled range input using CSS track and thumb pseudo-elements.

Styled radio group

Custom Radio Buttons

Beginner

Styled radio buttons without any images or JavaScript.

Styled checkbox with a drawn check mark

Custom Checkboxes

Beginner

Fully styled checkboxes using appearance:none and :checked.

Click a star to rate

Star Rating

Intermediate

Clickable star rating using radio inputs and the general sibling combinator.

Label floats on focus and on input

Floating Labels

Intermediate

Form labels that float above the input on focus using :placeholder-shown.

Switch driven by a checkbox

Toggle Switch

Intermediate

A styled on/off toggle built with a checkbox and CSS.