HTML Event Attributes Reference Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report HTML event attributes are used to define actions that should occur when specific events are triggered on a webpage.They enable interaction between the user and the system, like clicking a button or resizing a window.Event attributes are added to HTML elements to specify the event type and action.They enhance dynamic behavior and improve user experience on a webpage. HTML <html> <head> <script> function displayMessage() { alert("Button was clicked!"); } </script> </head> <body> <button onclick="displayMessage()">Click Me!</button> </body> </html> <button onclick="displayMessage()">Click Me!</button>: The <button> element includes the onclick attribute, which is set to call the displayMessage() function when the button is clicked.function displayMessage() { alert("Button was clicked!"); }: This JavaScript function displays an alert box with the message "Button was clicked!" when invoked.The complete list of Event Attributes are given below:Window Event AttributesDescriptiononafterprintUsed with onbeforeprint to perform actions after the page is printed.onbeforeprintThe alert message display before the print dialogue box appears.onbeforeunloadThe onbeforeunload event run when the document is about to be unloaded.onerrorThis attribute works when an error occurs while loading an external file.onhashchangeThis attribute works when there has been changes to the anchor part.onloadThis attribute works when an object has been loaded.onofflineThe onoffline event attribute works when the browser work in offline mode.ononlineThe ononline event attribute works when the browser starts working in online mode.onpageshowThis event occurs when a user navigates to a website.onresizeThe onresize event attribute is triggered each time when resize the browser window size.onunloadFired when the document is unloaded (e.g., when navigating away).Form Event AttributesForm Event AttributesDescriptiononblurThis attribute is mostly used in Form validation code.onchangeThe onchange event attribute works when the value of the element changes and select the new value from the List.oncontextmenuThis attribute works when the user right-clicks on an element to open the context menu.onfocusThis event attribute is mostly used with <input>, <select>, <a> elements.oninputThis attribute works when it gets user input value.oninvalidThe oninvalid event attribute works when an input field values are invalid or empty.onresetThe onreset event attribute in HTML is triggered when reset the form.onsearchWhen a user presses the ENTER button or click on the x button.onselectThe onselect event attribute works when some text has been selected in an element.onsubmitThe onsubmit event attribute in HTML is triggered when a form is submitted. Keyboard Event AttributesKeyboard Event AttributesDescriptiononkeydownThe onkeydown event is triggered when the user presses any key on the keyboard.onkeypressThis attribute fires when a user presses a key on the Keyboard.onkeyupThis onkeyup event attribute works when the user releases the key from the keyboard.Mouse Event AttributesMouse Event AttributesDescriptiononclickThe onclick event attribute in HTML works when the user clicks on the button.ondblclickThis Attribute Event occurs when a user fires mouse Double click on the Element.onmousedownwhen a mouse button is pressed down on the elementonmousemoveThe onmousemove attribute works when the pointer moves over an element.onmouseoutwhen the mouse pointer moves out of the specified element.onmouseoverThe onmouseover event attribute works when the mouse pointer moves over the specified element.onmouseupwhen a mouse button is released over the element.onwheelwhen the wheel of pointer device is rolled up or down over an element.Drag Event AttributesDrag Event AttributesDescriptionondragwhen the element or text selection is being dragged in HTMLondragendwhen the user finished the dragging of element. The drag and drop feature is common in HTML5ondragenterThe ondragenter event attribute in HTML works when the content is draggableondragleaveThe ondragleave attribute works when a draggable element or text selection leaves a valid drop targetondragstartHTML ondragstart Event Attribute is used when the user wants to drag the text or element.ondropThe ondrop event attribute is used to drag an element or text and drop it into a valid droppable location or target.onscrollThis onscroll attribute works when an element scrollbar is being scrolled.Clipboard Events AttributesClipboard Events AttributesDescriptiononcopyThis attribute fires when the user copied the content present in an element.oncutThis attribute fires when the user cut or delete the content that has been present in the element.onpasteThe onpaste attribute works when some content are paste in an element.Misc Events AttributesMisc Events AttributesDescriptionontoggleThe ontoggle event is triggered when the user open or close the <details> element.Best Practices for Using HTML Event AttributesPrefer External JavaScript: Instead of embedding JavaScript directly within HTML event attributes, link to external JavaScript files to enhance code organization and maintainability.Use Event Listeners: Implement event listeners in JavaScript rather than inline event attributes to separate structure from behavior, improving code clarity.Avoid Overuse: Limit the number of event attributes to prevent performance issues and maintain a responsive user interface. Create Quiz Comment K kartik Follow 2 Improve K kartik Follow 2 Improve Article Tags : Web Technologies HTML HTML-Attributes HTML-Event 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