Example 1 — Field Wrapper
Focusing the input causes its parent field wrapper to match.
<style>
.field:focus-within {
border-color: #2563eb;
background: #eff6ff;
}
</style>
<div class="field"><label>Name <input type="text"></label></div> How It Works
- The browser evaluates
.field:focus-withinagainst the document. - Only elements satisfying that selector receive the declarations.
- The rule changes the visible state without changing the HTML structure.
- Open the editor to test the selector with different markup.

