HTML oninvalid Event Attribute Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report The oninvalid event attribute works when input field values are invalid or empty. The script runs when a user clicks on the submit button. The required input field must be filled out before submitting it. It is basically triggered when a form element encounters invalid input and provides real-time feedback on incorrect form submissions.Syntax: <element oninvalid = "script">Attribute Value: This attribute contains a single value script which works when oninvalid attribute called. It is supported by all HTML elements.Example 1: In this example, we will see the implementation of the above event attribute. html <!DOCTYPE html> <html> <head> <title>oninvalid Event Attribute</title> <style> h1 { color:green; } body { text-align:center; } </style> </head> <body> <h1>GeeksForGeeks</h1> <h2>oninvalid Event Attribute</h2> <form action="#" method="post"> First Name : <input type = "text" oninvalid = alert('Please Fill all input field!') required><br><br> Last Name : <input type = "text" oninvalid = alert('Please Fill all input field!') required><br> <input type="submit" value="Submit"> </form> </body> </html> Output: Example 2: In this example, we will see the implementation of the above event attribute. HTML <!DOCTYPE html> <html> <head> <title>oninvalid Example</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin: 50px; } h1 { color: green; } form { max-width: 400px; margin: 18px auto; } input { width: 100%; padding: 10px; margin-bottom: 10px; box-sizing: border-box; } input[type="submit"] { background-color: crimson; color: #fff; cursor: pointer; } </style> </head> <body> <h1>GeeksforGeeks</h1> <form action="#" method="post"> <label for="firstName">First Name:</label> <input type="text" name="firstName" oninvalid="alert('Please fill in your first name!')" required> <label for="lastName">Last Name:</label> <input type="text" name="lastName" oninvalid="alert('Please fill in your last name!')" required> <input type="submit" value="Submit"> </form> </body> </html> Output:Supported Tags:<input>Supported Browsers: The browser supported by oninvalid event attribute are listed below: Google Chrome 10 and aboveEdge 12 and aboveFirefox 4 and aboveOpera 10 and aboveSafari Not supported Create Quiz Comment M manaschhabra2 Follow 1 Improve M manaschhabra2 Follow 1 Improve Article Tags : Web Technologies HTML HTML-Attributes Explore HTML BasicsHTML Introduction4 min readHTML Editors4 min readHTML Basics7 min readStructure & ElementsHTML Elements4 min readHTML Attributes7 min readHTML Headings3 min readHTML Paragraphs3 min readHTML Text Formatting4 min readHTML Block and Inline Elements3 min readHTML Charsets4 min readListsHTML Lists3 min readHTML Ordered Lists5 min readHTML Unordered Lists4 min readHTML Description Lists3 min readVisuals & MediaHTML Colors11 min readHTML Links Hyperlinks2 min readHTML Images7 min readHTML Favicon4 min readHTML Video4 min readLayouts & DesignsHTML Tables10 min readHTML Iframes4 min readHTML Layout4 min readHTML File Paths3 min readProjects & Advanced TopicsHTML Forms5 min readHTML5 Semantics5 min readHTML URL Encoding4 min readHTML Responsive Web Design11 min readTop 10 Projects For Beginners To Practice HTML and CSS Skills8 min readTutorial ReferencesHTML Tags - A to Z List15+ min readHTML Attributes Complete Reference8 min readHTML Global Attributes5 min readHTML5 Complete Reference8 min readHTML5 MathML Complete Reference3 min readHTML DOM Complete Reference15+ min readHTML DOM Audio/Video Complete Reference2 min readSVG Element Complete Reference5 min readSVG Attribute Complete Reference8 min readSVG Property Complete Reference7 min readHTML Canvas Complete Reference4 min read Like