50 Change your Blog Background According to the Time of Day
April 23, 2008 /

I've been working on a script which you can use to change the background color, or even any other background element of your blog, depending on the time of day.

You can see this script in action on the Time of Day test blog. Here I have used the script to change the main background color of the Minima template according to the time of day. Take a look at different times to see the changes take effect.

There are two versions of this script available for you to install instantly in your blog:

  • A pale color palette
  • A dark color palette

This means you can choose the color scheme which would work best for your existing fonts and color settings without having to also change the colors of existing elements in your blog.

If you would prefer to use your own color schemes, add images to the background, or change the background of other elements of your blog, I have also provided instructions for you to customize this script and adapt it to your own personal needs.

Here are the two different color schemes you could install in your blog:

Pale Scheme

Morning (6am-12pm)
Daytime (12pm-6pm)
Evening (6pm-12am)
Twilight (12am-6am)

Dark Scheme

Morning (6am-12pm)
Daytime (12pm-6pm)
Evening (6pm-12am)
Twilight (12am-6am)

Installing the Time of Day Background Color Script in your Blog

The script used to change the background color is really easy to install. Simply locate the closing </head> tag in your Blogger template, and add one of the following lines directly before it (choose the script according to the color scheme you would prefer to use):

For the pale color scheme:

<script src='http://bloggerbuster.com/scripts/time-of-day-pale.js' type='text/javascript'/>

For the dark color scheme:

<script src='http://bloggerbuster.com/scripts/time-of-day-dark.js' type='text/javascript'/>

Then locate this section of your Blogger template:

body {
background: $bgcolor;

This section may not appear exactly like this, or you may notice there is also a background image referenced in the background line. In either case, you need to delete the background statement which is highlighted in red text to ensure the JavaScript line you previously added is able to accurately declare the background color according to the time of day.

Now preview your blog. If all has gone to plan, you should see the background color of your blog has changed to the color specified for the time of day. You can then proceed to save your template.

Customizing the Time of Day Background Script

If you are able to edit and host the "Time of Day" JavaScript file yourself, you can use this as a basis for further customization including:

  • Using different background images for different times of day
  • Use different color schemes to those suggested above
  • Change the background color for a different section of your blog (for example, the header section)
  • Change the font colors depending on the time of day

First you should download a copy of the Time of Day Background script, then make your changes in your favorite editor (I use Notepad ++ though you could just as easily use Notepad or another simple text editor).

Once you have made your changes, you will need to upload your revised script to a hosting provider, and link to the script from the <head> section of your blog template as described above.

Here is a transcript of the JavaScript in its simplest form, which is used only to alter the background color:

var d = new Date()
var h = d.getHours()

//
if (h < 6) document.write('<style type="text/css">body{background: black; color: black}"></style>')
else if (h < 12) document.write('<style type="text/css">body{background: blue; color: black}"></style>')
else if (h < 18) document.write('<style type="text/css">body{background: yellow; color: black}"></style>')
else if (h < 24) document.write('<style type="text/css">body{background: red; color: black}"></style>')

Each time section features a JavaScript command, like this:

document.write('<style type="text/css">body{background: black; color: black}"></style>')

You can change the code highlighted in red to alter the effects of the script. For example, if you wanted to use a background image instead of a color, you could change the red section of code to something like this:

body {background:url(http://image-host.com/yourimage.jpg)}

To change the color of the header section (rather than the main body background), you would change this as follows:

#header {background: #ffff00;}

In fact, you can use this script to alter any CSS styled element of your blog template to suit the time of day! Just be sure to change the properties for each time slot in the JavaScript code to ensure your design will appear the way you prefer.

I'm currently working on a new template for Blogger blogs which uses a variation of this script in a rather elegant way. I will put this up for download as soon as it's ready, but in the meantime I would love to see how you have used this script to personalize your own blogs!

Author: Amanda Kennedy

Amanda is a professional blogger and web designer living in Sheffield, United Kingdom.

In addition to curating Blogger Buster, you can find Amanda on Twitter, Facebook or add her to your circle on Google+.

Like to share?

You may also like to subscribe to Blogger Buster's RSS feed or receive free email updates of our latest posts.

50 Comments:

  1. This has to be one of the coolest things I've read!! :D I love my brother's mobile because it does something like this, and doing it in my blog would be amazing! But I think I'd have to tweek a bit on my template to make it work... Still, I love it!

    ReplyDelete
  2. Hi Amanda,
    The feature is indeed unique and cool, but I suspect that it will be implemented on a niche blog. I think mostly it will be implemented on personal blogs. My personal thinking is this, that a high traffic niche blog won't take the risk of implementing it, as the owner may think that changing colors of the layout frequently may annoy the visitors and drag them away. What do you think about this?

    But in the end, I must say that this feature is indeed very innovative and good.

    ReplyDelete
  3. hi amanda, you always do a great work and thanks to also always share it.

    this is out of topic, but is it possible in blogger to put a script enable us to display the counting number of a file has been downloaded so far?

    thank you in advance,
    gre

    ReplyDelete
  4. Amanda, this is wonderful. I have to try it on with two different backgrounds... but before I'll have to "photoshop" the currently one! perhaps with a lamplight... Thanks, i'm sure I'll find it useful soon!

    ReplyDelete
  5. For Ale,

    I used to have something similar on my phone (it would also change depending on my location). This is partly what inspired me to create this.

    It is possible to use this for background images (with a bit of tweaking) which I'm currently experimenting with for a new template.

    Thanks for stopping by to comment :)

    For Rajeev Edmonds:

    I agree that not many "professional" blogs would benefit from changing the background considerably at different times of day. This was one of the main reasons why I used such similar colors for each of the premade scripts.

    Certainly personal blogs, artistic and design style blogs too may use this to hreat effect. There's also the possibility of using the script to write a greeting message instead of a background script (eg: "Good Morning", "Good Evening").

    But just take a look at this site to see how well something similar to this may be integrated into a blog design. I'm sure you'll agree this is awesome!

    ReplyDelete
  6. For Template-Godown:

    This is something I've been wondering about myself but haven't yet had the time to research. I will be sure to post this though if I find a method which works! I'm sure this would be very useful in determining popular templates on our sites!

    For Yo Misma:

    I'm glad to know you find this useful :) For a template I'm working on, I used slightly different color filters for the background images (I'm not great with Photoshop) but I can't wait to see what you come up with!

    ReplyDelete
  7. What a great tip - I shall be looking at using this for my bespoke shirts blog for sure.

    ReplyDelete
  8. Hi, i'am 'Ran [read: run in English].
    I used "your time of day" on my blog and i like it very much,BIG THANKS.But i've tried to customized it [using background] but it didn't work, bcause i add "repeat x-y" after the image url.If i use small image for the background will it repeat the whole background?,Thanks

    Anyway, i really love ur site.It's very useful to me,much! And could you please visit my blog give a comment about how i'm doing for customizing blog so far.

    Note: it's not done yet.

    ReplyDelete
  9. WoW!
    Really smart script! It reminds me of my iGoogle Page which had the header image change with time.. maybe you should check that feature too :)

    Will tweak & add it on my blog (& then showoff! :D )

    ReplyDelete
  10. wew, make evolution baground....luv ur site.It's very useful.
    btw, can i replacing color in pale scheme?
    regards from indonesia

    ReplyDelete
  11. Hi, thanks for the great work you do! I am playing around with a test blog (so I don't disrupt my main blog), I implemented the code above to change the background image of the body and the header based on the time of day.

    I want to make the wrapper background black without making header background go black, is there a name for the part that encloses the sidebars and main areas that I can make black or is there a better way to do it?

    If you look at my blog, you will notice the sidebars are only black as far down as there is text, I want it to be black all the way down to the bottom of the page.
    http://w-test-1.blogspot.com/
    I thank you for your time.

    ReplyDelete
  12. OK, Amanda, I was able to get assistance for the sidebars going all the way to the bottom, now the next question, I hope you can answer this, I want to make the header image change along with the background, this is the code I used:

    OK, blogger will not allow me to include the code, you can see it here:
    http://wretha.googlepages.com/bk1.jpgbackgroundcolors.js


    Well, if you go to the test blog, http://wretha-test-2.blogspot.com/ you will see that the header image does not change, right now what you see is the graphic with a transparent "sky" area, the image I want to appear has my picture imbedded and there is no transparency, is there any way to make the header image change as well as the background?

    Thanks,
    Wretha

    http://wretha-test-2.blogspot.com/

    ReplyDelete
  13. Hi Amada, it's Wretha again, I finally figured out how to make the header image change according to the time of day as well along with the background.I had to make a separate js code for the header images. I also had to make a transparent gif the same size as my header images and upload that in the layout/page elements section, this acts as a place card for the header graphic (otherwise the header area shrinks up if there is nothing there) and it allows the header background image to show through. Anyhoo, check it out if you want:

    http://wretha-test-2.blogspot.com/

    Thanks as always!

    Wretha
    read about my adventures living 100% off grid
    http://wretha.blogspot.com

    ReplyDelete
  14. ps, Amanda, I know you have been busy working on your own blog (looks good!), but do you actually read the comments? (grin)

    Wretha
    read about my adventures living 100% off grid
    http://wretha.blogspot.com

    ReplyDelete
  15. Hi Amanda, welcome back, ignore my previous comment, I didn't know you had a back injury, hope everything is good now. :) Sometimes we (I) forget that life happens and it's not all about the computer...

    Wretha

    ReplyDelete
  16. can u make background changes everyday?
    n how about sidebars? can I change it too?


    thx ^^

    ReplyDelete
  17. Hmm..
    Anyway to make it such that only the Background image reloads and not the whole page? o.0

    ReplyDelete
  18. Hi Amanda,

    I would like to thank you for writing this great article.

    I already implemented it on my blog, I've done a few tweaks according to my needs.

    So, please drop by at http://nadzqa13.blogspot.com

    ReplyDelete
  19. thanks for the wonderful article.

    I'm using your script (with a few tweaks) at http://nadzqa13.blogspot.com

    ReplyDelete
  20. Thank you, I made it! Blogger Buster bookmarked!

    ReplyDelete
  21. Dear Amanda,
    Thank you for this post, it was very helpful though this did not exactly work with my Blogger template:
    i.e. I had to use " instead of ' and > instead of >
    This works rather well in conjunction with a background image that with a modified colour temperature:
    http://furelys.blogspot.com/
    :-)

    P.s. a similar script can also cause changes randomly:
    http://isuman.blogspot.com/2008/07/random-image-headers-for-blogger.html

    ReplyDelete
  22. Hi Amanda. I been reading your blog and is really nice and helpful, so helpful that I'm here to ask your permision to translate it to spanish as a post in my blog of course with your permission.
    And links pointing to your blog.
    Thank you in advance

    My Blog http://oliverosm.blogsot.com

    ReplyDelete
  23. This doesn't work because the .js file is down... Could you reupload it or write it complete here?

    Thanks a lot for this! :D

    ReplyDelete
  24. This looks amazing! It is actually the first time i see something like that. But, is it valid with blogger?

    ReplyDelete
  25. Thanks for the information you provided. It would be great if got more post like this. I appreciate it.

    ReplyDelete
  26. A quality set of two pearl or perhaps diamond stud pandora earrings is mostly a classic and also romantic reward. A very simple pendant on the chain is actually surely a vital as is often a quality wristwatch. Then again, no lovely women requirements not pandora uk one but two of any kind of basic item; just being aware of what she needs pandora charms is definitely what makes the treasure especially innovative and emotional. Examine the woman's personal design. pandora necklace If the girl wears bohemian shirts with worn-in denims, pandora jewellery consider some, funky beaded necklace around your neck or a new color bracelet.

    ReplyDelete
  27. Good stuff. It is interesting to read comments. russische frauen

    ReplyDelete
  28. holy food I am an everyday cook, providing everyday food for my family christian hospitality simply means the practice of being hospitable.religion and food Thanks for sharing the post spiritual foodis a must for every Christian.

    ReplyDelete
  29. First of all, thank you for taking the time to read my blog and allow me to share my business coaching (Corporate Coaching, Business Coaching and Life Coaching) plus a piece of my life with you.
    Coaching in business
    small business coaching

    ReplyDelete
  30. I will bookmark this site and visit again. It is very informative. Thanks for sharing.
    vrnjacka banja smestaj
    vrnjacka banja privatni smestaj

    ReplyDelete
  31. Changing background color in accordance to time of day seems like a good idea. This is brilliant. Now the steps may be a little complex but the benefits are astounding nevertheless.

    ReplyDelete
  32. Another great idea and def one I will be using in the future. Thanks

    ReplyDelete
  33. I'm so excited. I really appreciate sharing this great post. Keep up your excellent work.
    bojanke za decu
    bojanke
    gledanje u solju

    ReplyDelete
  34. We have just started designing stand alone blogs for clients and this is a nice little feature to use

    ReplyDelete
  35. Excellent post. I want to thank you for this informative read. I will bookmark this site and visit again..
    Banje u Srbiji
    Banje Srbije
    dnevni horoskop

    ReplyDelete
  36. Excellent article above. May be you need more time to share all the knowledge that you have. wolfies Joint So, thanks for Trilobyte Sales share this information with us, I always Outlandish Gypsy come across this amazing post.

    ReplyDelete
  37. Thanks for review. I like Ageyev the foundation of this blog has a great Asif 16 variety of comments I really like it, several points of view Margaret Hayden MD helps in the appreciation of the subject.

    ReplyDelete
  38. Thank you CF Terminals for this blog. That’s all I can say. You most definitely have made this blog into something that’s eye opening and important.Go To Castle You clearly know Your DNA Online so much about the subject, you’ve covered so many bases. Great stuff from this part of the internet. Again, thank you for this blog.Kenbrewer

    ReplyDelete
  39. I hope you can still doing this. Demco Smart Health I mean, Chateau Bayfield posting and searching Prudential Valley Real Estate useful things to share. I really appreciate this kind of information. RTD Enterprises The blog isn't bad, but you can change the style to written.

    ReplyDelete
  40. I recently came across your blog Svinsider and have been Southern Cherry reading along. Northbay Faith I think I will leave my first comment. I don’t know what to say except that I have enjoyed reading.Nice blog. Fiftyplus Advocates I will keep visiting this blog very often.

    ReplyDelete
  41. I just found this Riverbend Trading blog and have high hopes Get Benefits for Less for it to continue. Elemental 5 Keep up the great work, its hard to find good ones. Goldenwest Realty I have added to my favorites. Thank You.

    ReplyDelete
  42. This is a great post and thank Homes by Mazhar you for sharing this nice experience, DC Sanctuary and hope you can give another posts as soon as possible. Prostate Cancer Climb Nice site , Very Intresting post. Thank you .

    ReplyDelete
  43. Easily, Techno Mayhem the post is really the Jasso Tree Service sweetest on this worthwhile Patent Masters topic. I fit in Cheetah Boat MFG with your conclusions Power Punch Productions and will eagerly look forward to your approaching Your Health Counts updates. Saying Washington Coast thanks will not just be sufficient, for the exceptional clarity in your Wilberforce Inn writing. I will immediately grab your rss feed to stay privy of any updates.

    ReplyDelete
  44. canada goose jacketsDeduction is the chord: Yeah canada goose down jacket This metamorphosis of place in "the most mythical" total four: The first is the summit of the Kunlun sun sets canada goose down coats Stream canada goose parkas This "mysterious Wu Sanjie" almost level with their own canada goose vest Chen Jiachuan chat window has opened a secret: worry canada goose hat She remember the first two days of the year in late spring

    ReplyDelete
  45. It's really a great and helpful piece of information. I'm satisfied that you just shared this useful info with us. Please stay us up to date like this. Thank you for sharing.

    ReplyDelete
  46. Thanks to share with us the information. I wish you good luck!

    ReplyDelete
  47. Quite interesting post. I simply got nothing at all to do and so I'm just killing time browsing the net and I think that I've found some incredibly practical web page. Thanks a lot

    ReplyDelete

Great! You've decided to leave a comment! Please bear in mind that comments are often moderated and that rel="nofollow" is in use and spammy comments will be deleted. Let's have a meaningful conversation instead. Thanks for stopping by!

Browse through the Archives

All existing posts are still available to view while I'm working on the site, albeit seen in a much simpler interface. Feel free to browse through the archives to find tutorials, templates and articles to help you build a better blog:

Blog Archive

© Blogger Buster 2010 Home | About | Contact | Hire Me