pseudo-class

:focus-within — CSS reference

Matches an element when it or a descendant has focus, including applicable shadow-tree descendants. Useful for indicating the active form group.

Formal Syntax & Structure

css syntaxcss
:focus-within

Working Example

Example Snippetcss
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Selector lab</title><style>:where(.sample) { color: rgb(32, 32, 32); }div:focus-within { color: rgb(0, 96, 80); }</style></head><body><div id="a" class="sample"><label>A <input id="field"></label></div><div id="b" class="sample"><label>B <input></label></div></body></html>
CSS Reference