JSFiddle - React, Tailwind, and code Playground

by padma rubhan

HTML

<form action="action_page.php">
  Country code: <div class="tooltip">
  
  <input type="text" name="country_code" id="a" pattern="[A-Za-z]{3}" ><span class="tooltiptext">Three letter country code</span></div>
  <input type="submit">
</form>

<p><strong>Note:</strong> The pattern attribute of the input tag is not supported in Internet Explorer 9 and earlier versions, or in Safari.</p>

CSS

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

.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: red;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;

    /* Position the tooltip */
    position: absolute;
    z-index: 1;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
}