O'Reilly

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.

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

Recent Features

  • Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

  • LightFace:  Facebook Lightbox for MooTools

    One of the web components I've always loved has been Facebook's modal dialog.  This "lightbox" isn't like others:  no dark overlay, no obnoxious animating to size, and it doesn't try to do "too much."  With Facebook's dialog in mind, I've created LightFace:  a Facebook lightbox...

Incredible Demos

  • Create a Clearable TextBox with the Dojo Toolkit

    Usability is a key feature when creating user interfaces;  it's all in the details.  I was recently using my iPhone and it dawned on my how awesome the "x" icon is in its input elements.  No holding the delete key down.  No pressing it a...

  • Smooth Scrolling with MooTools Fx.SmoothScroll

    I get quite a few support requests for my previous MooTools SmoothScroll article and the issue usually boils down to the fact that SmoothScroll has become Fx.SmoothScroll. Here's a simple usage of Fx.SmoothScroll. The HTML The only HTML requirement for Fx.SmoothScroll is that all named...

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!

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...