CSS Forms and Focus States
Basic form styles
label { display: block; margin-bottom: .4rem; font-weight: 600; }
input, select, textarea {
width: 100%;
padding: .7rem .8rem;
border: 1px solid #94a3b8;
border-radius: 8px;
font: inherit;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
outline: 3px solid #93c5fd;
outline-offset: 2px;
}
Associate each control with a visible label. Do not rely on placeholder text as the only label.
Validation states
input:invalid:not(:placeholder-shown) { border-color: #dc2626; }
input:disabled { background: #e2e8f0; cursor: not-allowed; }
Practice
Build a labeled sign-up form and test it with keyboard-only navigation.
Want to learn this professionally?
Explore practical IT training at Cyber Code Academy.
View Academy Courses