How to implement tooltips using CSS? Why you should use it?

Benefits of tooltips:

Implementing a Animated Tooltip

  • HTML file
<div class="section">
<h3>Hover to see the Tooltip</h3>
<div id="animated">
<span class="tooltip" data-tooltip="Create your own amazing tooltips">?</span>
  • CSS file
body {
background: #fff;
overflow: hidden;
.section {
display: flex;
align-items: center;
position: relative;
height: 100vh;
.tooltip {
position: relative;
background: #000;
padding: 5px 12px;
margin: 5px;
font-size: 15px;
border-radius: 100%;
color: #FFF;
.tooltip:after {
position: absolute;
content: '';
opacity: 0;
transition: all 0.4s ease;
.tooltip:before {
border-width: 10px 8px 0;
border-style: solid;
border-color: #000 transparent;
top: -15px;
transform: translateY(20px);
.tooltip:after {
content: attr(data-tooltip);
background: #000;
width: 160px;
height: 40px;
font-size: 13px;
font-weight: 300;
top: -75px;
left: -10px;
padding: 10px;
border-radius: 5px;
letter-spacing: 1px;
transform: translateY(20px);
.tooltip:hover::after {
opacity: 1;
transform: translateY(-2px);
// Only for Animation Effect (optional)@keyframes shake {
0% {
transform: rotate(2deg);
50% {
transform: rotate(-3deg);
70% {
transform: rotate(3deg);
100% {
transform: rotate(0deg);
#animated:hover {
animation: shake 500ms ease-in-out forwards;

Final Output



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Siddharth Rastogi

Siddharth Rastogi


I am a full stack developer, I have an expertise in Web Development. I write tech stuff and share my knowledge with others with the help of articles.