Tailwind CSS
/Beginner
Focus State
Definition
A state variant (`focus:`) that applies a utility class ONLY when the element is currently selected/active (e.g., clicking into a text input, or tabbing to a button via keyboard).
Explain Like I'm New
When you click inside an email `<input>`, the border should turn blue so you know you are actively typing in it. This is crucial for users who navigate websites using the 'Tab' key instead of a mouse.
Real World Example
Changing an input field from `border-gray-300` to `border-brand-500` the moment the user clicks into it to start typing.
Common Use Cases
- •Forms
- •Accessibility
- •Keyboard navigation
Interactive Example
Interview Questions
basic
- What prefix is used to change the background color of an input field when the user clicks into it?
intermediate
- What is `focus-visible:` and why is it sometimes better than `focus:`?