Open In App

How to spin text on mouse hover using HTML and CSS?

The spinning of text on mouse hover is known as the Spin Effect or the Rotation Effect. In this effect, each alphabet of the word is rotated along with any one of the axes (preferably Y-axis). Each word is wrapped inside in <li> tag and then using CSS:hover Selector selector we will rotate each alphabet on Y-axis. We will divide this article into two sections, in the first section we will create the basic structure of the text that will spin. IN the second section we will make that text structure spinnable when the user the hover on that.



Creating Structure: In this section we will create the structure by using HTML. 




<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport"
              content="width=device-width, initial-scale=1.0" />
        <title>Spin Text</title>
    </head>
    <body>
        <ul>
            <li>G</li>
            <li>e</li>
            <li>e</li>
            <li>k</li>
            <li>s</li>
            <li>f</li>
            <li>o</li>
            <li>r</li>
            <li>G</li>
            <li>e</li>
            <li>e</li>
            <li>k</li>
            <li>s</li>
        </ul>
    </body>
</html>

Designing Structure: In this section we will make that structure spinnable and add the little bit of decoration. 






<style>
            body {
                margin: 0;
                padding: 0;
            }
 
            ul {
                padding: 50px;
                margin: 0;
                position: absolute;
                top: 20%;
                left: 25%;
            }
            ul li {
                list-style: none;
                color: green;
                float: left;
                font-size: 40px;
                transition: 0.8s;
            }
 
            ul:hover li {
                transform: rotateY(360deg);
            }
</style>

Final Solution: It is the combination of the above two codes. 




<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport"
              content="width=device-width, initial-scale=1.0" />
        <title>Spin Text</title>
        <style>
            body {
                margin: 0;
                padding: 0;
            }
 
            ul {
                padding: 50px;
                margin: 0;
                position: absolute;
                top: 20%;
                left: 25%;
            }
            ul li {
                list-style: none;
                color: green;
                float: left;
                font-size: 40px;
                transition: 0.8s;
            }
 
            ul:hover li {
                transform: rotateY(360deg);
            }
        </style>
    </head>
    <body>
        <ul>
            <li>G</li>
            <li>e</li>
            <li>e</li>
            <li>k</li>
            <li>s</li>
            <li>f</li>
            <li>o</li>
            <li>r</li>
            <li>G</li>
            <li>e</li>
            <li>e</li>
            <li>k</li>
            <li>s</li>
        </ul>
    </body>
</html>

Output: 

 


Article Tags :