JavaScript Tooltip

The tooltip supports flexibility in how it is triggered, closed, and how its content is loaded:

DOWNLOAD
Demos & Source Code v2025.11.11

Thanks for using Menucool Tooltip

Confirm Download

Tooltip Options

You can configure the tooltip global options by editing the var tooltipOptions in tooltip.js.

Note: To set different options for an individual tooltip, pass a specific options object when opening it, as shown in the demos above.

var tooltipOptions=
{
    position: 1,
    smartPosition: false,
    maxWidth: 500,
    sticky: false,
    overlay: false,
    // In most cases, you don't need to change the following options.
    relativeTo: "element",
    cssClass: "",
    offsetX: 0,
    offsetY: 0,
    calloutPosition: 0.3,
    calloutSize: 20,
    showDelay: 150,
    hideDelay: 300,
    effect: "slide",
    duration: 200
};
position

An integer from 0 to 6 that specifies the tooltip's position:

  • 0: top
  • 1: right
  • 2: bottom
  • 3: left

The positions above are relative to the target element. The following positions are relative to the browser window:

  • 4: center
  • 5: top left
  • 6: bottom right
The tooltip will not have the callout arrow when its position value is greater than 3.
smartPosition

true or false.

When set to true, the tooltip box will automatically reposition itself if there isn't enough space, ensuring it remains visible.

maxWidth

An integer specifying the max width of the tooltip.

  • If the content width required is less than the maxWidth, the tooltip width will be the content width.
  • If the content width required is larger than the maxWidth and unable to wrap its content to fit the maxWidth, for example an image that is larger than the maxWidth, the tooltip will expand to the content width ignoring the maxWidth specification.
sticky

true, false or 1.

Controls whether the tooltip remains visible when the mouse leaves the target element.

  • Both true and 1 make the tooltip sticky.
  • With sticky: true, the tooltip fades out when clicking outside the box; with sticky: 1, it does not.
  • The tooltip automatically detects touch-enabled devices. On such devices, sticky is true and its close button is shown no matter if sticky is set to false.
overlay

true, false or 1. When set to true or 1:

  • An overlay covers the page while the tooltip is visible.
  • Both true and 1 will make the tooltip sticky.
Difference:
  • true — The tooltip fades out either the close button or the overlay is clicked
  • 1 — The close button has to be clicked to dismiss the tooltip.
relativeTo

Can be set to "mouse" or "element" indicating whether the tooltip should appear relative to the mouse or to the target element. It is applicable only when position is ranged from 0 to 3.

cssClass

Add a CSS class to the tooltip box element (DIV#mcTooltip).

Usually it is always set to a blank string "" here. It is only used when you want an individual tooltip instance to have a different style from the default ones, and in this case, you can pass a cssClass option to the tooltip launch method.

For details please refer to the Example 3 in the next section: Special Options for Individual Tooltip.

offsetX, offsetY

An integer specifying the tooltip offset (in pixels) from the expected tooltip position.

The default value is 0.

calloutPosition

A decimal from 0 to 1 that sets the callout arrow's position.

For example, 0.3 places it near the left or top; 0.5 centers it.

calloutSize

An integer specifying the callout size of the tooltip.

Note: There will be no callout if the position option is larger than 3.

showDelay

An integer specifying how many milliseconds should elapse before the tooltip pops up

hideDelay

The milliseconds taken for the tooltip starts fading away after the mouse leave the target element

effect

"slide" or "fade" animation effect

duration

The milliseconds taken by the effect animation

Customize Styles

You can modify tooltip.css directly to change the appearance of all tooltips globally.

If you want to apply custom styling to a specific tooltip only, pass the cssClass option when opening it. The specified class will be added to the div#mcTooltip element.

To better understand how the styles can be customized, refer to the sample tooltip markup below, which is generated by the tooltip.js script.

<div id="mcTooltipWrapper">
    <div id="mcTooltip">
        <div class="mcTooltipInner">
            (Tooltip content)
        </div>
    </div>
    <div id="mcttCo"></div> 
    <div id="mcttCloseButton"></div> 
</div>
<div id="mcOverlay"></div> 
Close button (visible only when the option sticky or overlay is true or 1, or the screen is touch-enabled device.)
Screen overlay (visible only when the option overlay is true or 1)