HTML DOM Range collapse() Method

The collapse() method collapses the Range to one of its boundary points.

A collapsed Range is an empty range and doesn’t contain any content.



Parameters: This method takes boolean value as parameter.

  • true: Collapses the Range to its start.
  • false: Collapses the Range to its end.

Return value: This method has no return value.

Example: This example shows how to collapse a range using this method. Collapsed property is used to check if the range is collapsed or not.






<!DOCTYPE html>
        HTML DOM range 
        collapse() method
    <p>This is the Range Content</p>
    <button onclick="collapse()">
        Click To Collapse Range
        let range = document.createRange();
        let referenceNode = document.
        function collapse() {


Output: In console, we can see that the range is collapsed using this method.

  • Before Clicking the Button:

  • After Clicking the Button:

    It can be seen that start Offset and en Offset are now set to 3 after collapsing

Supported Browsers: The browsers supported by DOM Range collapse() method are listed below:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.