A clean calendar in CSS3 & jQuery
by Jef Vlamings
Almost a year ago I had the idea to build a calendar app. The project was called LiveCal and was supposed to become a platform where you could share calendars. The whole idea was that calendars would become something you subscribe to. Let me clarify. Let’s say you are subscribed to the calendar stream of your school. One of your teachers plans an event, such as a task or a test and adds it to the calendar stream. From the moment the event is added to the stream, you’ll get a instant notification that a new event is being planned. This means you’ll always walk around with an updated calendar. Due to the complexity of the idea and the lack of knowledge on my side this project never really took off.
Nevertheless I started to make a CSS3 calendar with some jQuery animation while I was working on this project. In this article I will explain, step by step, how to use the calendar.
How to get it
You can download or view a demo of the animated CSS3 calendar by clicking one of following links.
How to use it
You’re allowed to use the calendar for your own purpose. For those who are interested to learn a bit more about how the calendar is built, I made a short guide about the animated CSS3 calendar.
Basic HTML structure
The first thing we have to do is add structure to the HTML file. To keep things as simple as possible I used the usual terms you find in a calendar. A day is nested in a week and a week is nested in a month. The div that represents a day is divided in three subdivs:
- daybar: the top bar displaying the day’s number of the month
- dots: a div containing an unordered list to present dots according to the events of that day.
- open: a div containing all events of that day. This div is only visible if it’s slid out.
<div class="week">
<div class="day">
<div class="daybar">
<p>31</p>
</div>
<div class="dots">
<ul>
<li></li>
</ul>
</div>
<!-- slide open -->
<div class="open">
<ul>
<li></li>
</ul>
</div>
<!-- slide closed -->
</div>
</div>
At the end of this article you can find out how I used jQuery to animate the accordion style calendar.
CSS Styling
There are three styling elements that are important in the calendar.
- Color: add color to the dots and the events
- Length: add length to the events. A one hour event should be half the size of a two hour event
- Padding: Position each event on the right spot.
Colors
For this calendar I made four classes with color names. If you add one of the classes to any div then that div will obtain the background color of that class. For example, if you want to create a green dot, you add the class “green” to the list element.
<div class="dots">
<ul>
<li class="red"></li>
<li class="green"></li>
<li class="yellow"></li>
<li class="blue"></li>
</ul>
</div>
- Red
- Green
- Yellow
- Blue
This calendar makes use of 4 different colors. Of course you can add as many colors as you want.
Event length
Instead of giving each individual event a specific height or length, I made some pre formatted classes you can use. Just type “lxx” where x is the amount of hours you want the event to be.
- l1 = 1 hour event
- l5 = 5 hour event
For example:
<div class="open">
<ul>
<li class="yellow l2"><p>2 hour event</p></li>
<li class="green l10"><p>10 hour event</p></li>
</ul>
</div>
Event padding
We now managed to add color and length to the events. To position each event on the row according to the start of the event, we need to add an extra class to each div. I made a preformatted class “ax” where x stands for the amount of hours between the previous event or the beginning of the day if no event took place.
- a1 = after 1 hour. The event starts at 1 o’clock
- a12 = after 12 hours. The event starts at 12 o’clock
- Multiple events
- a8 = after 8 hours. The first event starts at 8 o’clock
- a4 = after 4 hours. The second events starts 4 hours after the previous event, which is at 12 o’clock
For example:
<div class="open">
<ul>
<li class="yellow l1 a13"><p>13:00 first event</p></li>
<li class="yellow l1 a1"><p>15:00 second event</p></li>
<li class="red l2 a3"><p>19:00 third event</p></li>
</ul>
</div>
Keep in mind you’ll have to take the length of the event into account when you are adding spacing above an event.
jQuery magic
For the accordion effect used in this calendar I made a customized script based on the Simple jQuery Accordion menu. I tried to simplify the Simple jQuery Accordion script resulting in fewer lines of code. Here is my version.
function initMenu() {
//create variable named "block" and put class ".day" in it
var block = $(".day");
//hide every div with class "open"
$('.open').hide();
//when a div with class ".day" is clicked ...
block.click(
function() {
//... find all divs with class "open" and slide them open
$(this).parents('div:eq(0)').find('.open').slideToggle('fast');
}
);}
$(document).ready(function() {initMenu();});
Put this piece of code in the header of your HTML file and you should be ready to go!
Questions?
As I’m no longer using this calendar for the project I thought it could be useful for someone else. I hope my instructions are clear enough for you to figure out how to use it. If you have any problems with the calendar, feel free to ask questions. I’ll try to answer as quickly as possible.

I like this blog. I will certainly be peeping into it frequently.
View: Linkman.pl
@Lequancekek I’m glad to hear you’re so interested!
This is the coolest cal ever and I’m going to be using it on my site and promote you the creator. This is the epitome of amazing!
Thanks! I’m very pleased to hear you like it. Stay tuned for more stuff like this!
Awesome calendar, clean and precise. Good Job.
You definitively got a new subscriber.
Awesome calendar and a great work.
Very cool, your idea and concept of a Twitter like calendar feed is very inspirational, will be following
A very neat solution. Well done.
On FF, dots are square. I’m sure you can add radius on .dots ul li {}
Thank you Syndrael. I now realize I haven’t really tried to make it compatible with all current browsers. Anyway if you want it to work on FF as well, just add
-moz-border-radius: …px …px …px …px;
to
.dots ul li{
and your done!
Hi, other than -webkit-border-radius (which is in fact just a webkit only border radius polyfill) and the use of text-shadow, what exactly about this is CSS3?
Isn’t that enough CSS3 for you, what’s he meant to put? A javascript and css calendar?? A calendar using a web browser! HAHA
Nicely done. Any reason you used divs etc? A table might be better suited for it – strictly speaking, it’s tabular data, right?
I recently had to make a HTML/CSS calendar and used a table: http://jsfiddle.net/r7Q9m/
Great remark. I’ll definitely keep that in mind in my future projects.
I though it would be easier for developers to put dynamic content in a div than in a table. Now you only have to add 2 classes to a div to determine its length and start point.
Beautiful work, Jef… And if any WordPress developers are reading this, please port this into a calendar plugin!
Tell me one thing? Why so many divs? You should use tables (semantic point of view)…
It’s called divitis
Is there a solution to show two appointments which start at the same time and day?
Hi Jef,
This is a breath of fresh air, as I actually had the same idea and thought it was cool. And as a backend developer, I went ahead and created a working prototype which is up at http://www.shalendar.com. It’s funny because I was actually looking for a frontend guy who shares the same vision. Send me an email and maybe we can work on the project together.
Or reach me out at @jaequery
Found this from smashing mag feed on facebook. Thanks for sharing the calendar source.
Hello, i found it also on smashing mag feed on facebook.
I was looking for a calendar well designed and interactive to use on my project. I’ve already did the back-end things and i will use some principals of yours on mine.
thanks for sharing
Hi there! This is an amazing calendar you have here. I love the vision you had for it and hopefully one day it can get implemented.
Great work and thanks for sharing!
My first Christmas gift this year, thank you!
the original idea is google calendar! you can make a calendar public or share with a subset of people and voilá!
[...] A clean calendar in CSS3 & jQuery : Finishing Touch. Share this:TwitterFacebookLike this:LikeBe the first to like this post. [...]
The best calendar I’ve seen in a long time. Thanks for sharing. Definitely remember this one the next time I need a calendar in one of my projects.
Very good implementation. Thanks for sharing – you should made the internet 1% better.
Really nice calendar.
However, I think there is a bug, if one day is empty (like Friday the 4th in the example).
Line under ‘dots’ div is missing if expanded. It’ s connected with some way. Easy fix is to add ” and to create l0 and a0 in style.css to be sure it works.
The other thing is using -webit- prefix in CSS.
It isn’t really needed anymore. In fact it doesn’t work in Opera with this -webkit-. However, this version without working radius properties is also looking fine.
System has cleaned up my post
:
the fix is to add
Hi! Quick question (a stupid one, but I’m a newbie) — if I’d like to be able to click on individual calendar items to pop-up more detail on them (for example, the location and ingredients I need for the cookie bake-off), can that functionality be added to this calendar? Thank you! This is a beautiful way to display calendar information
It’s not possible with the current calendar unless you add extra JS code. The easiest way to show extra information is to use modal windows or popup balloons with an extra piece of jQuery for example.
Love this tutorials, this is a very simple and very effective calendar, thanks for sharing, keep up the good work…
Forget tables, and meaningless divs; I’m surprised you didn’t use (if not article; though that would be more appropriate to contain the whole calendar) here.
That solves both problems with using meaningless divs and tables elegantly….
* You didn’t use the section html5 tag here; your filter tools on comments on this blog seems to be very strict….
Good point. I wasn’t so much in to HTML5 when I wrote this article. But section tags would make more sense in an HTML5 document indeed.
Good calendar and neat coding.
a question regarding the functionality: how does this calendar to manage overlapping events? say event A occurs between 9AM and 10AM on 27/06 and the event B occurs between 9:30Am and 10:30AM on 27/06.
The calendar isn’t designed for overlapping events at the moment. You could try to circumvent this issue by putting them side by side. I propose you dynamically add an extra class to the event where you set the with of the list item to half the width of the day container. Using floating divs you can arrange them side by side.
This is probably not the most elegant solution, but it should work.
[...] A calendar in CSS3 and jQuery [...]
[...] A calendar in CSS3 and jQuery A step by step tutorial on how you can develop a CSS3 calendar by incorporating jQuery animation. Also, check out David Bushell’s responsive calendar demo. [...]
[...] A calendar in CSS3 and jQuery A step-by-step tutorial on the way to create a CSS3 calendar by incorporating jQuery animation. Also, check out David Bushell’s responsive calendar demo. [...]
[...] A calendar in CSS3 and jQuery [...]
[...] 2) A Clean Calendar in CSS3 jQuery [...]
[...] A calendar in CSS3 and jQuery A step by step tutorial on how to create a CSS3 calendar with some jQuery animation. Also, check out David Bushell’s responsive calendar demo. [...]
A clean calendar in CSS3 & jQuery : Jef Vlamings I was suggested this website by my cousin. I’m not sure whether this post is written by him as no one else know such detailed about my difficulty. You’re amazing! Thanks! your article about A clean calendar in CSS3 & jQuery : Jef VlamingsBest Regards Cindy
[...] 2) A Clean Calendar in CSS3 jQuery [...]
[...] A calendar in CSS3 and jQuery [...]
Great and very nice seems. Thanks.
[...] A calendar in CSS3 and jQuery A step by step tutorial on how to create a CSS3 calendar with some jQuery animation. Also, check out David Bushell’s responsive calendar demo. [...]
[...] A calendar in CSS3 and jQuery 37 A step by step tutorial on how to create a CSS3 calendar with some jQuery animation. Also, check out David Bushell’s responsive calendar demo. [...]
[...] A calendar in CSS3 and jQuery [...]
[...] 2) A Clean Calendar in CSS3 jQuery [...]
[...] open: a div containing all events of that day. This div is only visible if it’s slid out. ? [...]
[...] A calendar in CSS3 and jQuery A step by step tutorial on how to create a CSS3 calendar with some jQuery animation. Also, check outDavid Bushell’s responsive calendar demo. [...]
[...] A calendar in CSS3 and jQuery A step by step tutorial on how to create a CSS3 calendar with some jQuery animation. Also, check out David Bushell’s responsive calendar demo. [...]