How to set custom error messages for your HTML forms @KevinPowell
How to set custom error messages for your HTML forms  @KevinPowell
Uploaded September 2025 | Updated September 2026, 2 weeks ago
The browser comes with native, client-side form validation that works quite well, but the errors have a few issues, from problems with internationalization, and no way to custom style them. Luckily, we can use the same API the browser uses under the hood to customize our errors quite easily!

πŸ”— Links
βœ… Frontend Mentor Project: frontendmentor.io/challenges/contact-form--G-hYlqKJj?via=kevinpowell
βœ… Starting & finished code: github.com/kevin-powell/fem-contact-form-validation
βœ… First video where I look at the styling: youtu.be/jJgNgNNHqjk
βœ… MDN article on the Constraint Validation API: developer.mozilla.org/en-US/docs/Web/HTML/Guides/Constraint_validation

βœ‰ Keep up to date with everything I'm up to kevinpowell.co/newsletter
πŸ’¬ Come hang out with other devs in my Discord Community discord.gg/nTYCvrK
⭐ Are you a beginner? HTML & CSS for absolute beginners is for you: learn.kevinpowell.co
πŸŽ“ Start writing CSS with confidence with CSS Demystified: [https://cssdemystified.com](https://cssdemystified.com/)
πŸš€ Already mastered CSS? Check out my advanced course, Beyond CSS: https://www.beyondcss.dev/

⌚ Timestamps
00:00 - Introduction
03:00 - Using novalidate and manually checking validation
09:30 - Checking all the form fields
15:00 - Adding error messages
17:30 - Removing the error elements when they are empty
18:52 - Styling for the error states
20:20 - aria-live=”polite”
22:00 - Custom text for each error message
25:25 - Adding the errors for the radio buttons
29:00 - Adding error messages when the user moves out of a form field
32:45 - Removing error messages when a user fixes the problem
34:00 - Adding focus to the first invalid element on submit
36:40 - Fixing the layout when error messages appear

#css

---

Help support my channel
πŸ‘¨β€πŸŽ“ Get a course: kevinpowell.co/courses
πŸ‘• Buy a shirt: cottonbureau.com/people/kevin-powell
πŸ’– Support me on Patreon: patreon.com/kevinpowell or through YT memberships: youtube.com/@KevinPowell/join

---

πŸ§‘β€πŸ’» My editor: VS Code - code.visualstudio.com

🌈 My theme: One Dark Pro Var Night
πŸ”€ My font: Cascadia Code

---

I'm on some other places on the internet too!

If you'd like a behind the scenes and previews of what's coming up on my YouTube channel:

Bluesky: https://bsky.app/profile/kevinpowell.co
Codepen: codepen.io/kevinpowell
Github: github.com/kevin-powell

---

And whatever you do, don't forget to keep on making your corner of the internet just a little bit more awesome!
How to set custom error messages for your HTML formsPositioning in CSS is too easy nowConnect four with CSS-only3 powerful CSS nesting tricksChallenging you to a CSS BattleCentering in CSS keeps getting easierOpen AI didnt allow AI in the interviewHow?!A deceptively complex form / HTML & CSS / Frontend MentorNew CSS features to know for 2025No more magic numbers with this modern CSS feature4 color variations from 1 variable super easily
Kevin Powell |

How to set custom error messages for your HTML forms

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER