How to make blinking text using HTML and CSS
Contents
In many websites, we might have seen the blinking text that is used to get the visitors attention or announce the importance message. Examples : Offers and Discounts in e-commerce websites. Lets create the blinking text using HTML and CSS.
HTML code to assign blinking class
Here we are using the HTML span tag to give the blinking text. Then we have assigned the class name as blinking for this tag. Using the CSS code, we can define the style/animation properties for this text.
1 |
<span class="blinking">Upto 50% Offer</span> |
CSS code to add the animation and style properties
The @keyframes rule specifies the animation code for the blinking text. Inside this rule, we can specify the transparency of the text using opacity property.
For the blinking class. we have defined the style properties such as background colour, font properties, size of the text in the below code.
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 |
<style type="text/css"> /* Set the size, colour, font properties for the blinking text */ .blinking { animation: blinkingText 1s infinite; font-family: futura; font-style: italic; width: 100%; margin: 0 auto; text-align: center; color: white; font-size: 45px; background-color: #fc030b; } /* Specifies the animation and transparency for the blinking text */ @keyframes blinkingText { 0% { opacity: 0; } 50% { opacity: .5; } 100% { opacity: 1; } } </style> |
Example : Blinking text with single colour
Blinking text with multi colour using CSS
In the previous text, we have used single colour for blinking. Lets add multi colour for the blinking text using HTML and CSS. In the @keyframes rule, we need to specify the from color and to colour for multi colour blinking as below.
1 2 3 4 5 6 7 8 9 10 |
@keyframes blinkingText { from { opacity: 1; color : yellow; } to { opacity: 0; color : white; } } |
The from colour given as yellow and to colour given as white. Initially text will blink in the yellow colour and then it changed to white colour.
Output : Blinking text with multi colour
Complete HTML and CSS code for your reference
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 |
<html> <head> <style type="text/css"> .blinking { animation: blinkingText 1s infinite; font-family: futura; font-style: italic; width: 100%; margin: 0 auto; text-align: center; color: white; font-size: 45px; background-color: #fc030b; } @keyframes blinkingText { from { opacity: 1; color : yellow; } to { opacity: 0; color : white; } 0% { opacity: 0; } 50% { opacity: .5; } 100% { opacity: 1; } } </style> <body> <span class="blinking">Limited offers</span> </body> </html> |
Recommended Articles