Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap4 Tooltip

Bootstrap4 Tooltip

A tooltip is a small pop-up displayed when the mouse moves over an element and disappears when the mouse moves away.


How to Create a Tooltip

Create a tooltip by adding data-toggle="tooltip" to the element.

The content of the title attribute is what the tooltip displays:

<a href="" data-toggle="tooltip" title=">

I am the tooltip content!

"

Hover over me

a

Note: The tooltip should be written in the jQuery initialization code: then call the tooltip() method on the specified element.

The following example can use tooltips anywhere in the document:

Example

$

(

document

)

.

ready

(

function

(

)

{

$

(

'

[data-toggle="tooltip"]

'

)

.

tooltip

(

)

;

}

)

;

Try it »


Specifying the Tooltip Position

By default, the tooltip is displayed above the element.

You can use the data-placement attribute to set the direction in which the tooltip is displayed: top, bottom, left or right:

Example

<a href="" data-toggle="tooltip" data-placement="top" title=">

I am the tooltip content!

"

Hover over me

a

<a href="" data-toggle="tooltip" data-placement="bottom" title=">

I am the tooltip content!

"

Hover over me

a

<a href="" data-toggle="tooltip" data-placement="left" title=">

I am the tooltip content!

"

Hover over me

a

<a href="" data-toggle="tooltip" data-placement="right" title=">

I am the tooltip content!

"

Hover over me

a

Try it »

Used in a button:

Example

<button type="button" class=">

btn btn-secondary

"

data-toggle

=

"

tooltip

"

data-placement

=

"

top

"

title

=

"

Tooltip on top

"

Tooltip on top

button

<button type="button" class=">

btn btn-secondary

"

data-toggle

=

"

tooltip

"

data-placement

=

"

right

"

title

=

"

Tooltip on right

"

Tooltip on right

button

<button type="button" class=">

btn btn-secondary

"

data-toggle

=

"

tooltip

"

data-placement

=

"

bottom

"

title

=

"

Tooltip on bottom

"

Tooltip on bottom

button

<button type="button" class=">

btn btn-secondary

"

data-toggle

=

"

tooltip

"

data-placement

=

"

left

"

title

=

"

Tooltip on left

"

Tooltip on left

button

Try it »

To add HTML tags to the tooltip content, set data-html="true" and put the content inside the title attribute:

Example

<button type="button" class=">

btn btn-secondary

"

data-toggle

=

"

tooltip

"

data-html

=

"

true

"

title

=

"

Tooltip with HTML

"

Tooltip with HTML

button

Try it »

Disabled button:

Example

<span class="d-inline-block" tabindex="0" data-toggle="tooltip" title=">

Disabled tooltip

"

<button class=">

btn btn-primary

"

style

=

"

pointer-events: none;

"

type

=

"

button

"

disabled

Disabled button

button

span

Try it »