written on:3 Sep, 2007 by Alen Grakalic

Sitemap Styler: Style your Sitemaps with CSS and Javascript

Delicious Digg StumbleUpon Reddit Subscribe to RSS Feed

I believe that it isn't necessary to point out the benefits of having a sitemap somewhere on your site. Apart from making sure that all of your pages are linked and indexed, you are providing an overview of your site's structure. That can be very useful to some user trying to find his way around. But, what happens if you have huge sitemap and you don't want to overload your page yet still keep things accessible and "indexable"? Maybe CSSG Sitemap Styler could help.

What is it?

Sitemap Syler is a little CSS/JavaScript piece of code that can be easily applied to your sitemap list. It then takes care of it's presentation. All you have to do is include couple lines of code. It doesn't require any JavaScript knowledge but some CSS knowledge would come in handy if you want to modify the appearance of your sitemap.
I must point out that Sitemap Styler doesn't generate sitemaps, it merely styles them.

How does it work?

In order to have SEO friendly sitemap, entire site structure should be rendered in html code. So, no fetching subcategories with AJAX or anything like that. The best way to render links and display hierarchy is using nested lists. Sitemap Styler uses unordered lists. The root list has an id = "sitemap". Simple JavaScript function goes through list's item nodes and check for child elements. If item contains nested list, script attaches a span element that serves as a toggle button for expanding and collapsing child lists.
Here's a sample of what html code should look like:

<ul id="sitemap">
  <li><a href="#">First link</a>
  <ul>
    <li><a href="#">First link</a>
    <ul>
      <li><a href="#">First link</a></li>
      <li><a href="#">Second link</a></li>
      <li><a href="#">Third link</a></li>
      <li><a href="#">Fourth link</a></li>
      <li><a href="#">Fifth link</a></li>
    </ul>
    </li>
  </ul>
  </li>
</ul>

In our examples the list goes down to level 3, but it can go on forever. It is just a matter of styling.

How to apply it to your own site?

Easy. You have to download and extract one of the examples. Put the folder named "sitemapstyler" into the root of your site. On sitemap page (page that already contains your sitemap, rendered as unordered list) place this code inside the head tag.

<link href="sitemapstyler/sitemapstyler.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="sitemapstyler/sitemapstyler.js"></script>

Don't forget to put id="sitemap" to your top unordered list element.

Examples

Why don't you join in?

Here's a chance for all you css designers out there to be creative. Create your own "theme" for Sitemap Styler. Send your files to me and I will add it to the gallery. Your name will be listed (along with a link to your website) on this page as well as in the footer of your theme's index page.

About the author:

cssglobe's image Designer, developer and a passionate standardista. Long time web professional with huge experience in all types of front-end work. Founder of Css Globe and creator of Easy front-end framework.
To get in touch, visit Alen's personal page, follow Alen on Twitter or become a Facebook friend.

Enjoyed the article?

Then don't miss our next one! Subscribe to our RSS feed or share it with your friends.

Delicious Digg StumbleUpon Reddit Subscribe to RSS Feed

Read more! Here are our most recent articles:

View All Articles

Comments

  1. 3kolone on 3 Sep, 2007 wrote:

    example 2 is pretty nice ...
  2. Derek A on 3 Sep, 2007 wrote:

    The point of a sitemap is to see the the hierarchy/information architecture in a single glance.
    With these examples you've hidden the very information that makes the sitemap useful!
  3. cssglobe on 3 Sep, 2007 wrote:

    You have a point there Derek. You can always leave the list open, but if you want to hide it's parts, use the script. Also there are number of ways that you can use this script.
  4. Dean on 3 Sep, 2007 wrote:

    I agree with Derek. Site maps should be instantly visible. Maybe rename this as a menu or something else! Its cool code...
  5. cssglobe on 3 Sep, 2007 wrote:

    to tell you the truth, this started as something else.. it was similar to sitemap but it has a purpose of a menu... more like a widget of some sort... Anyway the code is here, so... :)
  6. David Hopkins on 3 Sep, 2007 wrote:

    I'm with 3kolone, 2 is the nicest. So long as you tell people they need to click to see the nested categories I don't see a problem with it.This would be pretty good to use in conjunction the <a href="http://dev.mysql.com/tech-resources/articles/hierarchical-data.html">nested set model</a>.
  7. Karl on 4 Sep, 2007 wrote:

    Nice styling, but in this day and age of progressive enhancement I expect to see the lists fully expanded when JavaScript is unavailable rather than a message saying that I need to enable JS to access information that's already in the source code.
  8. Save Videos on 4 Sep, 2007 wrote:

    Nice, but I can't imagine a large site using that especially when they could have hundreds or even thousands of pages.
  9. Ross Bruniges on 4 Sep, 2007 wrote:

    Site maps are a very important thing to include on any site for the means of accessibility and also SEO - they provide a lot of information at a glance.

    Nice examples but I would expect to also be able to click on the links themselves to expand the lists below. Clicking the 'cross' is rather fiddly.
  10. cssglobe on 4 Sep, 2007 wrote:

    Good point Karl, and the rest of you folks. What I wanted is to present this simple script. Sitemap was the closest thing that I could relate this script to.
  11. Tim on 9 Oct, 2007 wrote:

    This seems accessible and SEO friendly to me. The SE's can still read the content because it's not dynamically inserted, just moved onto the page when you drop down. In terms of accessibility, just disable the Javascript or maybe add some Access Keys to drop down the list.

    Personally, I think Site Maps can be a bit overwhelming, and this would work great to get you exactly where you want to go. That is, if the site architecture is good :)
  12. Tate on 10 Oct, 2007 wrote:

    I think this is a great initiative for human-readable sitemaps. However, it really ought to have utilise a no-javascript fallback, such as expanding the navigation when javascript is disabled.

    Secondly, this doesn't conform at all to the sitemap protocol. http://www.sitemaps.org/. It's just plain XML.
  13. Scott on 31 Oct, 2007 wrote:

    Great code, so much cleaner than others that I've seen on the web. I did make a couple of enhancements after seeing what others thought were limitations. First of all, to make the list expanded automatically if javascript is turned off, I added a <noscript> section to display the list:
    <noscript>
    <style type="text/css">
    #sitemap ul{display:block;}
    </style>
    </noscript>
    Secondly, I added an expand all/collapse all to allow users to quickly see the site hierarchy. I did this by naming the function openMap() and closeMap() and calling each from a link in the page. I changed the function in openMap() to set the <ul> display to 'block':
    ul.style.display = "block";
    and the className for the span to 'expanded';
    span.className = "expanded";
    works great, take a look:
    http://education.ou.edu/sitemap/
  14. Scott on 31 Oct, 2007 wrote:

    Sorry, it'd be nice to allow users to view the post before submitting so we'd know if code is getting stripped. Anyway, continuing with my prior post, I added a noscript section that sets the #sitemap ul display to block. This ensures that the list is expanded if javascript is disabled.
  15. Jan on 3 Nov, 2007 wrote:

    As Tate said above, XML sitemap is sufficient. Only a few visitors use HTML sitemaps for the navigation purposes. Instead, XML sitemaps can be crawled by search engines without being hidden. Just put a small link at the bottom of each page saying "XML sitemap".

    I personally use so-called HTML sitemap, but it is just a list of the most important pages on my site. Otherwise it would list approximately 1500 pages for each language... Not useful for ordinary visitors at all.
  16. presse on 8 Jan, 2008 wrote:

    Example 2 is very nice...

    Personally, I think Site Maps can be a bit overwhelming, and this would work great to get you exactly where you want to go.
  17. webkatalog on 8 Jan, 2008 wrote:

    I like both Example 2 and Example 3 - unfortunately leaves me between the two not decide why I invite them both down to me ;)
  18. yoichi on 15 Jan, 2008 wrote:

    Hi,
    I've installed this on my sidebar for categories and it's working perfectly ok in FF but for some reason the "+" and "-" do not appear in IE6 (i.e. can not open the sub-categories).
    I wonder what I may have done wrong. Your guidance will be much appreciated.
    Thanks
  19. yoichi on 15 Jan, 2008 wrote:

    Please disregard my previous comment.
    I found out that it was conflicting with "Secure and Accessible PHP Contact Form" plugin.
  20. root on 24 Jan, 2008 wrote:

    Example nr 1 is pretty good
    I was searching something like that for my site,
    now I found it :D
    Thx a lot for this article
    Keep blogging (I like good CSS/HTML articles ;) )
    Cya
  21. anarsizm on 6 Feb, 2008 wrote:

    Personally, I think Site Maps can be a bit overwhelming, and this would work great to get you exactly where you want to go. That is, if the site architecture is good :)
  22. forum on 9 Feb, 2008 wrote:

    Looks very interesting. Also there are number of ways that you can use this script.
  23. edebiyat on 12 Feb, 2008 wrote:

    Looks interesting. Nice styling, but in this day and age of progressive enhancement I expect to see the lists fully expanded when JavaScript is unavailable rather than a message saying that I need to enable JS to access information that's already in the source code.

  24. Oyun indir on 14 Feb, 2008 wrote:

    Thank you for your work.
  25. Alex on 18 Feb, 2008 wrote:

    CSS Sitemap Styler: Style your Sitemaps with CSS and JavascriptSitemaps can be very useful to some user trying to find his way around. But, what happens if you have huge sitemap and you don’t want to overload your page yet still keep things accessible and “indexable”? Maybe CSSG Sitemap Styler could help. Another solution: CSS SiteMap.
  26. msn ifadeleri on 18 Feb, 2008 wrote:

    Thanks, example 2 is pretty nice.
  27. Oyun on 20 Feb, 2008 wrote:

    Personally, I think Site Maps can be a bit overwhelming, and this would work great to get you exactly where you want to go. That is, if the site architecture is good :)
  28. 777smileys on 25 Feb, 2008 wrote:

    Great display of standards based html!

    One little thing: The examples quirk a little on Opera 9, I got to mend it a little by specifying a 61.25% font-size for the body and 1em line-height for the ul’s.

    It’s not perfect (my shot is that the em sized borders are to blame) but close to it! BTW I haven’t tested to see the changes on the ie side, I suppose it just takes some tweaking.

    Just being a little picky. It’s a fantastic job!
  29. orgu on 28 Mar, 2008 wrote:

    Thank you for your work. I liked it. Cool...
  30. Elaine on 8 Apr, 2008 wrote:

    Hi,
    How would you go about using the sitemap as a navigation system where the drop down stayed open even after clicking on one of the sub-links?

    Thanks,

    Elaine
  31. neuwagen on 17 May, 2008 wrote:

    Nice sitemaps, thanks for your shared work! cool stuff...
  32. yogaurlaub on 17 May, 2008 wrote:

    Site maps one and two are realy cool, good work! thanx a lot.
  33. chary on 22 May, 2008 wrote:

    its very nice article and add more articles like it
  34. bayrak on 24 May, 2008 wrote:

    thank you so much
  35. www.fettverbrennung.org on 25 May, 2008 wrote:

    Nice, but I can't imagine a large site using that especially when they could have hundreds or even thousands of pages.
  36. Büromöbel on 30 May, 2008 wrote:

    very good article with many usefull informations, but i think the most people need first informations about WHAT a rss feed is :))
  37. euwagen on 5 Jun, 2008 wrote:

    Thank you for sharing these stylish sitemaps!
  38. bayrak satişi on 11 Jun, 2008 wrote:

    thank you so much looks interesting. happy sharing

  39. Richard Metcalfe on 22 Jun, 2008 wrote:

    Very modern style very hard to have style and quality in one these days but i think you have nipped it in the bud with this.
  40. voyance gratuite on 23 Jun, 2008 wrote:

    Personally, I think Site Maps can be a bit overwhelming, and this would work great to get you exactly where you want to go.
  41. key sorgulama on 27 Jun, 2008 wrote:

    Thank you so much looks interesting. Happy sharing.
  42. Sean, Web Designer on 1 Jul, 2008 wrote:

    Nice share Alen, love sitemap 2 especially useful for large web sites however maybe overkill on smaller sites. Ran it through seo-browser.com and it passes the seo readability test v.nice!
  43. Firebubble Design on 25 Jul, 2008 wrote:

    Thanks for sharing, all the examples look really good.
    However I would just keep the sitemap page as simple as possible as in my opinion it mainly serves the search engines more than visitors.
  44. nick, search engine optimiser on 25 Jul, 2008 wrote:

    nice post, javascript not the most search engine friendly of code, smooth tho and ultimately looks great.
  45. Elgendi on 14 Aug, 2008 wrote:

    great work! @Scott expand/collapse (http://education.ou.edu/sitemap/) is a bit buggy in IE. Try: Expand all then collapse all then expand "Alumni.." you'll see wonders!
    any help in expand/collapse all will be appreciated!
  46. Farm frenzy 2 on 19 Aug, 2008 wrote:

    Very good article. Thanks for some sound advice. It's a topic that all creative industries need to know a lot about.
  47. Oak Garden on 19 Aug, 2008 wrote:

    You can get a sweet little copyright plugin that keeps you sitemap and copyright footer up to date. If i could find the link i would have put it here! lol

  48. Lohberger on 20 Aug, 2008 wrote:

    Nice display of standards based xhtml.
    Thank you for your work.
  49. Heidi on 21 Aug, 2008 wrote:

    I think this is a great initiative for human-readable sitemaps. However, it really ought to have utilise a no-javascript fallback, such as expanding the navigation when javascript is disabled.
  50. Modelagentur Graz on 27 Aug, 2008 wrote:

    I was looking for a sitemap for a clients website that could handle an ever increasing number of news articles. This was perfect.
    Cheers, works great!!
  51. Studio Créatif on 27 Aug, 2008 wrote:

    Really readable sitemap. Good job
  52. Bob on 3 Nov, 2008 wrote:

    Does this conform to sitemap protocol?
  53. Bob on 4 Nov, 2008 wrote:

    I'm sorry stupid question here.

    I get my sitemap generated by Google. If I were to use this app do I have to code the HTML?
  54. earth4energy on 27 Nov, 2008 wrote:

    I get all my sitemaps done by Google. Is it necessary to make sitemaps pretty - > thought that was just for google to see
  55. feha on 10 Jan, 2009 wrote:

    I really like this.
    I wish if JS is disabled to show expanded tree.
    This is very nice if used for Table of Contents in page sections.

    regards
    feha
  56. Alicia on 12 Feb, 2009 wrote:

    Okay, I'm kinda new to this whole thing, so this might be kind of a silly question... I created my sitemap using google, but my css won't allow it to display. It says, "Cannot view XML input using style sheet." If I add a css like the examples you listed to the sitemap page itself could it help solve that issue? In other words, how do I create a page (sitemap) on my website for which the overall website css does not apply?
  57. nomen on 16 Feb, 2009 wrote:

    I really like this. Great work!

    I have a big site tree and I would like to open, by default, just the first 2 or 3 levels. How can i do this?

    Thanks for your help.
  58. Roxbourne on 19 Feb, 2009 wrote:

    Thanks for this, I ended up using it on my website. I edited the code to make it load open by default.

    Is there anyway to keep it open even if the user viewing it doesnt have javascript on?
  59. Brandon on 1 Apr, 2009 wrote:

    Is there an update for sitemap styler that works with IE8? My words are all bunched together in IE8. I'm going to now apply the fix that displays this page in IE7, but ideally, I would like to see an update.
  60. Fussmatten on 1 Jun, 2009 wrote:

    Is it realy neccessary to style a sitemap?
    A sitemap contains maybe 20.000 single sites how will you style that ?
  61. bayrak on 16 Jun, 2009 wrote:

    thanks
  62. bayrak on 16 Jun, 2009 wrote:

    thank you very much

Sorry, further comments are disabled for this post.

Need help with your website?
Hire a CSS/JavaScript expert!

Hey, you are not logged in!
Apply for a membership or login here.

Subscribe to CSSG Feed

Want to join?

If you wish to contribute with your own articles, updates or gallery entries you can apply for a membership and even become our editor.

Apply here

Become a friend