WebKit Marquee CSS: Bringin’ Sexy Back

By  on  

We all joke about the days of Web yesteryear.  You remember them:  stupid animated GIFs (flames and "coming soon" images, most notably), lame counters, guestbooks, applets, etc.  Another "feature" we thought we had gotten rid of was the marquee.  The marquee was a rudimentary, javascript-like effect to move text from one side of a block to another.  I was recently looking at WebKit's CSS specs and found that Safari has implemented CSS marquees.

The CSS Format

.marquee {  
	overflow-x: -webkit-marquee;
	-webkit-marquee-direction: ahead|auto|backwards|down|forwards|inherit|left|reverse|right|up;
	-webkit-marquee-increment: small|medium|large;
	-webkit-marquee-repetition: {number};
	-webkit-marquee-speed: slow|normal|fast;
	-webkit-marquee-style: alternate|inherit|none|scroll|slide;
	font-size:1.4em;
}

There are five pieces to the marquee puzzle:

  • overflow-x:  Should be set to -webkit-marquee
  • -webkit-marquee-direction:  The direction of the marquee.
  • -webkit-marquee-increment:  The size by which to move.
  • -webkit-marquee-repetition:  The  number of times the marquee should repeat.
  • -webkit-marquee-speed:  The speed at which to move the ext.
  • -webkit-marquee-style:  The effect which the marquee should function.

CSS Marquee Usage

.marquee {  
	overflow-x: -webkit-marquee;
	-webkit-marquee-direction: backwards;
	-webkit-marquee-style: slide;
	-webkit-marquee-speed: fast;
	-webkit-marquee-increment: large;
	-webkit-marquee-repetition: 6;
	font-size:1.4em;
}

The example uses each of the marquee properties given above and should be straight forward.  If you choose to use WebKit's marquee, experiment with the settings to make sure the marquee does what you want.  When it doesn't, fix it with JavaScript...or question why you're using a marquee at all.

No word yet on when the WebKit team plans to implement a CSS counter.  I'm sure I'll do a tutorial on it when the time comes.

Recent Features

  • By
    How I Stopped WordPress Comment Spam

    I love almost every part of being a tech blogger:  learning, preaching, bantering, researching.  The one part about blogging that I absolutely loathe:  dealing with SPAM comments.  For the past two years, my blog has registered 8,000+ SPAM comments per day.  PER DAY.  Bloating my database...

  • By
    I’m an Impostor

    This is the hardest thing I've ever had to write, much less admit to myself.  I've written resignation letters from jobs I've loved, I've ended relationships, I've failed at a host of tasks, and let myself down in my life.  All of those feelings were very...

Incredible Demos

  • By
    MooTools-Like Element Creation in jQuery

    I really dislike jQuery's element creation syntax. It's basically the same as typing out HTML but within a JavaScript string...ugly! Luckily Basil Goldman has created a jQuery plugin that allows you to create elements using MooTools-like syntax. Standard jQuery Element Creation Looks exactly like writing out...

  • By
    Link Nudging with CSS3 Animations

    One of the more popular and simple effects I've featured on this blog over the past year has been linking nudging.  I've created this effect with three flavors of JavaScript:  MooTools, jQuery, and even the Dojo Toolkit.  Luckily CSS3 (almost) allows us to ditch...

Discussion

  1. Why not go all the way and make it work in firefox?

    https://developer.mozilla.org/en/HTML/Element/marquee

  2. While I agree (strongly) with garyb that one should make all effects work in as many browsers as possible, Firefox – and in fact almost any other browser on the planet – support the marquee element, not the marquee CSS-rule. Firefox has chosen to use an XBL-binding in their internal stylesheet.

    In fact, one can make lots of XBL-bindings through CSS in Firefox, not only marquees. But that is not recommended. The Webkit marquee CSS property is also intended for internal usage as a way to support the marquee element.

    And yes, browsers do support some elements that have not been formally standardized. That does not mean one should use them, though.

  3. inder

    How to make is stop on hover? and please can you give me an image slider like blogger homepage which auto scrolls but also have arrows to slide them fast :)

    thanks

  4. how to add google adsense code in marquee ?

  5. To do the hover, simple apple a regular hover style in the normal way and change the scroll speed in the hover style! Enjoy! :)

  6. Personally, I never had a problem with marquee.. Altho its great to see it as a css class I dont see any reason why you cant use the html tag as before. At least you can be sure it will work on all browsers. Then us css to style it.

    Just my 2 cents :)

  7. Mats

    Good article, however the Demo does not work. For me. Google Chrome v23.

    Another reflection, I tested to use marquee on some table cell that has overflow:ellipsis applied and overflow-x does not overwrite the ellipsis so you get scrolling cut of text. Fugly.
    Maybe I should file a bug with the webkit team… :)

    • Yeah! overflow > overflow-x.

      a {overflow:hidden;text-overflow:ellipsis}
      a:hover {overflow-x: -webkit-marquee;text-overflow:string}
      

      = The link will scroll, but with truncated mode.

      a {overflow:hidden;text-overflow:ellipsis}
      a:hover {overflow-x: -webkit-marquee;text-overflow:string;overflow:visible}
      

      = The link won’t scroll, but without truncated mode.

  8. I’ve been looking for the most efficient and cross-browser marquee implementation. For whatever reason, even the webkit CSS marquee implementation is glitchy. The common approach is to use timer (or jQuery animate implementation) to adjust the CSS margin property of the element. This is too glitchy and very inefficient. I came up with implementation that utilises CSS3 transitions for browsers that support it and otherwise animate the scrollLeft property of the containing element. It is an experimental implementation, though it works well with IE7+. Other people might find it useful as well, https://github.com/gajus/marquee (demo https://dev.anuary.com/60244f3a-b8b2-5678-bce5-f7e8742f0c69/).

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