Better Programming

Advice for programmers.

Follow publication

Member-only story

Advanced Form Validation With Only HTML and CSS

Mate Marschalko
Better Programming
Published in
19 min readJul 4, 2022

--

Photo by Sigmund on Unsplash

Last week we built an advanced input field that was interactive and animated and even included some self-validation and we used no JavaScript at all!

The focus was mainly on the mouse and keyboard interactions and styling depending on validation states. But we can do much more than that!

This time we are adding validation to and submitting a form with just CSS and HTML:

Input fields provided by the browser

Normal input fields with type="text", as their name correctly suggests, allow you to type in some text. We can further clarify what kind of text we are expecting by requiring a certain number of characters to be entered before the input can be valid and the form be submitted. This can be defined with the minlength and maxlength attributes. We can also use the required

--

--

Mate Marschalko
Mate Marschalko

Written by Mate Marschalko

Senior Creative Developer, Generative AI, Electronics with over 15 years experience | JavaScript, HTML, CSS

Write a response