How to Create Beautiful and Elegant HTML Lists Using CSS

Anatomy of HTML lists, unordered, ordered HTML list have become one of the most used HTML elements for marking-up various semantic content structures — navigation, comments and even image galleries.

This article will explain and show you how to style lists inside blog posts, articles or other basic HTML documents.

Before we start, it is necessary to understand the importance of using specific HTML tags <ul> and <ol>, instead of simple numbering (like 1., 2. or •, ») for building lists. By applying content a semantic structure, we emphasize the relationships between different content elements. In case of lists we are able to imply that there is a certain relationship between all of the list members, which is possibly described by the paragraph introducing the list. It also helps screen reader users for whom the total number of items is announced before the rest of the list.

Default list rendering in standards aware browsers and Internet Explorer

Let’s look at the default rendering of ordered <ol> and unordered <ul> lists by Web standards aware browsers (with Gecko, Webkit or Opera rendering engine) and Internet Explorer (IE).

HTML list rendering. standards vs internet explorer

It turns out that IE applies default left side margin to the list container (<ul> and <ol>) while standards aware browsers apply left side padding. These differences in list rendering force us to set both padding and margin of <ul> to 0 and continue to work only with styling <li> tag.

Another thing we notice is that list bullets or numbering becomes invisible in IE with the left side margin set to 0.

Getting the list rendering consistent among all browsers

To solve the invisible bullet problem described above, its a good idea to use relative positioning of list containers <ul> and <ol>. By doing so, we will be able to create much more advanced list style later without repeating most of the CSS.

CSS for simple lists

ul, ol { 
   margin:auto -3em 1em 0; 
   padding:0; 
   position:relative; 
   left:-3em;
   overflow:hidden;
}
 
li { 
   margin-top:0.25em;
   margin-bottom:0.25em; 
}
 
ul ul, ul ol, 
ol ol, ol ul { 
   margin-left:1em; 
   padding-left:0; 
}
 
ul li, ol li { 
   margin-left:5em; 
}
 
li li { 
   margin-left:1em; 
}

Internet Explorer specific CSS

To fix IE’s ability to do the math correctly, we have to enable hasLayout property for all of our <ul> and <ol> tags. This is done by using conditional comments:

<!--[if lte IE 6]><style>
ul, ol { 
    height:0; 
    overflow:visible;
}
</style>< ![endif]-->
 
<!--[if gt IE 6]><style>
    ul, ol { height:1%; }
</style>< ![endif]-->
Output

Simple unordered list

List is now rendered equally in all browsers. For illustration purposes a yellow background is applied to the list container <ul>, gray border shows the dimensions of <ul>, while list items <li> have gray background.

Flat lists for more content per list item

Sometimes you have multiple lines of content per list item and then it might be reasonable to align the lists with the rest of the content in order to sustain the vertical flow of it.

CSS for flat lists

.flat li { 
   margin-left:3em; 
}
 
.flat li ul, .flat li ol { 
   margin-left:1em; 
   padding-left:0; 
}
 
.flat li li { 
   margin-left:0; 
}
Screenshot: flat HTML lists for more content

Notice the little amount of CSS, but more importantly that it is rendered equally among all of the browsers and we can still use the default bullet styles instead of images.

However, sometimes one might want to use custom style list bullets. This can be done using the list-style-image property in CSS.

Lists with custom style bullets

Screenshot: HTML lists with custom bullet image

Note: don’t forget to remove the line break after list-style-image: to get it working.

CSS:

ul.bullet-a li { 
   list-style-image: 
    url('bullet-image-a.png');  
}
 
ul.bullet-b li { 
   list-style-image: 
    url('bullet-image-b.png'); 
}

Although the alignment of the list image is not pixel perfect among all of the browsers, it is more than satisfactory if the height of the bullet image doesn’t exceed 10 pixels. One might suggest to use background of <li> tag as a list bullet image, but this would brake the ability to combine multiple CSS identifiers per list, like <ul class="flat bullet-a"> because of inherited margin settings.

All the small details

Notice that the spacing between list items in the last example (rounded image bullets) is larger than the default one (arrow image bullets). This enhances readability and separates list items similarly to paragraphs. So here is the final set of CSS styles to suite most of the needs:

.spaced { 
    margin-bottom:0;
}
 
.spaced ul, .spaced ol { 
    margin-top:1em;
}
 
.spaced li { 
    margin-bottom:1em;
}
.indent li { 
    padding-left:1em; 
    text-indent:-1em; 
}
 
.inside li { 
    list-style-position:inside; 
}
 
.clear li { 
    list-style-type:none; 
}

You can see that one of the previous examples already utilizes the “spaced” styling, while “indent”, “inside” and “clear” might benefit from a few examples:

Screenshot: Flat and indented list, clear list, inside list

All of CSS combined & list style cheat-sheet

Screenshot showing the use of various HTML list styles

List output example

Internet Explorer specific HTML and CSS

<!--[if lte IE 6]>
    <style>ul, ol { height:0; overflow:visible; }</style>
< ![endif]-->
<!--[if gt IE 6]>
    <style>ul, ol { height:1%; }</style>
< ![endif]-->

Few suggestions:

  • Bullet image height preferably should not exceed 10 pixels. Lower image height makes them look better in Internet Explorer. If you want bullet images to be transparent, save them as transparent GIF or 8-bit PNG files.
  • You might find it useful to apply this styling only to your post content, which can be easily done by prepeding the identifier of your post wrapper (like .post or .article) to all of the list styles. The end result would be something like .post ul, .post ol {}.

One ad I selected (how?)
Creative Suite 3 Web Premium. Redefine the extraordinary in web design and development. image-2761360-10469520

KonstruktorsNotes?i=Rii26Ze KonstruktorsNotes?i=mRqrUYe KonstruktorsNotes?i=ANv5gIe
240509905

Woolgathering — Daily Sketches and Drawings by Elizabeth Perry

Sketch of flowers by Elizabeth Perry Amazing little drawings/sketches in various techniques by Elizabeth Perry published every day at woolgathering since January 2005. Be sure to have a look at one of her other projectsmuseum drawing project.

KonstruktorsNotes?i=e3DaSXe KonstruktorsNotes?i=qSosV5e KonstruktorsNotes?i=F9xxdke
239853567

Web Design Critique: Consistency and Homogeneity of the Blog Layout

Blog Herald Design over the years Blogherald.com is a blog featuring news from all around the blogosphere since 2003, and is run by a dozen of contributors and writers. It was founded by Duncan Riley from Australia and is now owned by Splashpress Media. The Blog Herald has gone through multiple design and layout variations, including the latest one made by Brian Gardner.

Web design and design in general should never be judged from the aesthetic viewpoint or by how much one likes/dislikes a particular color scheme, typeface or the layout of different content elements. The purpose of design is to make the content organized and accessible to the widest target audience possible. Design should be the information highway without traffic jams and clearly marked road labels which don’t require any Design Positioning System (DPS) in order to navigate.

By content I don’t mean only text and photos, and by road labels I don’t mean the physical labels or navigation tooltips on a website. The message which the website wants to deliver to its users is the content — everything from writing tips, or well explained PHP tutorials for beginning web developers, to “make money online” suggestions for young mothers. The content defines your audience and only by understanding that audience one can shape or design the content in a way that works the best. The purpose of the website should define its design and structure.

Luckily the blog authors can relatively easy understand their audience, because they write or post about something they are truly passionate about, and it is most likely that their audience should be as well. Their audience is very similar to themselves and therefore the simple question to ask is “what would I like to know?” or “what have I found out recently, that other people might find useful?”.

Keeping the above consideration in mind, lets look at the current design of Blogherald.com and ask a few questions:

  1. Blog Herald Design Critique - points of interest Blog Herald logo is a square with rounded corners and red background with a symmetric horizontal darker shade gradient with two lower-case oblique styled letters bh (an abbreviation from Blog Herald) in the middle. Square logo is aligned to the very left on the black header background without any padding from the header border. The icon is the only element on the whole website which uses gradient background or an oblique sans-serif typeface. Why such a decision?
  2. Blog Herald logo title is right next to the logo icon and is set in capitalized sans-serif typeface with letter ‘o’ in theme’s red. Why exactly ‘o’? Is it because ‘o’ resembles a sphere the most? Use of the word Herald comes from the newspapers, so why was the sans-serif typeface chosen? Just below the title is the tagline ‘Blogosphere’s latest, daily’ and ‘Since 2003’ set in the same typeface, but in upper-case.
  3. Related Network links in the top right corner are set in serif typeface without any differentiable styling (in color or with an underline) that would suggest that they are links. Each of them are separated by dots which are never used anywhere else on the website. Below the links is a description ‘Your friendly neighborhood blogosphere’ set in the same serif typeface but with cursive styling, which again is never used anywhere else. The current layout and positioning very weakly suggests that Blog Herald is one of the proud network members and doesn’t encourage the readers to explore the other sites.
  4. Search bar is aligned right without any padding from the rightside border of the header background, even though there is plenty of horizontal space around it — enough for an input field label or a ‘Search’ button. This would also allow removing the obvious search instructions.
  5. Main Navigation menu items are aligned horizontally bellow the header and are set in uppercase sans-serif typeface similar to the one used for the tagline, and are separated by lighter vertical lines. Although this font choice is good for the limited horizontal space and it ties well with the style of the tagline, in such combination (sans-serif + uppercase) it never appears anywhere else on the blog. The first two menu items ‘About’ and ‘Advertise’ are much less important to the readers than those items that follow and correspond to the blog’s content like ‘Editorials’, ‘Reviews’ or even more importantly ‘News’, which is currently placed only fifth.
  6. Section headings use a slightly larger and uppercase serif font which is fairly different from the viewpoint of typography.
  7. Post tagline is styled the same way as the rest of the content, and would much help the vertical rhythm and the scannability of the post listing if it was set a bit different than the rest of the content. Placing ‘Leave a Comment’ link right after the post title seems to be the most unreasonable design decision (yes, it is a design decision, because placing it there expects a certain user behavior or need). Having the ‘Filed under …’ information below the post introduction and the ‘Post a Comment’ immediately after the title is definitely unjustified.
  8. Post related information contains the same link to all the articles written by the same author, which is already mentioned in the post tagline. Removing this link and replacing the ‘Filed under …’ information as suggested above would leave there only the copyright information which is repeatedly displayed after every post introduction. Why display it under every post, if it is also mentioned in the page footer?

Suggestions for improving the Blog Herald

These are just a few observations about the top part of the Blog Herald’s layout and an examination of all content elements including the column content and individual section pages would be required for a complete design analysis. Nevertheless, it is enough for creating a layout that would correct the design mistakes mentioned above:

Blog Herald Suggestion No.1

Example 1: Suggested redesign.

Blog Herald Suggestion No.2

Example 2: Unique theme color for each of the member blogs.

Ideas behind the suggested design

Although most of the changes are obvious, here are some of the design features worth mentioning:

  • Blog Herald is part of a blog network, therefore the top horizontal stripe which links all the network members would span across the full browser width, while each of the individual blogs would have the usual width (~70em) which is visually emphasized through the top and bottom borders of the main navigation. The slogan of the network placed before the links and the tabbed design of the network navigation distinctively shows that the site currently viewed is one of the members.
  • A single theme color in each of the member sites would create a strong and unique brand for the whole network.
  • Separated content navigation and general information links in the main menu put more emphasis on the unique content of this blog.
  • Only two typefaces are used — serif font (like Georgia) for “important type” of content, and sans-serif (like Arial) for the body copy. Notice how the capitalized serif font is used consistently in navigation and for all the sidebar headings.

Conclusions

One should never criticize the design of a website on the grounds of visual liking or preference, but rather by how well the design enhances and delivers the content to its readers and viewers. Different content requires a different approach to presenting it in the way that is both accessible and easy to explore.

All of the blog authors want their readers to stay around and view more of the content they have produced. Unfortunately the format of blogs inherently makes the latest content to appear more prominent and buries some of your much beloved older posts deep into the archive pages. Although describing the solution for this problem would require another article, it is worth mentioning that sometimes just grouping and organizing the existing content, and removing the clutter makes the users much more comfortable with staying around.

Want to hear my critique of you blog/website?

Just leave a comment with your views on the blog design problems discussed in this article or about the web design in general. If more than three people post a comment, I’ll randomly choose three.

One ad I selected (how?)
Blue Host: Free Domain With $6.95 Hosting Package image-2761360-10376741

KonstruktorsNotes?i=yzHZ9xe KonstruktorsNotes?i=zhtn7Ne KonstruktorsNotes?i=FIp6kse
237281885

No

KonstruktorsNotes?i=1K9bhWe KonstruktorsNotes?i=fz4Ni2e KonstruktorsNotes?i=6xNclfe
232655996

Podcast of the week: WordPress Weekly

WordPress Weekly podcast logo If you are a WordPress user, you should definitely check out the WordPress Weekly podcast hosted by Jeff from Jeffro2pt0.com. It covers the latest and greatest in the world of WordPress — from news, plugin and theme reviews to general discussions about the online publishing.

The show is recorded live every Friday evening at 21:00 EST using the TalkShoe recording platform. It follows the round table discussion format where apart from the panel of guests also any of the listeners can call in and have their own say about the topics being discussed.

There are already five episodes available that you can download and listen to.

This week’s panel members were Ronald Huereca, Andrew Rickmann, Rob White and me (featuring the most wonderful sentence structures and wording at 4:00 in the morning; I was so nervous at the beginning). Topics discussed include: usefulness of pingbacks/trackbacks and their presentation (check out the yet-to-be-released Comment Sorter plugin); content theft and spam blogs (splogs); two new plugins by Sony; and the regular WordPress Tips of the Week by all of the panel members.

Homepage (and blog): jeffro2pt0.com/category/wp-weekly
WordPress Weekly on TalkShoe: talkshoe.com/tc/34224
RSS feed: recordings.talkshoe.com/rss34224.xml

One ad I selected (how?)
Now available: Adobe Photoshop Lightroom, the professional photographer's essential toolbox! image-2761360-10461410

KonstruktorsNotes?i=Bdxak8e KonstruktorsNotes?i=Fzi8Sbe KonstruktorsNotes?i=DhMYkie
232181472

Single page entry archive is available finally

I have finally created a single archive page so that those who prefer plain and simple lists instead of various ‘Most Popular’, ‘Recent Posts’ or ‘Similar Posts’ widgets, can now easily find something interesting to read. All thanks to the the very useful Smart Archives plugin by Justin Blanton.

KonstruktorsNotes?i=4wcpK6e KonstruktorsNotes?i=RZxExde KonstruktorsNotes?i=2QbwGWe
230946727

Suggestions for writing flexible and usable plugin

After the release of Custom Function Widgets plugin I also wrote about it in the WordPress support forum. Fellow forum contributor Otto42 (author of a very similar plugin: ExecPHP) had very interesting things to say regarding the plugin development in general. Really worth reading and discussing.

KonstruktorsNotes?i=aiaD3we KonstruktorsNotes?i=RRpxc7e KonstruktorsNotes?i=jfWq8ne
229783868

WordPress Plugin: Custom Function Widgets

Custom Function Widgets logo Many of the WordPress plugin authors don’t offer widgets, but only raw PHP functions (or hooks) which you have to insert into the theme’s template files. As the number of functions increases it becomes harder to manage it all, especially if you decide to uninstall some of them or add new ones.

It is especially inconvenient for those who are not so savvy, or don’t want to edit theme files. Moreover, if one decides to change the theme, the edits have to be repeated all over again.

Therefore, I made this Custom Function Widget plugin which allows you to create sidebar widgets without ever touching the theme’s files and use these widgets in any theme you like.

This plugin offers you up to 20 widgets you can then add to your theme’s sidebars. All you have to know is:

  1. the name of the function, and
  2. the arguments it requires (if any).

Additionally you can wrap the output in HTML, remove the widget’s title from the output, or remove the default widget wrapper (set in functions.php of your theme).

Download Custom Function Widgets Plugin

Note 1: Turns out that the version 0.1 had a bug in it (the way data was passed to the widget output), therefore a new version 0.2 is now available for a download.

Download custom-function-widgets.zip (Version 0.2 / 127 KB) — includes the plugin, readme.txt and four screenshots.

Installation Instructions

  1. Download the plugin and unzip its content
  2. Upload all of the custom_function_widgets directory to /wp-content/plugins/ directory. The final directory tree would like /wp-content/plugins/
    custom_function_widgets/custom_function_widgets.php
  3. Sidebar Widget Arrangement Activate the plugin through the ‘Plugins’ menu in your WordPress dashboard.
  4. Go to ‘Presentation’ > ‘Widgets’ inside your WordPress dashboard. Just bellow the list of sidebars you will see a list of ‘Available Widgets’. There you will find five new widgets ‘Custom Function 1′, ‘Custom Function 2′, etc.
  5. Drag one of these widgets inside the sidebar of your choice. Once it is there, click on the widget’s options button (next to its title), which will open the widget’s options dialog box.
  6. Custom Function Widgets settings There you can specify the following:
    1. Wiget title
    2. Name of the function you want to call (the only obligatory item you must specify)
    3. Arguments to pass to the function, like $onearg = 2, 'Something', $other = 3
    4. HTML to display before the output of the function
    5. HTML to display after the output of the function
    6. Option to hide the title of the widget (which you specified as Widget title) during the ouput
    7. Option to remove the default wrapper of the widget (defined in template.php of your theme’s folder, for each sidebar)
  7. Close the widget options pop-up and click ‘Save Changes’
  8. Now you should see the new widget in the sidebar of you blog/site

Example: creating a widget for Popularity Contest plugin

To better illustrate where to find this information and how to create a widget, lets use the ‘Popularity Contest‘ plugin by Alex King. Once you install Popularity Contest, you have several PHP hooks available:

  • akpc_most_popular($limit = 10, $before = <li>, $after = </li>)
  • akpc_most_popular_in_cat($limit = 5, $before, $after, $cat_ID = current category)
  • akpc_most_popular_in_month($limit, $before, $after, $m = YYYYMM)

To use either of these hooks, simply drag an new ‘Custom Function’ widget (from ‘Available Widgets’ under ‘Presentation’ > ‘Widgets’) inside a sidebar of your choice.

Click on the Widget’s options button and enter the following details (for the akpc_most_popular hook as an example):

  1. Widget title: Most Popular Posts
  2. Function name: akpc_most_popular
  3. Function variables: $limit = 5, $before = <li>, $after = </li>
  4. HTML Before: <ul>
  5. HTML After: </ul>
  6. Leave unchecked both 'Remove Widget title from the output' and 'Remove the default widget wrapper' options

Once you specify a Widget title, it will be also used in your list of widgets (instead of default ‘Custom Function #’).

What’s next?

There are already other WordPress plugins planned for a public release very soon. On this blog you can already see the Tabbed Widgets plugin which enables you to put any number of other widgets inside a single widget as tabs (with an option to rotate).

I will also release a new WordPress theme called Sunrise Racer (view the wiki entry or the demo).

Notes

  • I will try to get this plugin submitted at the official WordPress plugin repository, but so far nobody has reviewed my application.
  • Please leave your ideas, suggestions and bug reports in the comments.

One ad I selected (how?)
Lunarpages Web Hosting: Get 15,000GB of transfer for only $6.95! image-2761360-8242914

KonstruktorsNotes?i=onYwSxe KonstruktorsNotes?i=uCPqX5e KonstruktorsNotes?i=zMF7Ble
229025839

Singer/songwriter Martin Confused — acoustic and absolutely fantastic

Martin Confused (Mārtiņš Dambis) Martin Confused is an amazing singer/songwriter from Latvia whom I discovered only today. Download and listen to his two latest songs “Too late” and “Boy who never cried” at martinconfused.lv or watch him perform at NokiaOpenStage.lv. p.s. Turns out that we share the same surname — his real name is Mārtiņš Dambis.

KonstruktorsNotes?i=IRoAsZe KonstruktorsNotes?i=5dKqhGe KonstruktorsNotes?i=PWNAY0e
227232674