HTML onresize Event Attribute


The HTML onresize attribute is triggered when user resize the browser window.

Syntax

Following is the syntax −

<tagname onresize=”script”></tagname>

Let us see an example of HTML onresize event Attribute −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      color: #000;
      height: 100vh;
      background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
      padding: 20px;
   }
</style>
</head>
<body onresize="resizeFn()">
<h1>HTML onresize Event Attribute Demo</h1>
<p>Now resize the browser window</p>
<script>
   function resizeFn() {
      document.body.style.background = 'linear-gradient(45deg, #8BC6EC 0%, #9599E2 100%) no-repeat';
   }
</script>
</body>
</html>

Output

Now resize the browser window to observe how onresize event attribute works.

Updated on: 26-Sep-2019

66 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements