:focus

noun

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

A pseudo-class that matches the element that has keyboard focus: the one the Tab key moved to, or the box someone clicked into, ready for typing or pressing Enter.

What does :focus do?

:focus applies styles to the element that has keyboard focus, like the text box you're typing in. Never remove it without a replacement: keyboard users rely on it.

input:focus { outline: 2px solid royalblue; }

In a sentence

  • “I gave the form's text boxes a thick blue outline with :focus, so you can always see which box you're typing in.”

Level: Apprentice · More CSS terms at this level

Updated