The Balai’s porch light is on while focus is inside the sign-in card: the browser answers which ancestors match :focus-within, what your CSS changed, and…
A form card that lights up, the active row, a clear button that shows while typing, a dropdown that stays open while focus is inside: all pure CSS. No listener to forget to clean up, and no flicker as focus moves between fields.
focus-within means me or one of my descendants has focus
focusin/focusout to highlight a form A listener + class toggle is easy to forget to clean up and flickers as focus moves between fields (focusout, then focusin). .kartu:focus-within gives the same result in pure CSS.:focus-within only touches one parent It matches every ancestor of the focused element, up to <html>. Two nested containers that both use it will both light up; pick the ancestor with your selector.:focus-within and :focus-visible Different jobs: :focus-visible = "does it need a focus indicator?" (keyboard vs mouse) on the element itself; :focus-within = "does a descendant have focus?". Combine them with :has(:focus-visible) when a parent should light up for keyboards only..cari:focus-within .hapus. Tab to it: it stays.:focus-within, but :focus-visible is true only via the keyboard.