- How to Create a Blinking Effect with CSS3 Animations
- Solutions with CSS animations
- Example of creating a blinking text effect with CSS3 animations:
- Result
- Example of adding a blinking text effect:
- Example of creating a blinking background:
- HTML Tag
- Syntax
- Attributes of Tag
- How to Use Tag in HTML?
- Example
- Example 1: Using JavaScript to Create a Blinking Effect
- Example 2: Recreating the Blink Tag with CSS Animations
- Example 3: Blink Tag Not Working
- Styling the Tag
- Accessibility Concerns
- Browser Support
- Conclusion
- Learn More
- Мигающий текст на CSS для привлечения внимания
How to Create a Blinking Effect with CSS3 Animations
Often, the blinking effect is used to bring the users to the attention of some text on your website. If you need such an effect, try using CSS animations.
Solutions with CSS animations
CSS3 allows creating animation without any Javascript code. To have a blinking text effect, you also need the @keyframes rule. We use CSS animation by defining some keyframes for our blinking text animation and set the visibility to «hidden». In our example below, we also add the -webkit- extension to the animation property for more browser compatibility.
Example of creating a blinking text effect with CSS3 animations:
html> html> head> title>Title of the document title> style> .blink < animation: blink-animation 1s steps(5, start) infinite; -webkit-animation: blink-animation 1s steps(5, start) infinite; > @keyframes blink-animation < to < visibility: hidden; > > @-webkit-keyframes blink-animation < to < visibility: hidden; > > style> head> body> Here is a span class="blink">blinking span> text. body> html>
Result
Example of adding a blinking text effect:
html> html> head> title>Title of the document title> style> .blink < width: 220px; height: 50px; background-color: #342ab8; padding: 10px; text-align: center; line-height: 50px; > span < font-size: 26px; font-family: cursive; color: #fff; animation: blink 2s linear infinite; > @keyframes blink < 0% < opacity: 0; > 50% < opacity: .5; > 100% < opacity: 1; > > style> head> body> div class="blink"> span>blinking text span> div> body> html>
It is also possible to have a blinking background with CSS3 animations. Here also we create a set of keyframes and then specify the background-color at the starting and ending points.
Example of creating a blinking background:
html> html> head> title>Title of the document title> style> @keyframes blinking < 0% < background-color: #06c3d1; border: 3px solid #666; > 100% < background-color: #270da6; border: 3px solid #666; > > #blink < width: 200px; height: 200px; animation: blinking 1s infinite; > style> head> body> div id="blink"> div> body> html>
HTML Tag
The HTML tag is used to enclose text to create a blinking effect. Blinking refers to a light flashing on and off regularly or intermittently. However, the relevant web standards have removed this non-standard element.
Syntax
The blink element comes in pairs, meaning the tag has an opening and closing element.
Attributes of Tag
The tag is a non-standard element that helps the text to flash in a regular pattern. Since its functioning solely depends on the browser, the tag does not require any parameters and has no attributes.
How to Use Tag in HTML?
The text that needs to have a blink effect is enclosed within the HTML tag. It is written in line with the rest of the content, as shown below.
Note: Since the HTML tag is deprecated no visual effect is seen on using it. Though some browsers might still support it for compatibility purposes, most consider the element obsolete. It is recommended to not use this tag, and update existing codes to avoid compatibility issues, as the feature may stop working at any time.
Example
Example 1: Using JavaScript to Create a Blinking Effect
JavaScript can be used to add blinking functionality to desired elements. In this example, the following CSS code is used only for styling purposes.
Example 2: Recreating the Blink Tag with CSS Animations
CSS can add visual blinking effects in two ways.
- Using text-decoration property -Setting the value of the text-decoration property to blink can fetch the desired result in some cases. However, it is not a viable solution as most browsers do not support it.
- Using CSS animation — The goal can be achieved by setting CSS animations for the desired text using the @keyframes rule.
Example 3: Blink Tag Not Working
No visual effect is noticed since the web browsers consider the HTML tag obsolete. In this example, the following CSS code is used only for styling purposes.
Styling the Tag
The following example shows you different ways to style a HTML tag.
- In the first sentence, the blinking effect is applied by changing the text color.
- In the second sentence, the blinking effect is applied using opacity.
Accessibility Concerns
Blinking is constant flashing that results in a negative user experience. Reading such text becomes difficult and annoying as the text continuously turns on and off. As per the internet guidelines blinking texts are not user-friendly for people with disabilities. Users with cognitive problems and photosensitive epilepsy might experience seizures when viewing flashing content.
Browser Support
The recent versions of the standard browsers do not support the HTML tag. Though some old versions use it for compatibility, it is a better practice to avoid its usage.
Conclusion
- The HTML tag adds a slow flashy blinking effect to the text.
- The tag is not standardized by hypertext mark-up language and has now been deprecated.
- As most browsers do not support the HTML tag, a blinking effect can be created using CSS and JavaScript.
- Internet usage guidelines strongly advise avoiding the usage of the blinking effect, as it can cause problems for disabled users.
Learn More
Мигающий текст на CSS для привлечения внимания
Мигающий текст на страницах сайта привлекает внимание, а значит может применяться для размещения надписей с акциям и скидками в интернет-магазинах. Раньше реализации были основаны на javascript, но с появлением CSS 3-го поколения, создание мигающего текста упростилось.
Переливание цвета достигается посредством анимации. Для этого необходимо создать фреймы с указанием состояния элемента. Переход между фреймами будет плавно осуществляться в автоматическом режиме.
Первый вариант
В примере мы создали плавный переход от красного цвета шрифта к розовому и обратно. Блок @-webkit-keyframes blink и @keyframes повторяет фреймы, это из-за того что разные браузеры поддерживают разные свойства css анимации.
Этот вариант смотрится отлично на тёмном фоне. Он выглядит сложнее и должен дать понять что комбинируя различные свойства можно добиться множества вариантов пульсации и переливания надписей.
Второй вариант
Не следует забывать что мигающие надписи отвлекают посетителей от целевых действий и могут способствовать быстрому уходу с сайта. Поэтому размещать их следует так, чтобы они не раздражали и не мешали просмотру основного контента. Не делайте мигание слишком ярким, небольшой пульсации цвета будет достаточно.