CSS chapters

Chapter 15 of 17

Focus, hover and form states

Try this in our CSS Compiler →

The idea

CSS styles interaction states but does not receive process stdin or validate a server request. :focus-visible highlights keyboard focus, :hover responds to a pointing device, and :invalid reflects native form constraints. Never remove focus outlines without an accessible replacement.

Worked example

input:focus-visible, button:focus-visible { outline: 3px solid teal; outline-offset: 3px; }
input:invalid { border: 2px solid crimson; }

What to check

A hover effect alone is insufficient for keyboard navigation. Invalid styling does not explain the error, so pair it with readable instructions in HTML.

Practice task

Tab through a small form and button. Make every focused control visible without using the mouse.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on