From Microformats Wiki
Jump to navigation Jump to search

XOXO 'compact' sample

Sample CSS and JS that demonstrates how to style and dynamically show XOXO outlines subtrees.


  • Written by Maciej Stachowiak.
  • Minor validation tweaks by Tantek Çelik.

You may redistribute this code freely under Simple BSD or CC-by-2.0 so long as you preserve the copyright notice.


This code will currently only work in Safari and other WebKit-based browsers. In Firefox and other Gecko-based browsers, the behavior is right but the layout is wrong because Gecko doesn't handle the negative margin-top properly on generated content. In Opera, it displays properly but does not behave right, because Opera doesn't appear to support attribute selectors. It does not work at all in Internet Explorer (any platform) because IE does not support generated content nor attribute selectors.

Workarounds for other browsers are welcome.

Markup Sample

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

Copyright (C) 2006 Maciej Stachowiak. All rights reserved.

You may redistribute this code freely under Simple BSD 
<http://microformats.org/wiki/simple-bsd-license> or CC-by-2.0 
<http://creativecommons.org/licenses/by/2.0/> so long as you 
preserve the copyright notice.

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<style type="text/css">

li {
    list-style: none;

ul, ol {
    padding-left: 20px;

ul[compact="compact"], ol[compact="compact"] {
    top: 0px;
    left: 0px;
    line-height: 0px;

ul[compact="compact"] *, ol[compact="compact"] * {
    display: none;

li ol:before, li ul:before {
    content: url('http://homepage.mac.com/ctholland/thelab/outlines/img/triangle_down.gif');
    float: left;;
    height: 0px;
    margin-top: -1em;
    margin-left: -40px;

li ol[compact="compact"]:before, li ul[compact="compact"]:before {
    content: url('http://homepage.mac.com/ctholland/thelab/outlines/img/triangle.gif');

<script type="text/javascript">
function tickleStyle(e)
    var parent = e.parentNode;
    var after = e.nextSibling;
    parent.insertBefore(e, after);

function clickHandler(event)
    if (event.target != this) {

    var list = this.firstChild.nextSibling;
    if (list.getAttribute("compact") == "compact") {
    } else {
        list.setAttribute("compact", "compact");

function attachClickHandlers()
    var uls = document.getElementsByTagName("ul");
    for (var i = 0; i < uls.length; i++) {
        if (uls[i].parentNode.tagName == "LI") {
            uls[i].parentNode.addEventListener("click", clickHandler, false);

    var ols = document.getElementsByTagName("ol");
    for (var i = 0; i < ols.length; i++) {
        if (ols[i].parentNode.tagName == "LI") {
            ols[i].parentNode.addEventListener("click", clickHandler, false);
window.addEventListener("load", attachClickHandlers, false);



<ul class="xoxo">
        <ol compact="compact">