Skip to content
Related Articles

Related Articles

Web DOMRect API | DOMRect() Constructor

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 08 Aug, 2019

The DOMRect() constructor in DOMRect API is used to create DOMRect object which represents a rectangle.


var myDOMRect = new DOMRect(x, y, width, height);

Parameters: This constructor contains four parameters as mentioned above and described below:

  • x: It sets the x-coordinate of the rectangle.
  • y: It sets the y-coordinate of the rectangle.
  • width: It sets the width of the rectangle.
  • height: It sets the height of the rectangle.

Example: This example creates a DOMRect object with given parameters.

<!DOCTYPE html> 
        Web API | DOMRect() Constructor
<body style="text-align:center;">
    <h1 style="color:green;"
    <h2>Web API | DOMRect() Constructor</h2>
    <button onclick="getDOMRect ();">
        Get DOMRect object
    <p id='DOMRect'></p>
    <script type="text/javascript">
        function getDOMRect () {
            var myDOMRect = new DOMRect(0, 0, 100, 100);


  • Before Click the button:
  • After Click the Button console view:

Supported Browsers: The browsers supported by DOMRect() constructor are listed below:

  • Google Chrome
  • Firefox
  • Opera
  • Safari 10.1

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!