Insert HTML into your app.
Adding custom HTML to your app impacts safety, styling, and maintainability. We sanitize HTML with DOMPurify, but inserting HTML remains a developer risk. Passing untrusted code to Jt.html or dynamically loading external code can increase the risk of vulnerabilities in your app.
Jt.html
content is not iframed. Executing JavaScript is not supported.
Method Signatures and Parameters | |
Jt.html(String body) | body (String) The HTML code to insert. |
Jt.html(java.nio.file.Path filePath) | filePath (java.nio.file.Path) The path of the file containing the HTML code to insert. |
Chainable builder methods | |
width(String width) | The width of the element. This can be one of the following:
|
width(int widthPixels) | The width of the element in pixels. The element will have a fixed width. If the specified width is greater than the width of the parent container, the width of the element matches the width of the parent container. |
key(String key) | A string to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. No two widgets may have the same key. |
No description | |
use() | Put the widget in the app, in the |
use(JtContainer container) | Put the widget in the app, in the provided container. |
Examples
Simple HTML content
import tech.catheu.jeamlit.core.Jt;
public class HtmlApp {
public static void main(String[] args) {
Jt.html("<h3>Custom HTML Header</h3>").use();
Jt.html("<p style='color: blue;'>This is blue text</p>").use();
Jt.html("<ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>").use();
}
}
Loading HTML from file
import tech.catheu.jeamlit.core.Jt;
import java.nio.file.Path;
public class HtmlFileApp {
public static void main(String[] args) {
// Assumes you have a file "content.html" in your project
Jt.html(Path.of("content.html")).use();
}
}
Still have questions?
Go to our discussions forum for helpful information and advice from Jeamlit experts.