Developing software in the Real World

Dynamic JavaScript Tabs

Please note that this code is very old now and I recommend looking at JQuery UI's tabs instead.

This is some code that I wrote to create dynamic tabs. I use it for forms where I have a lot of fields and a good percentage are "advanced" or otherwise not important enough to have visible immediately. The CSS is based on ideas from Silverorange Labs and the JS code is mine. The code is released under the MIT license which basically means you can do what you like with it as long as you don't blame me!


Basic tutorial

It's not hard to use and I've included a sample html file in the zip archive. The basics are:

i.e. you need a "tab-container" and then each tab is contained in a "tab-content" and we use a "tab" to sort out the title. The nice thing is that it degrades really nicely!

Change Log

  • 22/Mar/2005: version 1.0.0
    • Initial release.
  • 28/Mar/2005: version 1.0.1
    • Gracefully handle the case when there is no container id.
  • 21/Dec/2005: version 1.0.2
    • Patch from Áncor & Imobach González Sosa to allow for multiple tab containers
  • 17/Jan/2006: version 1.0.3
    • Fixed version number at top of file
    • Added this Change Log
    • Fixed CSS as noted by Adam Fortuna of
    • Patch from Simon H to add tab ids for other scripts to hook into