Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

:user-valid — a valid field after user interaction

The :user-valid pseudo-class selects valid form controls only once the user-interaction condition is met. Unlike :valid, it does not automatically signal that an untouched field is valid.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

input:user-valid { /* declarations */ }

:user-valid is a pseudo-class without arguments. In HTML it matches input, textarea, and select elements that are candidates for constraint validation, satisfy their constraints, and have their internal user validity state set to true.

:valid describes validity without that additional condition. A field with a valid initial value can therefore match :valid but not :user-valid. Its counterpart :user-invalid indicates invalidity after the interaction condition is met; not matching it does not imply matching :user-valid.

Do not assume that merely focusing a control or assigning .value activates this state. The precise timing during editing can depend on the browser. Attempting form submission provides a clear checkpoint, while resetting clears the interaction state.

The example starts with the valid value Ada. Press Submit without editing, then Reset. The script prevents navigation, not validation. Text beside the field supplements the border color; the selector only styles a state and does not validate data on the server.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>:user-valid demo</title>
<style>
  input { border: 2px solid #666; padding: 0.4rem; }
  input:user-valid { border-color: #087a35; }
  .status::after { content: "Not user-valid"; }
  input:user-valid + .status::after { content: "User-valid"; }
</style>
<form id="demo">
  <label for="name">Name (required)</label>
  <input id="name" name="name" required value="Ada">
  <span class="status" aria-live="polite"></span>
  <button type="submit">Submit</button>
  <button type="reset">Reset</button>
</form>
<script>
  document.querySelector('#demo').addEventListener('submit', (event) => {
    event.preventDefault();
  });
</script>
</html>

Result

Initially: Not user-valid; gray border.
After Submit without editing: User-valid; green border.
After Reset: Not user-valid; gray border.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources