How we can cut a text from the middle using HTML & CSS? Solution: CSS Text Cut Effect On Hover, Divide Text From Middle And Reveal Another.

Yesterday I saw text cutting effect on hover on a website, When I did hover on phone number field and the “phone number” text cut from the middle and actual number reveals. Then I started thinking about how I can create that cool effect. Finally, I did my work.

So today I am sharing CSS Text Cut Effect On Hover program. In other words, Divide text and reveal another text on hover. This is a pure CSS cutting text program, no javascript or any library. Also, it has a little sword effect, when cutting text. In this case, I take a text “secret” when I hover on text, the text divide in two parts from the middle. One section of the text goes left and one goes right, The the second text appears.

This is the power of CSS3, You don’t have an idea of what you can do only with CSS. This program is nothing at all, Expert developers create unbelievable things with CSS. But if you a beginner, then you can understand is program easily because that is not a hard one. You can use this on your website at special section like about intro, portfolio, etc.

If you don’t get what is the program I am talking about, Then see the preview given below.

Preview Of Divide Text And Reveal Another Program

See this video preview to getting an idea of how this program looks like.

Now you can see this program visually. If you like this, then get the source code of its.

You May Also Like:

CSS Text Cut Effect On Hover Source Code

As always before sharing source code, Let’s talk about this program. As you know this is a Pure CSS Text Cut Effect, Text divide into parts on hover and another text appear. For creating this program I used CSS clip (get info) property. And I gave the text position: absolute; property, because The clip property applies only to absolutely positioned elements. & I used @keyframe for creating the sword effect for cutting text.

For creating this program you have to create only 2 files. One for HTML and one for CSS. Follow the steps to create this program without any error.

index.html

Create an HTML file named ‘index.html‘ and put these codes given below.

index.html <!DOCTYPE html> <!-- code by webdevtrick ( https://webdevtrick.com ) --> <html lang="en" > <head> <meta charset="UTF-8"> <title>CSS Text Cutting Effect | Webdevtrick.com</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="main"> <p class="rtext"><a href="https://webdevtrick.com" class="txt" data-txt="SECRET">WEBDEVTRICK.COM</a></p> </div> </body> </html> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <!DOCTYPE html> <!-- code by webdevtrick ( https://webdevtrick.com ) --> <html lang = "en" > <head> <meta charset = "UTF-8" > <title> CSS Text Cutting Effect | Webdevtrick.com </title> <link rel = "stylesheet" href = "style.css" > </head> <body> <div class = "main" > <p class = "rtext" > <a href = "https://webdevtrick.com" class = "txt" data-txt = "SECRET" > WEBDEVTRICK.COM </a> </p> </div> </body> </html>

style.css

Now create a CSS file named ‘style.css‘ and put these files.

style.css /** code by webdevtrick ( https://webdevtrick.com ) **/ @import url(https://fonts.googleapis.com/css?family=Fredoka+One&display=swap); * { margin: 0; padding: 0; } body { width: 100%; height: 100%; background: #1D1F20; } .main { position: relative; width: 100%; height: 100vh; } .rtext { position: absolute; top: 0; bottom: 0; left: 0; right: 0; width: 120px; height: 40px; line-height: 40px; margin: auto; } .txt { position: relative; display: block; text-decoration: none; font-family: 'Fredoka One', cursive; font-size: 30px; text-align: center; color: transparent; transition: all .5s 0s ease-out; } .rtext:hover .txt { color: white; transition: all .8s .3s ease-in; margin-left: -50px; } .txt::before, .txt::after { content: attr(data-txt); position: absolute; top: 0; left: 0; clip: rect(0,54px,40px,0); color: #fff; transition: all .3s .3s; } .txt::after { clip: rect(0,200px,40px,54px); } .rtext:hover .txt::before { left: -10px; opacity: 0; } .rtext:hover .txt::after { left: 10px; opacity: 0; } .rtext::before { content: ''; position: absolute; top: -100px; left: 0; right: 0; width: 1px; height: 80px; margin: auto; background: #fff; visibility: hidden; opacity: 0; } .rtext:hover::before { -webkit-animation: sword .5s; animation: sword .5s; } @keyframes sword { 0% {top: -100px; visibility: hidden; opacity: 0;} 20% {visibility: visible; opacity: 1;} 100% {top: 100px; visibility: hidden; opacity: 0;} } @-webkit-keyframes sword { 0% {top: -100px; visibility: hidden; opacity: 0;} 20% {visibility: visible; opacity: 1;} 100% {top: 100px; visibility: hidden; opacity: 0;} } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 /** code by webdevtrick ( https://webdevtrick.com ) **/ @import url(https://fonts.googleapis.com/css?family=Fredoka+One&display=swap); * { margin : 0 ; padding : 0 ; } body { width : 100% ; height : 100% ; background : #1D1F20 ; } .main { position : relative ; width : 100% ; height : 100vh ; } .rtext { position : absolute ; top : 0 ; bottom : 0 ; left : 0 ; right : 0 ; width : 120px ; height : 40px ; line-height : 40px ; margin : auto ; } .txt { position : relative ; display : block ; text-decoration : none ; font-family : 'Fredoka One' , cursive ; font-size : 30px ; text-align : center ; color : transparent ; transition : all .5s 0s ease-out ; } .rtext:hover .txt { color : white ; transition : all .8s .3s ease-in ; margin-left : -50px ; } .txt::before, .txt::after { content : attr ( data-txt ) ; position : absolute ; top : 0 ; left : 0 ; clip : rect ( 0,54px,40px,0 ) ; color : #fff ; transition : all .3s .3s ; } .txt::after { clip : rect ( 0,200px,40px,54px ) ; } .rtext:hover .txt::before { left : -10px ; opacity : 0 ; } .rtext:hover .txt::after { left : 10px ; opacity : 0 ; } .rtext::before { content : '' ; position : absolute ; top : -100px ; left : 0 ; right : 0 ; width : 1px ; height : 80px ; margin : auto ; background : #fff ; visibility : hidden ; opacity : 0 ; } .rtext:hover::before { -webkit-animation : sword .5s ; animation : sword .5s ; } @keyframes sword { 0% { top : -100px ; visibility : hidden ; opacity : 0 ; } 20% { visibility : visible ; opacity : 1 ; } 100% { top : 100px ; visibility : hidden ; opacity : 0 ; } } @-webkit-keyframes sword { 0% { top : -100px ; visibility : hidden ; opacity : 0 ; } 20% { visibility : visible ; opacity : 1 ; } 100% { top : 100px ; visibility : hidden ; opacity : 0 ; } }

That’s It. Now you have successfully created a CSS Text Cut Effect On Hover and Divide Text And Reveal Another. If you have any doubt or question comment down below.

Thanks For Visiting, Keep Visiting.