:focus-within

noun

say it: “FOH-kus with-IN” /ˈfoʊkəs wɪðˈɪn/ or “KOH-lun FOH-kus with-IN” /ˈkoʊlən ˈfoʊkəs wɪðˈɪn/

The CSS pseudo-class that matches an element while it, or anything inside it, has focus, such as a link someone has tabbed to. It lets a menu or a tooltip that opens on hover open for keyboard users too.

What does :focus-within do?

:focus-within matches an element while it or anything inside it has focus, such as a link someone has tabbed to. It lets a parent react to the keyboard: a menu that opens on hover can open for keyboard users too.

.find:hover .find-menu,
.find:focus-within .find-menu { display: block; }

In a sentence

  • “Thanks to focus-within, the menu stays open while I tab through its links.”
  • “Our dropdown only opened under the mouse until I added focus-within to its selector list.”

Level: Journeyman · More CSS terms at this level

Updated