Skip to content
PHP Logo

How can HTML-formatted text be used in tooltips in PHP?

When using tooltips in PHP, HTML-formatted text can be used by simply including the HTML tags within the tooltip content. This allows for styling such as bold text, links, or even images to be displayed within the tooltip. Ensure that the tooltip content is properly escaped to prevent any potential security vulnerabilities.

php
<?php
$tooltipContent = '<strong>This is a tooltip</strong> with <a href="#">HTML-formatted text</a>.';
echo '<span title="' . htmlentities($tooltipContent) . '">Hover over me</span>';
?>