MooTools Typewriter Effect Plugin

By on  

Last week, I read an article in which the author created a typewriter effect using the jQuery JavaScript framework. I was impressed with the idea and execution of the code so I decided to port the effect to MooTools. After about an hour of coding, I had a smooth, customizable Mootools class that accomplished the same goal. Without further adieu, here's my MooTools 1.2 Typewriter plugin.

The MooTools JavaScript Class

//class is in
var Typewriter = new Class({
	Implements: [Options],

	options: {
		container: $(document.body),
		message: '',
		delay: 150,
		cursor: 0
	initialize: function(options) {
		//set options
	//start the typewriter
	start: function() {
		//for every letter
		for(x = 0; x < this.options.message.length; x++) {
			//spit out the letter
			var id = this.setLetter.delay(this.options.delay * x, this);
	//place the newest letter in the container
	setLetter: function() {
		this.options.container.set('html',this.options.container.get('html') + '' + this.options.message.charAt(this.options.cursor));
		//increment cursor

Once the class is initialized, options get set (also note the class defaults). Once the start method is called, we loop through every character and call setLetter() to place the next character into the container after the specified delay.

The Usage

var t = new Typewriter({
	container: $('type-here'),
	message: 'This is output from the typewriter class. This class is small but packs a good punch. Isn\'t MooTools great?',

When creating your typewriter, you can pass it the following parameters:

  • container:: What element would you like the typewriter to write to?
  • message:: What do you want the message to be?
  • delay:: How much time would you like between letters?
  • cursor:: What position in the message (which character) do you want the Typewriter to start at?

Once you're ready for to start the typewriter, you'll call the start() method.

O'Reilly Velocity Conference
Save 20% with discount code AFF20

Recent Features

  • Introducing MooTools Templated

    One major problem with creating UI components with the MooTools JavaScript framework is that there isn't a great way of allowing customization of template and ease of node creation. As of today, there are two ways of creating: new Element Madness The first way to create UI-driven...

  • Serving Fonts from CDN

    For maximum performance, we all know we must put our assets on CDN (another domain).  Along with those assets are custom web fonts.  Unfortunately custom web fonts via CDN (or any cross-domain font request) don't work in Firefox or Internet Explorer (correctly so, by spec) though...

Incredible Demos

  • dwImageProtector Plugin for jQuery

    I've always been curious about the jQuery JavaScript library. jQuery has captured the hearts of web designers and developers everywhere and I've always wondered why. I've been told it's easy, which is probably why designers were so quick to adopt it NOT that designers...

  • CSS Kwicks

    One of the effects that made me excited about client side and JavaScript was the Kwicks effect.  Take a list of items and react to them accordingly when hovered.  Simple, sweet.  The effect was originally created with JavaScript but come five years later, our...


  1. would be nice if as an option you could implement some “typo” function, so randomly to mistype some chars and delete it.
    i think is just some “fancy” feature, but i thought you might like it :)

  2. @rborn: Awesome idea! I’ll think about those possibilities. Good suggestion.

  3. Catar4x

    Yes, Mootools is great !

  4. Amazing! Thanks you!

  5. I also think you should have the _ after the character its typing :D

  6. Darren

    Good work. It would be nice to be able to pass a string to the start function so you can add more to the string again with a second call. Or overwrite the first string. I also second the typo option and underscore option.

  7. Just a brain fart

    But it would be really cool if it was possible to overlay the text with something grunge, that would crack up the text link text

    Fontface embedding is properly the easiest way, but anyone have a idea with a image overlay/underlay that moves with the text?

  8. @Esben: I think the only way to this is writing a script which works with sIFR because this is the best way to embed only fonts I think.

  9. @Esben and @Mattias

    what about some png overlay, as css gradient text technique?

    would this be possible with a grunge pattern ?
    will not become a really typewriter font, but….

  10. @rborn:
    Nice idea! It should work I think. You need to know the height of your typewriting font and then you could create a seamless grunge-texture (as transparent PNG). The method could be creating a DIV-overlay (with the PNG as background-image) that changes it “width”-value referring to the amount of the typewrited letters. A problem would be the whitespaces I think but it would be a way.

  11. @Mattias

    if u go here


    there is a “wow zebra” that seem to do the trick

    i think is just a matter image from there :)

  12. Ah yes alright – there isn’t a problem if you a have plain-colored background. I thought of a complex background (like a graphic or stripes). But the trick is very nice although. I’ll try that out later!

  13. Badchenn

    Another enhancement idea… As you know, we don’t always type at a steady speed. How about adding a speed variation? Maybe a range? Let’s say delay:100 variance:20 (where the variance could be a percentage of the delay setting). This along with the random worng letter/backspace feature would be cool.

  14. @Badchenn: Another great idea!

    Keep them coming everyone.

  15. @All: Version “2” is coming very soon. Any more suggestions before I release it to the world?

  16. Hi David,

    good work.

    My suggestions:

    Multiple messsges.
    Leading character (as seen on http://www.bbc.co.uk/news ticker)

    Hmm… not sure about rborn’s random mistype addition – from a user’s point of view I can see that being quite annoying.

    Still – I guess implementers don’t have to use that feature ;)

  17. Hey,

    I saw that you had used trackbacked me and thought I’d see what was going on.

    Awesome stuff. I’m glad that my code inspired you, and even across two different javascript frameworks. I was looking at the blinking underscore idea as someone else suggested and I actually finished doing it but never though that it was a feature anybody wanted. Guess I was wrong.

    Again thanks for the trackback and good luck with you Mootools class. :-)

  18. Greg

    Hey David,

    I was excited to find your Typewriter class. However, I’m using mootools 1.1 and receive the following error when I try to use it:

    this.options.container.get is not a function

    Any idea why? I assume it’s a version issue. Is it possible to tweak the class slightly to work with 1.1? I prefer not to deal with using 1.2; doing so breaks a lot of other script.


  19. sam

    Hi is there a way to have a few of these on one page each starting with an onclick

  20. Javascript newbie here. How would I make this start from an onClick instead.

  21. You would change the usage code to only fire on the click event.

  22. Rashy

    Hey David,

    Can you make a jQuery version of this plugin too ? Can you also add an option to add a arbitary text like “_” (Underscore) to the effect and delete it when the effect finishes. Eg:


  23. Nice article but I think it needs to support rich format really… I.e. allow the text to have html tags within it so people can type out text that becomes a hyperlink. Admittedly could attach an event within the panel that loads the content, i.e. change the cursor to a hand, and even addClass to the text so it behaves like a normal hyperlink but I’m wondering whether or not that’s the best approach? Probably is, just a thought…

  24. Great script! Can you tell me how I can use a chain on this script? I want another script to be executed when the typewriter finishes. Thanks in advance!

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!

Recently on David Walsh Blog

  • Prevent Chrome from Translating a Page

    A while back I shared my favorite Google Chrome extension:  Google Art Project.  I've enjoyed seeing beautiful art when I open a new tab -- it's brought genuine happiness to my day, however small that happiness may be.  About a week ago, however, the art presented had...

  • Create Any Type Of Website With These Multi-Purpose Themes

    We have selected what we believe are the very best multipurpose WordPress themes on the market today. Our list contains a number of best sellers, several newcomers that are proving to be highly popular, and a few themes that are ideal for creating the types of...

  • An Introduction to Static Site Generators

    Static site generators seem to have been becoming more and more popular recently, but they’re not one of those ephemeral novelty things that grow in popularity as quickly as they fall into oblivion shortly after. For over a decade, many different projects — 394 of...

  • Automated Tests for Visual Responsive Layouts

    Today it's all about testing. In 2015, many developers knows about TDD and I personally think that testing is one of the key for quality products. But what about testing in a Front-end environment? How do you guys write your tests for a responsive page or...

  • Getting Dicey With Flexbox

    What if you could build complex CSS layouts in minutes? Flexbox is a new CSS layout spec that makes it easy to construct dynamic layouts. With flexbox, vertical centering, same-height columns, reordering, and direction agnosticism are a piece of cake. There's a popular myth floating around that...