O'Reilly logo

Firefox Hacks by Nigel McFarlane

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #69. Make New Tags and Widgets with XBL

Don't like the set of HTML or XUL tags that browsers provide? Make new ones.

The HTML and XHTML standards allow a content author to extend the set of composition elements on a web page by applying special styles to the <div> and <span> tags and their content. A styled <div> block might appear to be a navigation bar, an advertisement, or some other specialized content that HTML does not explicitly define. XML Binding Language (XBL) is an alternate strategy for naming features of web pages. This hack shows how you might use it.

XBL is a Mozilla technology that's slowly being adopted by the W3C. It first appeared at the W3C as a technical note at http://www.w3.org/TR/2001/NOTE-xbl-20010223/. More recently, it has entered the formal standardization track via the sXBL standard (the s indicates that XBL's initial standard use is in SVG). That standard is here: http://www.w3.org/TR/sXBL. Mozilla XBL syntax is not yet the same as the W3C syntax, but the concepts are all the same. It will match the standard one day.

In Firefox, XBL is used to create a new tag for any XML or HTML dialect, but most frequently for XUL. Public or strictly conforming HTML and XHTML documents should not be hacked with XBL. Use it for custom, private documents only. An XBL binding written in XML is attached to a tag using a Mozilla-specific CSS style:

tagname { -moz-binding : url("binding-definition.xml"); }

It's also possible to say the binding is bound to the tag, but the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required