How we can customize specific characters between a word using CSS? Solution: CSS Variable Font Style With Split Character, Variable Text Animation.
Maybe you have heard about variable fonts, its different from normal static fonts. We can more customize and give special styles to each character or words. There is a JavaScript library to create variables to any fonts family, which is splitting.js (get). Basically, Splitting JS create elements and add CSS variables for animating text, grid, etc.
Today you will learn to create Variable Text Animation. In this program, I have selected some special characters between a word and give different color and styles. You do more like you can give transition and animation to selected char or words, font size, etc. I think this program will be very useful for you, and also you will understand the concept easily.
So, Today I am sharing CSS Variable Font Style With Split Character. Basically, there is a heading “webdev” and split its character using the JS library. And selected some special characters and give different style, height, width, animation, etc using CSS variable commands.
If you are thinking now how the variable text animation actually is, then see the preview given below.
Preview Of Variable Text Animation
See this video preview to getting an idea of how this var text looks like.
Now you can see this visually, also you can see it live by pressing the button given above. If you like this, then get the source code of its.
You May Also Like:
- JavaScript Copy To Clipboard
- CSS Gradient BackgroundÂ
- Active Tab Animation With Icon
- Responsive Testimonial Slider
CSS Variable Font Style With Split Character Source Code
Before sharing source code, let’s talk about it. As you know I have used splitting.js to creating this program. So, first I have created a heading using HTML <h1> tag. In the heading, I wrote WEBDEV and selected E, D, and V as a special character and stored using Data-* element.
Now there I have used some special CSS variable commands, for styling char separately. There is a command for manage font’s style font-variation-settings . Using this you can width and height of var font, But there is different command for width and height. For width, this is wdth and for height wght.
There left all other things you will understand after getting the codes, I can’t explain all in writing. For creating this you have to create only 2 files, one for HTML and one for CSS. Follow the steps to creating this without any error.
index.html
Create an HTML file named ‘index.html‘ and put these codes given here below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<!DOCTYPE html> <!--Code By Webdevtrick ( https://webdevtrick.com )--> <html lang="en" > <head> <meta charset="UTF-8"> <title>CSS Variable Font | Webdevtrick.com</title> <link href="https://fonts.googleapis.com/css?family=Lexend+Deca&display=swap" rel="stylesheet"> <link rel="stylesheet" href="style.css"> </head> <body> <h1 data-splitting>WEBDEV</h1> <script src='https://unpkg.com/splitting/dist/splitting.min.js'></script> <script>Splitting()</script> </body> </html> |
style.css
Now create a CSS file named ‘style.css‘ and put the codes given here.
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 |
/** Code By Webdevtrick ( https://webdevtrick.com ) **/ * { box-sizing: border-box; font-family: 'Lexend Deca', sans-serif; } body { text-align: center; } h1 { font-variation-settings: 'wght' 400; font-size: 5rem; animation: letters 5s ease forwards; color: #212121; } [data-char="E"], [data-char="D"], [data-char="V"] { font-variation-settings: 'wdth' 100, 'wght' 800; animation: specialChars 5s ease forwards; position: relative; z-index: 1; } @keyframes letters { 100% { font-variation-settings: 'wght' 700; letter-spacing: -0.045em; } } @keyframes specialChars { 50% { color: red; } 100% { font-variation-settings: 'wdth' 800, 'wght' 200; color: red; } } @media (min-width: 60em) { body { padding: 3rem; } } |
That’s It. Now you have successfully created CSS Variable Font Style With Split Character, Variable Text Animation. If you have any doubt or question comment down below.
Thanks For Visiting, Keep Visiting.
How to add video player in blogspot post blogger website
You can create youTube channel and then add youTube channel video link in your blogspot blog. Video automatically added