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
    Write Better JavaScript with Promises

    You've probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don't see what makes them so special. Can't you just use a callback? What's the big deal? In this article, we'll...

  • By
    6 Things You Didn’t Know About Firefox OS

    Firefox OS is all over the tech news and for good reason:  Mozilla's finally given web developers the platform that they need to create apps the way they've been creating them for years -- with CSS, HTML, and JavaScript.  Firefox OS has been rapidly improving...

Incredible Demos

  • By
    Telephone Link Protocol

    We've always been able to create links with protocols other than the usual HTTP, like mailto, skype, irc ,and more;  they're an excellent convenience to visitors.  With mobile phone browsers having become infinitely more usable, we can now extend that convenience to phone numbers: The tel...

  • By
    New MooTools Plugin:  ElementFilter

    My new MooTools plugin, ElementFilter, provides a great way for you to allow users to search through the text of any mix of elements. Simply provide a text input box and ElementFilter does the rest of the work. The XHTML I've used a list for this example...

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!