Forms & Pseudo-classes: Focus, Invalid, Required, Helper Text

intermediate
By FrontendAtlas Editorial · Updated Oct 5, 2026
Style form fields using :focus, :invalid, and :required to guide users. Show clear focus rings, error borders, and helper text without causing layout shifts, and make sure states are accessible (color contrast, focus visibility).

Solution idea

Use :focus-visible (with a :focus fallback) to show an outline ring, :invalid to indicate errors, ::placeholder for lighter hint text, and :focus-within on the label to highlight the label+input group. The solution also applies nicer visual styling so it looks clearly different from the starter.