The Wayback Machine - https://web.archive.org/web/20250101193418/https://www.geeksforgeeks.org/html-dom-designmode-property/
Open In App

HTML DOM designMode Property

Last Updated : 30 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The DOM designMode property in HTML is used to specify whether the document is editable or not. It can also be used to set the document editable. 

Syntax:

  • Set: This property is used to set whether the document is editable or not.
document.designMode = "on|off";
  • Get: This property is used to return whether the document is editable or not.
document.designMode

Property Value: This property contains two values which are listed below:

  • off: It is the default value. In this mode, the document is not editable.
  • on: In this mode the document is editable.

Example 1: In this example, we will use DOM designMode property.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>
        DOM designMode Property
    </title>
</head>

<body style="text-align: center; ">
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <h2>DOM designMode Property</h2>
    <p>This document is editable!</p>

    <!-- script to set designMode property
        editable -->
    <script>
        document.designMode = "on";
    </script>
</body>

</html>

Output: 

Example 2: In this example, we will use the get method of designMode.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>
        DOM designMode Property
    </title>
</head>

<body style="text-align: center;">
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <h2>DOM designMode Property</h2>
    <button onclick="myFunction()">
        Get the designMode
    </button>
    <p id="geeks"></p>
    <!-- script to display designMode -->
    <script>
        function myFunction() {
            let x = document.designMode;
            document.getElementById("geeks").innerHTML = x;
        }
    </script>
</body>

</html>

Output: 

Supported Browsers: The browser supported by the designMode method are listed below:

HTML DOM designMode Property – FAQs

How does designMode affect the document’s content?

When enabled, users can edit the content directly in the browser, and changes are made to the document’s HTML.

Can designMode be used in web applications for user editing?

It is generally used for debugging or demonstration purposes. For user-driven editing in applications, consider using contenteditable elements.

How do you check if designMode is enabled?

Check the value of document.designMode. If it returns ‘on’, editing mode is enabled; otherwise, it is disabled.

Can designMode be applied to iframes?

Yes, you can enable designMode on the document inside an iframe using iframe.contentDocument.designMode.

How do you save changes made in designMode?

Changes made in designMode are temporary and not saved to the server. To persist changes, implement custom saving logic or use other methods.



Next Article

Similar Reads

three90RightbarBannerImg