> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/ui-customization/custom-modals.md).

# Custom Modals in WebViewer UI

Enhance your WebViewer UI with custom modals using the addCustomModal API. Learn how to create and manage unique modals with header, body, and footer components efficiently. Optimize user experience n

WebViewer supports custom modals. There are multiple APIs to help you manage them.

To create a new custom modal, you can use the [addCustomModal](https://sdk.apryse.com/api/web/UI.html#.addCustomModal__anchor) API. In order to create a custom modal, you need, at least, the dataElement that will be used to identify the modal, and the structural components `header`, `body` and `footer`.

The header element requires the following properties:

* `title` String, required. Used for the title of the modal
* `className` String, optional. CSS class name for the header section of the modal
* `style` Object, optional. Inline style as an object, for example: { width: '12px', height: '23px', color: 'red' }
* `children` Array, optional. The parameter for passing custom DOM elements to the header section of the modal

The body components is the main section of the custom modal and it requires following properties:

* `title` String, optional. Used for the \<p> text in body of the modal
* `className` String, optional. CSS class name for the body section of the modal
* `style` Object, optional. Inline style as an object, for example: { width: '12px', height: '23px', color: 'red' }
* `children` Array, optional. The parameter for passing custom DOM elements to the body section of the modal

The footer section of the custom modal requires the following parameters:

* `className` String, optional. CSS class name for the footer section of the modal
* `style` Object, optional. Inline style as an object, for example: { width: '12px', height: '23px', color: 'red' }
* `children` Array, optional. The parameter for passing custom DOM elements to the footer section of the modal

Once the custom modal is added, you can manage its visibility with these handy APIs:

* [UI.openElement](https://sdk.apryse.com/api/web/UI.html#.openElement)
* [UI.closeElement](https://sdk.apryse.com/api/web/UI.html#.closeElement)
* [UI.toggleElement](https://sdk.apryse.com/api/web/UI.html#.toggleElement)
* [UI.disableElements](https://sdk.apryse.com/api/web/UI.html#.disableElements)

Here is a code snippet that add a custom modal to WebViewer and immediately opens it:

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  initialDoc: "mydoc.pdf",
  css: 'path/to/stylesheet.css'
}, viewerElement).then(instance => {
  // Creating HTML DOM elements
  let divInput1 = document.createElement('input');
  divInput1.type = 'text';
  divInput1.id = 'unique_id_1';
  divInput1.style = 'height: 28px; margin-top: 10px; margin-right: 20px';

  let divInput2 = document.createElement('input');
  divInput2.type = 'text';
  divInput2.id = 'unique_id_2';
  divInput2.style = 'height: 28px; margin-top: 10px;';

  // Custom modal parameters
  const modalOptions = {
    dataElement: 'myCustomModal',
    header: {
      title: 'Header',
      className: 'myCustomModal-header',
    },
    body: {
      className: 'myCustomModal-body',
      style: {},
      children: [ divInput1, divInput2 ],
    },
    footer: {
      className: 'myCustomModal-footer footer',
      style: {},
      children: [
        {
          title: 'Cancel',
          button: true,
          style: {},
          className: 'modal-button cancel-form-field-button',
          onClick: (e) => {console.log('Cancel button') }
        },
        {
          title: 'OK',
          button: true,
          style: {},
          className: 'modal-button confirm ok-btn',
          onClick: (e) => { console.log('OK button') }
        },
      ]
    }
  }

  instance.UI.addCustomModal(modalOptions);

  instance.UI.openElements([modalOptions.dataElement]);
});
```

{% endcode %}
{% endtab %}
{% endtabs %}

For styling these components, see [Customizing WebViewer UI Styles](/web/ui-customization/customizing-styles.md). Here is an example stylesheet file for the above code.

{% tabs %}
{% tab title="CSS" %}
{% code lineNumbers="true" %}

```css
.myCustomModal-header {
  background-color: red;
}

.myCustomModal-body {
  background-color: green;
}

.myCustomModal-footer {
  background-color: blue;
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

This is the output for the code above:

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-9ea25060eded86620bd75fe8146dba9e3b37d964%2F0f6d81a870f7898f9faae027ae63a03a9ec81473-570x229.png?alt=media)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/ui-customization/custom-modals.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
