HTML onresize Attribute

HTML onresize Attribute: The HTML onresize Attribute is defined as it fires when the browser window is resized. The onresize attribute is part of the Event attributes.

HTML onresize Attribute

This HTML onresize attribute can be applied on the <body> element.

Syntax: <element onresize=”script”>



Browser Support:

The HTML onresize attribute is supported by the following browsers:

  • Chrome
  • Firefox
  • Safari
  • Opera
  • Internet Explorer

Example: for <body> element

<!DOCTYPE html>
<html>
<body onresize="myFunction()">
<p>Try to resize the browser window.</p>
<script>
function myFunction() {
  alert("You have changed the size of the browser window!");
}
</script>

</body>
</html>

Output:

Try to resize the browser window.