
The HTML Panel is a crucial tool for web developers, providing a visual representation of your HTML code and allowing you to inspect and edit elements in real-time.
It's a game-changer for debugging and troubleshooting, as you can see the actual HTML structure of your page and make changes on the fly.
To get started with the HTML Panel, you'll want to familiarize yourself with its key features, such as the Element Tree, which displays a hierarchical representation of your HTML elements.
The Element Tree is a powerful tool for navigating and understanding the structure of your HTML code.
On a similar theme: Html Tree
Getting Started
To create a ReactiveHTML component, you create a class by inheriting from the ReactiveHTML class. This custom class requires a _template attribute defined using HTML, which serves as the design blueprint for your component.
You can make the template dynamic by using JavaScript template variables ${...} as well as Python Jinja2 syntax. I've found that using these variables can greatly enhance the user experience, but it does require some extra coding.
You might enjoy: Component Contract Html
To get started with creating an HTML panel, you'll need to follow these steps:
- Insert a heading tag with the class panel-head and set the text and heading size as needed.
- Directly below the heading, insert a div tag with the class panel-content and place the desired content inside.
- Paste the necessary JavaScript and CSS code into the Additional Fields section.
A Basic Example
To create a custom component, you'll need to inherit from the ReactiveHTML class. This class serves as a foundation for your custom component, allowing you to build upon its existing functionality.
By defining the _template attribute using HTML, you can create a design blueprint for your custom component. This template can include JavaScript template variables ${...} to make it dynamic.
You can also use Python Jinja2 syntax to add more complexity to your template. This flexibility allows you to create custom components that meet your specific needs.
Here's a simple example of how you can structure your custom component:
- Define the _template attribute with HTML code
- Use JavaScript template variables to make the template dynamic
- Utilize Python Jinja2 syntax for added complexity
By following these steps, you can create a custom component that's tailored to your project's requirements.
When Ready
The HTML panel object exposes two promises that reflect the lifecycle of the window, allowing you to attach event handlers to controls inside the HTML panel.

You can use these promises to know when the panel is ready.
The DOM has been loaded when the "DOMContentLoaded" promise is triggered.
The document has been fully loaded when the "window.onload" promise is triggered, including things such as images.
To take advantage of these promises, you can use event handlers to control your HTML panel's behavior.
API Guide
The API Guide is a crucial resource for working with the HTML panel. You can find it here: API > ReactiveHTML.
To access the API Guide, simply click on the link provided. Note that you must wrap a {%for...%} loop in an HTML element with an id attribute as shown in the example. This is a specific requirement for using the API Guide effectively.
Discover more: Html to Pdf Api
Templates
In the HTML panel, you can define the blueprint of your component using the _template attribute, which consists of HTML for the content and optionally CSS or JavaScript for styling and behavior.
The _template variable can be used to create a slideshow, for example, by displaying an image and changing it dynamically with a parameter like ${index}.
This parameter allows you to change the image displayed, and you can also add event listeners, like the onclick event listener that triggers a Python method _img_click when the image is clicked.
Intriguing read: Html Form Submit Event
Template Template
The _template attribute is where the magic happens in defining your component's blueprint. It uses HTML for the content and can also include CSS or JavaScript for styling and behavior.
In fact, the _template attribute is like a blueprint that defines the structure of your component. This is especially useful when you want to create reusable components that can be easily customized.
The _template variable can consist of an HTML tag, like an img tag, that displays an image. This tag can also include dynamic parameters, such as ${index}, that change the image displayed.
Consider reading: Include Jquery to Html
For instance, an image component that displays a slideshow can be defined using the _template variable. This component includes an onclick event listener that triggers a Python method when the image is clicked.
By using the _template attribute, you can create components that are both visually appealing and functional. It's like having a template that you can customize to fit your needs.
Broaden your view: Set up Html Mail Using Word
Template Variables
Template variables are a powerful tool in templates, allowing you to link the parameters of a component to the attributes of HTML elements.
You can use JavaScript template variables of the form ${...} to set attributes of HTML elements. For example, the _template variable sets the class attribute of a div element to the value of the some_parameter parameter.
If the parameter is a list, each item in the list will be inserted in sequence, unless declared otherwise. However, if you want to wrap each child in some custom HTML, you will have to use Jinja2 loop syntax.
If this caught your attention, see: B Tag Html
You can also use JavaScript template variables to trigger Python methods on the component, like the _img_click method in the example.
To use JavaScript template variables, you must declare an id on components that contain a template variable.
Here are the differences between JavaScript template variables and Jinja2 templating:
- Time of Rendering: Jinja2 templating is rendered on the Python side during initial rendering, while JavaScript template variables are inserted later on the JavaScript side.
- Type of Rendering: Jinja2 templating provides literal string values, while JavaScript template variables provide Panel objects by default.
- Element ids: With Jinja2 templating, you don’t need to add an id attribute except when using {% for … %} loops. With JavaScript template variables, you must add an id attribute.
- Parameter Linking: Jinja2 {{...}} template variables are not dynamically linked, while JavaScript template variables `${…} are dynamically linked.
Reactive and Class
ReactiveHTML is a powerful tool for layout and event handling in HTML panels.
You can use HTML, JavaScript template variables ${...}, and Python Jinja2 syntax to layout your parameter values. This is especially useful for creating dynamic and interactive user interfaces.
The _template attribute allows you to configure event handlers using JavaScript code. You can also use the _scripts attribute to define JavaScript callbacks that respond to events or parameter changes.
Here are some key features of the HTMLPanel class:
Reactive
Reactive is a powerful approach that allows you to develop custom components using HTML, CSS, and JavaScript. Both ReactiveHTML in the Panel ecosystem and AnyWidget in the Jupyter ipywidgets ecosystem support this, but they have different parameter layouts and event handling mechanisms.
In ReactiveHTML, you typically use HTML, JavaScript template variables ${...}, and Python Jinja2 syntax to layout your parameter values. This is a key difference from other approaches.
You can configure event handlers using JavaScript code within the _template attribute in ReactiveHTML. This allows for a high degree of customization and flexibility.
Here are some key benefits of using ReactiveHTML for event handling:
- Use JavaScript code within the _template attribute to configure event handlers
- Define JavaScript callbacks that respond to events or parameter changes using the _scripts attribute
By using ReactiveHTML, you can create interactive HTML panels that are tightly integrated with your application code. This allows for a seamless user experience and powerful functionality.
Class
In the world of programming, classes are a fundamental concept that help us organize our code into reusable and modular pieces. A class is essentially a blueprint or a template that defines the properties and behavior of an object.
The HTMLPanel class is a great example of a class in action. It's a UI component that allows us to create and manage HTML elements within our application. The class has several constructors that enable us to initialize it with different types of HTML content.

One of the key features of the HTMLPanel class is its ability to add child widgets to the panel. This is done through methods such as add(Widget widget), add(Widget widget, Element elem), and addAndReplaceElement(Widget widget, Element toReplace). These methods allow us to dynamically add and replace widgets within the panel.
The class also has a createUniqueId() method that helps us generate unique IDs for elements within dynamically-generated HTML. This is useful when we need to identify specific elements within the panel.
Here are some of the key methods of the HTMLPanel class:
- add(Widget widget)
- add(Widget widget, Element elem)
- addAndReplaceElement(Widget widget, Element toReplace)
- createUniqueId()
These methods demonstrate the flexibility and customizability of the HTMLPanel class, making it a powerful tool for building dynamic user interfaces.
Usage and Configuration
To create an HTML panel, you can make a createHtmlPanel call on a UI element, which accepts parameters like the height of the panel to customize the experience further.
This call returns a Promise that resolves when the onload event of the underlying iframe fires, returning the frame's window object for easier interaction between the page and the HTML panel's page.
Curious to learn more? Check out: Click to Dial Html
You can interact with your HTML panels more easily by using the JavaScript SDK, which passes you the window element of the requested URL in a promise when createHtmlPanel is called.
However, due to browser security restrictions, accessing a panel's window variable is subject to the same-origin policy, which means most of the properties of window will not be accessible if you're on a different domain.
To avoid these issues, it's recommended to host your HTML document on the same domain as your main site, such as https://www.mywebsite.com.
This will allow you to use example code that relies on both your main app and the embedded HTML document being hosted on the same domain.
You might enjoy: Langchain Document Loaders Html
Adding and Integrating
To add a panel to your document, you can use the TinyMCE editor in the KB, which allows you to add collapsible panels without editing the document's HTML.
You can find the button to add a panel on the right end of the toolbar and under the Insert menu, looking like a plus and minus sign.
The button will prompt you to choose the heading size for the panel, enter the panel heading text, and optionally enter an ID for anchor reference, as well as choose if you want the panel to be expanded by default.
If this caught your attention, see: Color for Heading in Html
Adding

Adding a panel to your document is a breeze, thanks to the TinyMCE editor in the KB. Clicking the plus and minus sign button on the right end of the toolbar or under the Insert menu will prompt you to choose the heading size, panel heading text, and optional ID for anchor reference.
You can also choose to expand the panel by default or add buttons that allow the reader to open or close all panels within a document. Simply select the desired option, and you're good to go.
Alternatively, you can create a panel using the Source mode window in the editor. To do this, add a heading and a container, and then wrap the content you want to include in the panel within the container.
Consider reading: Html Container
Call App Internally
You can call your app from inside the HTML panel, which is an alternative way to accomplish the same thing. This is done by accessing the host app's Window object using window.top.
Note that window.top is the top frame, which corresponds to your app's Window object. This is unless your app itself is inside an iframe.
Readers also liked: Html Window Open
General Functionality
By default, panels will be collapsed when the page loads, unless certain panels were set to be expanded by default. This can be seen with the first panel in the example.
If a panel's heading is given an ID, you can link to it directly using an anchor link. This allows users to jump to a specific panel from another page, and it will be automatically expanded.
When a user follows an anchor link to a panel from the same page, the page will jump directly to that panel, which will also be expanded.
For another approach, see: Html a Anchor
External Dependencies
In a notebook, external dependencies are loaded automatically if a component is imported before calling pn.extension.
You can declare external dependencies like Javascript and CSS files using attributes such as __javascript__, __javascript_modules__, and __css__.
In a server context, you'll need to explicitly load extensions unless the component is rendered on initial page load.
If you add a component to the page in a callback, you'll also need to run pn.extension to load the extension.
Components can declare an _extension_name to require users to load them as an extension explicitly via a pn.extension call.
You might enjoy: Html Component Library
Web Components
Web components are custom HTML elements that work really great with ReactiveHTML. They integrate seamlessly with built-in HTML elements like button, div, and img.
Some popular web components that work well with Panels designs are Shoelace, Fast, and Material. These collections of components are mature and integrate well with their respective design systems.
You can use web components to create custom UI elements that are reusable and consistent throughout your application. For example, you can create a custom button component that matches your brand's design.
Here are some examples of web components that you can use with Panels designs:
- Shoelace: A large, mature collection of components that integrate well with the Bootstrap design.
- Fast: A relatively large and mature collection of components that integrate well with the Fast design.
- Material: A growing collection of components that integrate well with the Material design.
These web components can save you a lot of time and effort when building your application, and they can also help ensure consistency in your UI design.
Styles Tab
The Styles Tab is a non-closable tab that shows you a list of CSS blocks in your design, matching the currently selected component.
This is a quick way to discover what's affecting the element you're editing, and it displays both your own CSS and the app-generated CSS, labeled as "Bootstrap".

You can't edit the app-generated CSS, but you can override it by copying it to your own stylesheet.
To edit a CSS block, simply click on a selector, property, or value to edit them, and hit Enter or Tab to move to the next rule, or Shift+Tab to the previous.
You can also create new rules by clicking the space between them, and Bootstrap Studio will show you a suggestion list with valid CSS properties and values.
As you type, Bootstrap Studio will preview your changes in real time, making it easy to see the effects of your edits.
You can learn more about CSS editing in the dedicated CSS guide.
For your interest: Edit Html on Mac
General Functionality
Panels are collapsed by default when the page loads, unless they were set to be expanded by default.
You can link to a panel directly using an anchor link if its heading has an ID. This allows users to jump to a specific panel from another page, and it will expand automatically.
If a user follows an anchor link to a panel from the same page, the page will jump directly to that panel, which will also be expanded.
This behavior is useful for creating smooth navigation and user experience.
Broaden your view: Default Html
Different Conversations

By default, an HTML panel is shown for all conversations. This means that every conversation will have an HTML panel associated with it, even if the user switches to a different conversation.
You can limit an HTML panel to a single conversation by specifying the conversation ID, ConversationRef, or ConversationBuilder. This will make the panel visible only when that specific conversation is displayed.
The conversation parameter can be omitted in some createHtmlPanel calls, which will then act as the default HTML panel. This panel will be shown for conversations that don't have a conversation-specific HTML panel configured.
You can create multiple HTML panels for different conversations by calling createHtmlPanel multiple times. TalkJS will preload every HTML panel you create, but keep them hidden until the appropriate conversation is selected.
A fresh viewpoint: Html for Different Fonts
Limitations and Troubleshooting
You can only use HTML panels if you can host the HTML panel content on HTTPS. This is due to browser security policies.

Your entire app needs to be hosted on HTTPS if you want to be able to interact with the HTML panel client-side with JavaScript. Browsers consider http and https to be different origins.
You also need to host the HTML panel content on HTTPS during development. This can be a bit of a challenge, but there's a workaround.
You can use a tool like ngrok to serve the HTML panel pages from your local development server over HTTPS. This gives you a custom URL like https://qwerty12345.ngrok.io that points straight to your local development server.
To make HTML panels work, your server must not send an X-Frame-Options header with HTML panel pages. This is because HTML panels are loaded into iframes and the header would prevent them from working.
Here are some things to keep in mind when using HTML panels:
- You can only use HTML panels on HTTPS.
- Your entire app needs to be on HTTPS for client-side JavaScript interaction.
- Use a tool like ngrok for local development.
- Don't send the X-Frame-Options header with HTML panel pages.
Frequently Asked Questions
What is a panel in HTML?
A panel in HTML is a container that holds other tags and content, used to show or hide form elements based on user roles or permissions. It's a versatile tool for creating dynamic and secure web forms.
How to create a popup screen in HTML?
To create a popup screen in HTML, combine HTML, CSS, and JavaScript to create a basic structure, style it, and add interactive control. This trifecta of technologies enables you to create a dynamic popup that appears on demand.
Featured Images: pexels.com

