Stop adding HTML in report headers
How to implement custom HTML tooltips accross your APEX application

Since Microsoft launched Word in the '90s, we were introduced to tooltips. Back then, they used tooltips to improve the UX, allowing navigation through a complex app without an extreme need to read all the documentation, as these small boxes conveyed very useful information.
Little has changed since then; tooltips are still a great way to engage users and help them use your product as intended. To learn more about how and when to use this powerful resource, you can read this article. However, to learn how to implement this in your Oracle APEX applications, follow me 🤘🏽
Oracle APEX already has built-in Help Text, and there are also excellent tooltip plugins available on apex.world. Many of them include advanced features like positioning engines, accessibility improvements, and dynamic rendering.
However, sometimes you only need a lightweight tooltip solution, without adding external dependencies.
In this article we’ll implement two different tooltip approaches using vanilla JavaScript:
1️⃣ Generic tooltips for any element
2️⃣ Column header tooltips designed specifically for APEX reports
Both solutions share the same tooltip appearence, but they differ in how the tooltip icon is attached.
Why Two Approaches?
Oracle APEX tables (Interactive Reports, Classic Reports, etc.) have very sensitive layout behavior.
If we inject HTML directly into column headings, we may break:
column width calculation
responsive layout
sorting links
Select Columns dialog
exported metadata
You can end up with something like this:
Therefore, I will show you how to implement tooltips without these flaws.
Step 1 — Tooltip Engine (Vanilla JS)
This is the core tooltip logic.
💡 For educational purposes, I used innerHTML, but avoid this in real-world scenarios as it can be vulnerable. If you need HTML support, create a whitelist. There are various methods available online, including using PL/SQL, so let's keep it straightforward. If you want only text-based tooltips, you can use textContent instead of innerHTML
In summary, this code detects elements with .js-tip (we will inject this after) and displays the tooltip.
(function () {
/**
* Unique DOM id used by the shared tooltip balloon.
*
* This tooltip engine creates a single floating tooltip element and reuses it
* for every trigger that has the `.js-tip` class.
*/
const TIP_ID = "apxBalloonTip";
/**
* Safely finds the closest tooltip trigger element starting from an event target.
*
* Why this helper exists:
* - In delegated DOM events, `e.target` is not always an HTMLElement.
* - Sometimes it may be a text node or another node type without `.closest()`.
* - This function prevents runtime errors such as:
* "TypeError: e.target.closest is not a function"
*
* How it works:
* 1. If the target itself is an element and supports `.closest()`,
* search upward for the nearest `.js-tip`.
* 2. If not, try the parent element.
* 3. If no valid tooltip trigger is found, return null.
*
* @param {EventTarget|Node|null} target - Original event target.
* @returns {HTMLElement|null} The nearest tooltip trigger or null.
*/
function getClosestTipTarget(target) {
if (!target) return null;
if (target.nodeType === 1 && typeof target.closest === "function") {
return target.closest(".js-tip");
}
if (target.parentElement && typeof target.parentElement.closest === "function") {
return target.parentElement.closest(".js-tip");
}
return null;
}
/**
* Initializes the generic tooltip engine.
*
* Responsibilities:
* - Creates the shared floating tooltip element once, if it does not already exist.
* - Reads tooltip data from any element with class `.js-tip`.
* - Supports both plain text and HTML tooltip content.
* - Uses event delegation so dynamically added elements also work.
*
* Expected trigger attributes:
* - data-tip-title : optional tooltip title
* - data-tip-html : optional HTML content (takes precedence)
* - data-tip-text : optional text/HTML fallback content
*
* Positioning behavior:
* - By default, shows the tooltip above the target.
* - If there is not enough space above, it shows below the target.
*
* Notes:
* - This implementation uses `innerHTML` on purpose, so HTML markup is allowed.
* - Only use trusted content, or sanitize it beforehand if the source is user-provided.
*/
function initTooltipEngine() {
/**
* Reuse the existing tooltip balloon if already present in the DOM.
* Otherwise, create it once and append it to <body>.
*/
let tipEl = document.getElementById(TIP_ID);
if (!tipEl) {
tipEl = document.createElement("div");
tipEl.id = TIP_ID;
tipEl.className = "apx-balloon-tip";
/*Avoid it, use textContent for text only */
tipEl.innerHTML = `
<div class="apx-balloon-tip__inner">
<div class="apx-balloon-tip__title"></div>
<div class="apx-balloon-tip__text"></div>
</div>
`;
document.body.appendChild(tipEl);
}
/**
* Cache references to the tooltip title and content containers.
*/
const titleEl = tipEl.querySelector(".apx-balloon-tip__title");
const textEl = tipEl.querySelector(".apx-balloon-tip__text");
/**
* Displays the tooltip for a given trigger element.
*
* Content resolution order:
* 1. data-tip-html
* 2. data-tip-text
*
* Title fallback:
* - "Information"
*
* Positioning logic:
* - Center horizontally relative to the trigger
* - Prefer above the trigger
* - If there is not enough top space, place it below
*
* @param {HTMLElement} target - Tooltip trigger element.
*/
function show(target) {
const title = target.getAttribute("data-tip-title") || "Information";
const html = target.getAttribute("data-tip-html");
const text = target.getAttribute("data-tip-text") || "";
titleEl.innerHTML = title;
// Intentionally use innerHTML so the tooltip can render markup such as: <b>, <br>, <img>, <a>, lists, tables, etc. Use textContent just for text
textEl.innerHTML = html || text;
tipEl.style.display = "block";
const rect = target.getBoundingClientRect();
const tipRect = tipEl.getBoundingClientRect();
let left = rect.left + rect.width / 2 - tipRect.width / 2;
let top = rect.top - tipRect.height - 10;
// If there is not enough space above the target,
// render the tooltip below it instead.
if (top < 8) {
top = rect.bottom + 10;
}
tipEl.style.left = (left + window.scrollX) + "px";
tipEl.style.top = (top + window.scrollY) + "px";
}
/**
* Hides the shared tooltip balloon.
*/
function hide() {
tipEl.style.display = "none";
}
/**
* Show tooltip on mouse enter using event delegation.
*
* Delegation is important because some APEX components re-render portions
* of the page after refresh, and dynamically added `.js-tip` elements should
* still work without rebinding events.
*/
document.addEventListener("mouseenter", function (e) {
const el = getClosestTipTarget(e.target);
if (!el) return;
show(el);
}, true);
/**
* Hide tooltip on mouse leave using event delegation.
*/
document.addEventListener("mouseleave", function (e) {
const el = getClosestTipTarget(e.target);
if (!el) return;
hide();
}, true);
}
/**
* Initialize the tooltip engine when the APEX page DOM is ready.
*/
apex.jQuery(initTooltipEngine);
})();
/**
* Adds a tooltip icon to a report column header using the header element id.
*
* This approach is specifically intended for Oracle APEX report headers
* (Interactive Reports, Classic Reports, etc.), where injecting HTML directly
* into the column heading may cause layout issues or pollute report metadata.
*
* Instead of editing the heading text itself, this function:
* - locates the rendered <th> by id
* - finds the most appropriate insertion point inside that header
* - appends a tooltip icon dynamically
*
* Why this is useful:
* - preserves the original APEX-generated header structure
* - avoids placing raw HTML inside the column heading definition
* - can be reapplied automatically after region refresh
*
* @param {string} headerId - DOM id of the rendered header cell (<th>).
* @param {string} tooltipHtml - HTML content to show inside the tooltip balloon.
* @param {Object} [options] - Optional configuration object.
* @param {string} [options.title="Information"] - Tooltip title.
*/
window.apexAddHeaderTooltipById = function (headerId, tooltipHtml, options) {
options = options || {};
const title = options.title || "Information";
/**
* Determines where the tooltip icon should be inserted inside the header.
*
* Priority:
* 1. If the header contains a link (<a>), use it.
* This is common in sortable report headers.
* 2. Otherwise, if a <span> exists, use it.
* 3. Fallback to the <th> itself.
*
* This tries to preserve the visual structure produced by Oracle APEX.
*
* @param {HTMLElement} th - The header cell element.
* @returns {HTMLElement} The node that should receive the tooltip icon.
*/
function getInsertionTarget(th) {
const link = th.querySelector("a");
if (link) return link;
const span = th.querySelector("span");
if (span) return span;
return th;
}
/**
* Renders the tooltip icon into the target header if it is not already present.
*
* Safeguards:
* - If the header does not exist yet, do nothing.
* - If a tooltip icon has already been added for this header, do nothing.
*
* The generated icon:
* - uses Font Awesome classes
* - includes `.js-tip` so the generic tooltip engine can detect it
* - stores tooltip title/content in data attributes
*/
function render() {
const th = document.getElementById(headerId);
if (!th) return;
// Prevent duplicate icons when the same function is called multiple times
// or when the region refreshes.
if (th.querySelector('.js-tip[data-header-id="' + headerId + '"]')) {
return;
}
const target = getInsertionTarget(th);
const icon = document.createElement("span");
icon.className = "fa fa-info-circle js-tip";
icon.setAttribute("data-tip-title", title);
icon.setAttribute("data-tip-html", tooltipHtml);
icon.setAttribute("data-header-id", headerId);
icon.style.marginLeft = "6px";
icon.style.cursor = "pointer";
target.appendChild(icon);
}
/**
* Execute once when the page is ready, and again after APEX refresh events.
*
* This is necessary because APEX report regions may rebuild their headers after:
* - filtering
* - sorting
* - pagination
* - actions menu changes
* - manual region refresh
*
* Re-running `render()` ensures the tooltip icon is restored when needed.
*/
apex.jQuery(function () {
render();
apex.jQuery(document).on("apexafterrefresh", render);
});
};
Let's add some style 😎
/* =========================================================
1) BASE: any tooltip trigger
========================================================= */
.js-tip {
cursor: pointer;
}
/* =========================================================
2) GENERIC INLINE TOOLTIP
Use for labels, buttons, text, form items, etc.
Example:
<span class="fa fa-info-circle js-tip js-tip-inline" ...></span>
========================================================= */
.js-tip-inline {
display: inline-block;
vertical-align: middle;
margin-left: 4px;
font-size: 12px;
line-height: 1;
position: relative;
top: -1px;
}
/* =========================================================
3) COLUMN HEADER TOOLTIP
Use only for report column headers injected by JS
========================================================= */
.js-tip-col {
display: inline-block;
vertical-align: middle;
margin-left: 6px;
font-size: 12px;
line-height: 1;
position: relative;
top: -1px;
white-space: normal;
}
/* If the icon is appended inside a sortable link, keep it inline */
th a .js-tip-col,
.a-IRR-headerLink .js-tip-col,
.a-GV-headerLabel .js-tip-col {
display: inline-block;
vertical-align: middle;
margin-left: 6px;
}
/* =========================================================
4) BALLOON TOOLTIP
Shared by both scenarios
========================================================= */
.apx-balloon-tip {
position: absolute;
z-index: 99999;
display: none;
max-width: 340px;
min-width: 220px;
pointer-events: none;
}
.apx-balloon-tip__inner {
background: #1f1f1f;
color: #ffffff;
border-radius: 10px;
padding: 12px 14px;
box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
font-size: 13px;
line-height: 1.45;
text-align: left;
}
.apx-balloon-tip__title {
font-weight: 700;
margin-bottom: 6px;
}
.apx-balloon-tip__text {
overflow-wrap: break-word;
word-break: normal;
}
.apx-balloon-tip__text p {
margin: 0 0 8px 0;
}
.apx-balloon-tip__text p:last-child {
margin-bottom: 0;
}
.apx-balloon-tip__text ul,
.apx-balloon-tip__text ol {
margin: 8px 0 8px 18px;
padding: 0;
}
.apx-balloon-tip__text li {
margin: 0 0 4px 0;
}
.apx-balloon-tip__text img {
max-width: 100%;
height: auto;
display: block;
margin-top: 8px;
border-radius: 6px;
}
.apx-balloon-tip__text a {
color: #7dc3ff;
text-decoration: underline;
}
.apx-balloon-tip__text table {
width: 100%;
border-collapse: collapse;
margin-top: 8px;
}
.apx-balloon-tip__text th,
.apx-balloon-tip__text td {
border: 1px solid rgba(255, 255, 255, 0.18);
padding: 6px 8px;
text-align: left;
}
Step 2 — Upload the JavaScript/CSS File
Instead of placing JavaScript/CSS inline on every page, we’ll store them in an Application Static File.
Upload the file
Get all the code above, name it and save it as a .js / .css.
Go to: Shared Components → Static Application Files → Upload it → Copy the URL
Do it for both.
Reference the file globally
Navigate to: Shared Components → User Interface Attributes → On Javascript group, past the URL
Do the same with CSS.
For older versions, navigate to: Shared Components → User Interface → Click on Edit icon for a specific User Interface → On Javascript group, past the URL
Now the script is available across the application.
Generic Tooltip (for Any Element)
This approach is extremely simple.
You only need to add the class .js-tip to an element and provide the tooltip text.
Example:
Your component name: <span class="fa fa-info-circle js-tip"
aria-hidden="true"
data-tip-title="Information:"
data-tip-text="Your tip here"></span>
Notice something important:
Instead of using textContent we use innerHTML. This allows HTML formatting inside the tooltip.
Example tooltip content:
Your text <b>here</b>
<!--For more complex tags, use single quote.-->
This approach works well for:
icons
buttons
labels
form fields
dashboards
However, it is not ideal for report column headers.
Why This Approach Is Not Ideal for Columns
If you insert HTML directly inside column headings like this:
Your column heading <span class="fa fa-info-circle js-tip"></span>
you may encounter issues:
column width miscalculation
layout shifts
sorting link interference
Select Columns dialog showing HTML
Oracle APEX reports rely on a specific DOM structure. Changing that structure can easily break the layout. So for column headers we use a different approach.
Column Header Tooltip
Instead of modifying the heading text, we attach the tooltip icon dynamically after the report renders. This preserves the original markup generated by APEX.
For this, we rely on a function defined earlier, allowing us to simply call it with the necessary parameters.
In my demo, I set the column Static ID of my IR column as HeaderMSRP
For Classic reports, we can simply use the column name in our JavaScript call. This call will occur in a dynamic action on onload (action = Execute JavaScript code) or in Execute when Page Loads in page attributes.
//Injecting the tooltip
apexAddHeaderTooltipById(
"HeaderMSRP",
`
This value represents the suggested <strong>retail price</strong> for the product.
`,
{
title: "Information"
//you can taylor with more attributes if you must
}
);
The tooltip icon is inserted without altering the column structure.
Final Thoughts
If you only need simple tooltips across your application, the generic .js-tip approach is perfect.
If you're working with report column headers, always prefer the header injection method, since it preserves APEX’s internal structure.
And remember:
There are also excellent tooltip plugins available on apex.world that provide advanced features such as:
smarter positioning engines
accessibility improvements
dynamic rendering
animation support
In this article we implemented a minimal vanilla JavaScript solution to keep things simple and dependency-free.
If you'd like, I can also show how to extend this tooltip system with:
auto-placement (Popper-style positioning)
tooltip arrows
mobile support
keyboard accessibility improvements
—all still using vanilla JavaScript. So let me know in the comments!
About the author
I'm a APEX Senior developer who likes write down what I discover to keep a part of my mind stored and share my knowing with others.
Comments
Join the discussionNo comments yet. Be the first to comment.






