Skip to content
PHP Logo

What are best practices for formatting tooltips in PHP?

When formatting tooltips in PHP, it is important to keep them concise and informative. Avoid using too much text or overwhelming the user with information. Use HTML and CSS to style the tooltips for a visually appealing presentation.

php
<?php
echo '<span class="tooltip">Hover over me<span class="tooltiptext">This is a tooltip message</span></span>';
?>

<style>
.tooltip {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: black;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -60px;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
}
</style>