In this round-up we’ll be looking at 5 JavaScript libraries that can really ease the development of modern, attractive web sites. The libraries that we’ll be looking at aren’t libraries in the same sense as something like jQuery or the YUI; they’re much smaller and much more specialized. But they’re the best at what they do and provide unique functionality.
5 Lesser Known JavaScript Libraries that Make Web Design Easier
Sep 28th in Web Roundups by Dan Wellman1. Fixing PNGs in IE6 with DD_BelatedPNG
- Created by: Drew Diller
- License: MIT
- Usage: Fixes alpha-transparent PNGs in IE6
- Size: 6.86kb (compressed)
- Compatibility: IE6 only
- View Demo
- Download
DD_belatedPNG was created for the single purpose of allowing alpha-transparent PNGs to be used in IE6 without resorting to Microsoft’s proprietary AlphaImageLoader filter. As anyone who’s tried to use PNGs in IE6 before knows, although they can be made to work to a very basic degree, things like repeated background-images are out of the question.
Using the AlphaImageLoader filter only fixes half of the PNG problem in IE6 as it can only be used with background images. To make use of alpha-transparent PNGs on <img> elements, another fix is used, which is typically the HTC fix which relies on a transparent PNG and an HTC behavior file. Additionally, as Firebug and YSlow users will be aware of, Microsoft’s AlphaImageLoader is slow; one of YSlow’s guidelines is to avoid the filter at all costs.
DD_belatedPNG uses Microsoft’s implementation of VML to replace PNGs with VML elements, which do support alpha-transparency. It can be used with both full <img> elements and CSS background-images. When background-images are replaced, common features such as background-repeat and :hover states can also be used so this library solves all of the common PNG problems in IE6.
Usage
Using DD_BelatedPNG is exceptionally easy; it only needs to be used with IE6, so the main script can be included in the page using a conditional comment:
<!--[if IE 6]> <script src="DD_belatedPNG.js"></script> <![endif]-->
The library has a single method, fix, which is used to supply simple CSS selectors that are targeted by the library, any <img> element that has a PNG src attribute, or any element using a PNG CSS background with the matching class name will be fixed. This part of the script can go into the conditional comment as well so that only IE6 will need to process these additional rules:
<script type="text/javascript">
DD_belatedPNG.fix(".linkButton");
</script>
Fixed PNGs in IE6 will now appear as they should and can be background-positioned and repeated, and also work with :hover states, unlike Microsoft’s proprietary filter. The following image shows a before and after picture of an alpha-transparent background image:
2. Use any Font with Cufon
- Created by: Simo Kinnunen
- License: MIT
- Usage: Allows embedding of non-standard fonts without needing flash
- Size: 17.8kb (compressed)
- Compatibility: All (all common versions from all common vendors, including IE6)
- View Demo
- Download
Typography is one area of web development that has seen painfully little advancement when compared with other areas of the industry. Web developers have been forced to rely on a small set of ‘web safe’ fonts that are likely to be installed on the majority of their visitor’s computers. Image and flash-based solutions have arisen, both of which have downsides to using.
Cufon offers developers a robust and fast solution, which can be displayed in the browser without requiring third-party plugins using features built in to browsers. Cufon fonts can be used as VML for native IE implementation, or the <canvas> element for other more capable browsers. Awesomely, we can also set different styles of the replaced text, such as its color and size using pure CSS.
Usage
This library differs from the others in that a little bit of preparation is required before use; a new font file needs to be generated which can be done easily using the cufon website. The will generate an SVG font and save it in a JS file. This file needs to then be linked to any other <script> resource after the cufon core file:
<script type="text/javascript" src="cufon.js"></script> <script type="text/javascript" src="Breip_500.font.js"></script>
Then it’s just a case of telling Cufon which elements to replace:
<script type="text/javascript">
Cufon.replace('h1.replacedFont');
</script>
The API offers other solutions for using multiple fonts on the same page and for improving performance in IE. Although I’ve called this section, "Using any Font"… you should remember that only fonts that are licensed to be embedded should be used. The following screenshot shows a replaced heading:
3. Use Firebug in any Browser
- Created by: Mike Ratcliffe
- License: BSD-style
- Usage: All the power of Firebug in browsers other than Firefox
- Size: 76.9kb (compressed)
- Compatibility: All non-Firefox browsers
- View Demo
- Download
Firebug is without doubt one of the greatest assets to web development available; I certainly use it on a daily basis when developing for the web, and I know it’s the plugin of choice for many others too. An unfortunate side-effect of Firebug’s excellence is that other similar tools for other browsers pale in comparison and appear inferior. Trouble-shooting layout issues and CSS bugs in IE for example can be a lesson in futility.
This is where Firebug Lite steps in; this is a simple JavaScript library that recreates most of the key features of the Firebug interface, bringing our debugger of choice to all other platforms. Fixing layouts and troubleshooting cross-browser issues becomes easy once more.
One of the greatest things about Firebug Lite is that you don’t need to download it or install anything in order to start using it; when you want to debug a page you’re working on in browsers that aren’t Firefox you can just include a script file whose SRC points to the online version:
<script type="text/javascript" src="http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js"></script>
That’s it, when you run the page in any other browser, Firebug Lite will be present on the page. For off line use, the script file, as well as a CSS file, can be downloaded and should just be used like any other JS or CSS file. The following screenshot shows Firebug Lite in Safari:
4. Render Interactive 3d Shapes with Raphael JS
- Created by: Dmitry Baranovskiy
- License: MIT
- Usage: Draw SVG shapes on the page
- Size: 58.4kb (compressed)
- Compatibility: All (all common versions from all common vendors, including IE6)
- View Demo
- Download
Ok, so this library isn’t quite so small, but there’s a reason for that; the library does a huge range of things and adds complete SVG control to a web page. Frankly, its power is awesome. Imagine being able to draw smooth curves across a web page and create custom shapes on the fly – Raphael does that.
You can do rounded corners that are completely cross-browser with no images (other than those actually drawn by the library), you can create faded reflections for any images, rotate the images dynamically and much more. As all paths are drawn using SVG elements, you can attach JavaScript events to them so that people can interact with the images on mouseover or click (or any other JS events). The possibilities are endless and the API provides a wide range of different methods that make working with the library a pleasure.
Usage
The library must of course be linked to:
<script type="text/javascript" src="raphael.js"/>
This is it, there are no other dependencies. Now we can begin creating our SVG shape:
<script type="text/javascript">
var canvas = Raphael(50, 50, 620, 100);
var shape = canvas.rect(0, 0, 500, 100, 10);
shape.attr("fill", "#fff");
canvas.text(250, 50, "Using Raphael to create custom shapes\ndrawn on the fly is extremely easy").attr("font", "20px 'Arial'");
</script>
The library is made to be easy to use and we’ve only used a tiny fraction of its capabilities in this example. The page that this is used on should appear like this:
5. Progressively Enhance Your Site into the Future with Modernizr
- Created by: Faruk Ateş and Paul Irish.
- License: MIT
- Usage: Detect HTML5 and CSS3 support
- Size: 7kb (compressed)
- Compatibility: All
- View Demo
- Download
It’s an exciting time for web development with CSS3 and HTML5 advancing by the day, but it’s also a frustrating time because we’ve got all these advanced new technologies coming out with very little support. We want to start using all the great new HTML5 and CSS3 features, but most of the new HTML5 elements for example are only supported in maybe a single browser.
Modernizr is a tiny little library which simply tests whether the current environment supports a series of advanced features, such as the new <audio> and <video> elements. A JavaScript object is then created by the library which contains Booleans indicating whether each feature is supported. So if the current browser does support the new <audio> element, Modernizr.audio will return true. It’s that simple.
The library also adds class names to the <html> element that we can target with CSS in order to hide certain elements to the page, so when the <audio> element is supported, <html> element will receive the class name .audio. When browsers that don’t support it view the page, the element will get the class .no-audio.
This is incredible because it means that we can safely add these new features to our pages for the browsers that do support them, without causing chaos in the browsers that don’t. In the nature of progressive enhancement, we can create an accessible and broadly support core of content, and then progressively add more and more features for browsers that support them.
Usage
Let’s see it in action to display some nice CSS3 effects; first we just link to the very tiny library using the standard <script> element:
<script type="text/javascript" src="modernizr-1.0.min.js"></script>
Then we can add the following CSS:
.no-audio #audioContainer { display:none; }
This will ensure that browsers which do not support the <audio> element do not see it. The element does provide a built-in fallback for browsers that don’t support it, but this way is better. The body of the page could then look something like this:
<div id="audioContainer">
<audio id="audio" src="http://upload.wikimedia.org/wikipedia/en/7/77/Jamiroquai_-_Snooze_You_Lose.ogg" controls"true"></audio>
</div>
<a id="linkToAudio" href="http://upload.wikimedia.org/wikipedia/en/7/77/Jamiroquai_-_Snooze_You_Lose.ogg">Link to the audio</a>
Once this is done we can detect whether the browser supports HTML5 audio and show or hide the link to the media (we could easily do this using just the CSS, but this way we get to see the Modernizr object in action):
if (Modernizr.audio) {
var audioLink = document.getElementById("linkToAudio");
audioLink.style.display = "none";
}
This is all we need; capable browsers will see the <audio> element but not the link, while less capable browsers will see the link and not the <audio>:
Conclusion
Each of these libraries caters to a very specific problem; they’re generally much smaller than more well known and general purpose libraries, but just as useful for their specialized purpose. Each of them can aid us in one way or another when developing web sites from either easing development in IE6, using non-standard fonts without cumbersome replacement techniques, to detecting support for the latest CSS3 and HTML5 technologies or generating complex and interactive images.
- Follow us on Twitter, or subscribe to the Nettuts+ RSS Feed for more daily web development tuts and articles.
Related Posts
Check out some more great tutorials and articles that you might like
Plus Members
Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.










User Comments
( ADD YOURS )Benjamin Reid September 28th
Thanks for ‘3. Use Firebug in any Browser’, I didn’t know that. *dissapointed face*
( )Slobodan Kustrimovic September 29th
Don’t be dissapointed, it doesn’t work perfect. To be honest the IE Developer is much better when you must work with IE.
And yes, microsoft made the IE Developer and it’s quite good (strange, but it’s true).
Who knows maybe they will make something even better soon, something we will all be happy with, and that is – change business, maybe open a pizzeria or something, maybe NOT, i don’t like bugs on pizza.
( )David September 28th
As far as Firebug Lite goes, you can go to this page on their site:
http://getfirebug.com/lite.html
And drag a bookmarklet to IE, Safari, IE. Then you can use firebug on-demand (as it’s intended) instead of actually having to put the include script on the webpage.
( )Rahul September 28th
It also works with chrome… Oh.. Thanx a lot.. Its great
( )aryan September 29th
awesome! I was looking for this
( )Stefan September 28th
Think the article got cut off in the middle of the sentence there at the end…
( )Jason | Five Finger Coding September 28th
Nice collection. It’s good to see something other than jQuery. I particularly like Cufon because it’s easy to implement and allows you to add some unique typographic touches to a design. The fewer creative limitations, the better.
( )Firs Yura September 28th
This is only a small part of what you can use the designer!
( )But at this thank you)))
IgnacioRV September 28th
Firebug in any browser? cool… going to try it now on IE
I played a little with Modernizr a while ago. I’ve found it ok for small websites but I don’t know how useful could it be for large projects… because it could really mess up the stylesheet or javascripts.
( )Patrick September 28th
please check point 2’s and 3’s HTML code – theres something wrong….
( )Jeffrey Way September 28th
Yeah – fixed it. Of course, right before I scheduled it last night, I added a link to Cufon and didn’t close the href correctly!
( )Simon September 28th
Thanks for the nice article !
Already knew most of the libraries in this list but anyway !
Juste one advice, be carefull with firebug as bookmarklet ! Browsers like IE 6 are kind of weak when having to deal with JS, meaning they could freeze or even crash (already happened quite often to me) !
Still, thanks !
( )adam16ster September 28th
I don’t see much usage of raphaeljs out in the wild. For something simple like rounded edges, would you recommend raphael over an image? Which will load faster? Or should raphaeljs just be used for more complex tasks?
I’m not so sure raphaeljs.com is even using its library for its rounded corners.
( )Dan Wellman September 29th
No, for something as simple as rounded corners I’d not recommend RaphaelJS, but for the example I needed something quick and basic that didn;t require lots and lots of code
Check the Raphael site for some *extremely* cool examples of it’s power
( )GaVrA September 28th
“The following screenshot shows Firebug Lite in Safari:”
It is showing screenshot of Firebug Lite in Internet Explorer…
( )Dan Wellman September 29th
lol, typo on my part…I think I was wishing I was using Safari
( )Neil September 28th
#3 is amazing… I didn’t know you could do this!
( )Jeffrey Way September 28th
Sorry for that formatting glitch from earlier.
( )zcorpan September 28th
“This is all we need; capable browsers will see the element but not the link, while less capable browsers will see the link and not the :”
Dude, you’ve just reimplemented something that is already supported natively by design.
<audio src><a href>link</a></audio> does the exact same thing. (Also, an empty audio will just render nothing in old browsers; no need to set display:none to it.)
In many cases you don’t actually have to test support for a feature, you can just use it and fall back to something else for old browsers.
( )Dan Wellman September 29th
Sure, in the basic example there are other fallbacks we could make use of, howerver usually the fallback is just a line of text that says ‘Sorry your browser does not support this…etc’ – which can look pretty bad…
And modernizr works with many advanced CSS, which of course doesn’t have native fallbacks (unless you count simply not being applied as a fallback)
( )zcorpan September 29th
There’s no reason you have to say “Sorry your browser does not support this” in the fallback, so that’s not a valid argument.
Agreed that fallback for CSS features is harder, but in some cases possible nonetheless. Consider wanting a semi-translucent background, and falling back to a PNG background image:
#foo { background:url(foo.png); background:rgba(255, 255, 255, 0.5) }
If rgba() is not supported, the second declaration will be dropped. If it is supported, it overrides the first declaration.
Dan Wellman September 29th
of course
perhaps the example was extremely lacking when it comes to demonstrating modernizr’s usefulness
but it’s still a very effective, very good library with a place in every forward-thinking web-developer’s box of tricks. It’s extremely useful and gives you more options when using new features that aren’t universally implemented. Sure the built-in fallback will be effective in some browsers, but there’s a possibility that very old browsers will choke and die on new elements rather than displaying the fallback. At least Modernizr gives us options
jaded September 28th
#2 is misleading. You can’t just use any font with cufon. You must use a font whose EULA permits web embedding. That aside, cufon is awesome.
( )RussellUresti September 28th
DD_belatedPNG is definitely the best PNG fix for IE6 that I have found, and I’ve tried many. It works consistently well with background images, content areas, links, and anything else. No transparent .gif needed.
And, as stated by jaded, #2 isn’t exactly “any font”, in fact, the number of fonts is quite limited. Though, Cufon’s site does a pretty decent job outlining which foundries play nice and which don’t. Make sure your EULA gives web embedding a thumbs up before you go using this.
( )Dan Wellman September 29th
yeah, I mentioned at the end of the description that only fonts licensed for embedding should be used…although there isn’t a huge range of fonts available for this right now the list is growing all the time
( )jaded September 30th
Yeah but you titled the section Use ‘Any’ Font.
Dan Wellman October 2nd
You can use ‘any’ font, but using some fonts in some situations may get you into trouble. Needing to check the license of something is not the same as not being able to use it point blank. The generator will still generate the font, even if it is against copyright to actually use it…
And I’m not sure the heading ‘Use any font you like provided it has been licensed for embedding and/or displaying on a website, and not just with flash’ would have had quite the same impact…
Faruk Ateş September 28th
The example page you’ve created for Modernizr should be updated to include both a .ogg and a .mp3 (or .m4a) audio file, because Safari doesn’t support .ogg — that’s a Firefox 3.5 thing, only.
Your explanation of Modernizr also seems to have been cut off abruptly?
( )Dan Wellman September 29th
thanks for reading Faruk
in a proper implementation of Modernizr the different audio fomats should be taken into consideration of course, but I felt the example was enough for this simple demo
The text hasn’t been cut off, but there should have been another image showing the fallback in IE…
( )Bronson Quicj September 28th
Thanks very much for the article. I only recently found out about Firebug Lite as well and it can come in particularly handy.
I wasn’t aware of Modernizr before so I’ll definitely be having a play around with that later today!
( )Ben September 28th
Wow, cufón is awesome. Thanks for this roundup.
( )Andi September 28th
Firebug Bookmarklet is the best.
( )Franky September 28th
Legit
( )Zac September 28th
Cool
( )FJ September 28th
no 3 is sooooooooooooo coooool dude.
( )Patrick September 29th
Genial
( )RedRockLabs September 29th
Regarding cufon – if you use something like:
Cufon.replace(’ul#mainNav li’);
remember to put jquery on top of that as IE may have serious problems with finding this element.
( )Dan Wellman September 29th
Thanks for reading everyone
( )Dan Wellman September 29th
oh, and apologies for the bit in the Modernizr section where I mention implementing some advanced CSS3 functionality…the element is of course HTML5, not CSS3 ><
( )Web 2.0 September 29th
Excellent tutorial, I had spent so many times on fixing PNGs in IE last year and I really hated, thanks…
( )Maurizio Liberato September 29th
Thanks a lot for that! I was looking forward to javascript replacement font and custom shapes!!!
( )NetChaos September 29th
Seems like the 5th one got cut off while editing, or is it just for me ?
“So if the current browser does support the new” …. ?
( )AuGusTin September 29th
Wow, I’m finding the smart way to work with font, your post helps me very much. Thanks.
( )abhijit September 29th
Thanks for letting us know about these cool tools. I never knew about Firebug Lite and was pretty excited, but after testing it found that its nowhere near Firebug. I don’t think its better than IE Developer Toolbar, even though that also sucks a lot. It may be useful for Safari or Opera, but I rarely see a page getting into trouble in Safari if its okay on Firefox.
( )Website Design Sydney September 29th
The fewer creative limitations, the better.
( )Sorin Istudor September 30th
great tutorial, thank you for sharing it.
( )Stephen Webb September 30th
Some great libraries and fixes in this tutorial, especially the one addressing PNG usage in Internet Explorer – a common issue for all web designers. I was particularly interested to read about ‘Firebug’, as this appears to be quite an
in-depth tool that all developers could use. Previously I have used a similar tool in Firefox, but it didn’t have the advanced capabilities of ‘Firebug’, so I shall be downloading this soon!
The significant lack of usable fonts in web design can be very restricting and frustrating, so reading about “Cufon” is great! Having tried to get around this issue previously using Flash I discovered multiple downsides, so to have custom fonts on web pages (that search engines can read fully) is an excellent step in the right direction. Again I shall be downloading this soon and trying out it’s capabilities, particularly when using on Internet Explorer.
( )vj September 30th
sorry but use any font is not working in firefox 3.0 and ie 6
( )it is working in opera 10
Dan Wellman October 2nd
Cufon definately works in IE6 as I have used it…might need to include jQuery as one of the comments above states (I use jQuery in pretty much *all* my sites!)
Not sure about firefox 3 but I’d be surprised tbh…it works flawlessly on FF3.5
( )Joao Aliano September 30th
Thanks Dan! And specially for the Modenizr tip.
That means a lot.
It’s great to see we can now test CSS3 and HTML5 without fearing a total browser versus document collapse.
( )Cem Meric September 30th
Thanks for sharing Dan. I’ve been using Cufon for a while, it’s great.
( )John Sanders October 1st
I just implemented a site with DD_BelatedPNG. It worked great, and did so in one line of code.
I’m looking forward to trying Cufon and Firebug lite.
Thanks for the article!
( )KA October 2nd
oh my! if i only knew the firebug thing earlier! I’d have saved so much time!
I have this plugin on IE that attempts to be like firebug but the usability of the thing is nowhere near!
( )web graphic design October 6th
I would like to comment that JavaScript libraries can really ease the development of modern, attractive web sites. The libraries that we’ll be looking at aren’t libraries in the same sense as something like jQuery or the YUI; they’re much smaller and much more specialized. But they’re the best at what they do and provide unique functionality.
( )