Hacker News new | ask | show | jobs
by _2z1p 1103 days ago
Modern CSS and HTML's built in elements are better at a lot of the things people use JS for.

I think as coders we feel most comfortable reaching for JavaScript first, when really we should be doing as much in HTML itself as possible, then prettying it all up with CSS, and then finally adding some JS for interactivity such as client side form validation.

1 comments

Indeed, and even a lot of client side form validation can be done using HTML and CSS: https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_va...
It’s pretty limited, though, and has some random quirks. Like a required field will be marked as invalid immediately on load, or that it’s not really possible to display multiple errors on a single input.

You can work around them, but you’re approaching the complexity of just writing your own validator by that point.