CKTIS / CSS
Forms and controls in CSS
CSS defines the presentation of form controls and responds to their state through pseudo-classes. Preserve HTML semantics and visible focus; native control rendering can differ between browsers and operating systems.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
selector { property: value; }
input:focus-visible { outline: 3px solid #005fcc; }
input:checked + label { font-weight: 700; }Styling forms and controls means applying CSS rules to fields, buttons, and other interface elements. HTML defines their meaning and behavior, while CSS describes their presentation. Selectors can target a control type or its current state.
The :checked pseudo-class matches checked checkboxes and radio buttons, as well as selected options. :disabled matches disabled controls. :invalid matches a control that fails validation, for example because a constraint is not met or a custom validity error has been set. A custom validity error can make the control invalid even if its value meets all declared constraints. A form has no value of its own, but it matches :invalid if at least one associated element is a candidate for constraint validation and fails that validation. An associated fieldset is not a candidate for constraint validation. It can still match :invalid if it contains an invalid input owned by a different form. The fieldset matching :invalid does not by itself make its associated form match :invalid. CSS responds to these states; applying a style does not itself check, disable, or validate a field.
:focus identifies an element with focus. :focus-visible matches it when the browser determines that a focus indicator should be shown; it does not mean keyboard interaction exclusively. Do not remove an outline without providing a visible replacement. In the example, outline highlights focus, and input:checked + label makes the label immediately following the checked checkbox bold.
accent-color sets the accent used by controls that support it; the browser may adjust the color for legibility. Native appearance can limit the effect of some CSS properties. appearance: none removes native appearance, not control behavior—requiring you to recreate clear states and a focus indicator. The example deliberately retains the native checkbox; pixel-identical rendering across platforms is not expected.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Form controls</title>
<style>
body { font: 1rem sans-serif; padding: 1rem; }
input { accent-color: #005fcc; }
input:focus-visible {
outline: 3px solid #005fcc;
outline-offset: 3px;
}
input:checked + label { font-weight: 700; }
</style>
<input id="updates" type="checkbox">
<label for="updates">Updates</label>
</html>Result
Initially: an unchecked checkbox and the label Updates. When checked: the label becomes bold. Keyboard focus displays an outline when :focus-visible matches. Native checkbox rendering and accent color can vary by browser and platform.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.