Apparently a battle of sorts has erupted amongst devs clamoring for the title of Best Typewriter Animator Person.
- @alvaromontoro started with a Typewriter effect in CSS
- @afif then gave us A scalable CSS only Typewriter Effect
- @inhuofficial has promised us an HTML-only typewriter
- And @alvaromontoro came back with an Animated no-element typewriter
In the classic spirit of one-uppery that has arisen, it was only a matter of time before someone, somewhere took on the most legendary of tasks: to create a typewriter animation for the web without using anything. No Javascript. No CSS. Not even HTML.
Behold, the power of Scalable Vector Graphics.
Ok but actually don't use this if you want a typewriter animation! It's got browser compatibility and accessibility issues, but at least it's a cute experiment.
How it works
The SVG spec has something called Synchronized Multimedia Integration Language (SMIL) which allows animations to be defined in the XML document directly.
For example, consider the animate tag. When made a child of some shape like rect
, you can choose what attribute to animate over time and specify the way in which it changes.
So for example, the text cursor is given a simple blink animation just by adjusting the width of a rectangle between 0 and 1, and doing it discretely so it blinks:
<rect fill="black" x="0" y="4" width="1" height="12">
<animate
attributeName="width"
calcMode="discrete"
values="1; 0"
dur="1s"
repeatCount="indefinite" />
</rect>
This is the first time I've ever used SMIL, so almost certainly someone smarter than me can find a better way than adjusting an overlaying white rectangle!
Top comments (12)
Nice 🙂
Wait... No multiline? I may need to revoke the "nice" comment 😋
But seriously, this looks really nice. Good entry. And welcome to the "fight."
Lol, no multiline, hardcoded magic numbers, and the background has to be white! Truly the height of flexible code 😆
oh, a new warrior!
PS: add some tags to your post to get some visibility (the #webdev and even #html can fit, also #codepen and the #SVG of course)
Thanks! Totally forgot to do that ^^'
Nice. I like.
But I think it a tad extreme to claim no HTML. I mean the svg tag is... er, HTML, not?
It's Schrödinger's tag. It's HTML and it's not. It's markup not HTML but HTML "supports" it. So if browser supports it while rendering it's HTML. But not really. I think you see how this could be series of blog posts by itself.
Technically, there's a clause in the HTML spec for the
svg
element; but, you could also save this as a literal*.svg
file and load it up in a browser, hence HTML isn't necessary!Or a different way of putting it, I technically used HTML to present it in this post, but only used features provided by the SVG specification 😊
Nah, that's considered SVG as it's present within an SVG file anyways I believe
Even my sacred SVG isn’t safe from people beating me to the punch.
Just so you know Temani normally needs a health warning on SVG stuff as the lack of CSS causes him pain! 🤣
Ah, SVG, very nice! It's probably one of the most underappreciated technologies on the web :D
I created a CSS-only (no HTML or JS) typewriter 2½ years ago and feel it’s worth a mention… 👀
twitter.com/branmcconnell/status/1...