loading..

loading, please wait...
Mohit Aneja a.k.a CSSJockey

CSSJockey.com

Hello! I am Mohit Aneja, Designer and Developer based in India.
I believe in creating a Unique & Practical Web Presence not just html pages.
If you need some cool stuff, let's talk :)

An easy way to create Loading Bar!

“People count up the faults of those who keep them waiting”
Seems like I kept them busy decoding this loading bar :D

Recently, while browsing I landed on a page on StackOverflow.com where people were discussing about how I implemented this loading bar on CSSJockey.com. I could sense a lot of confusion in the discussion so thought I would take the mystery out as I love to share best practices. Here’s how you can create a loading bar in few steps..

Things You’ll Need

  1. A nice loading image: If you are good in creating animated GIF images that’s nice, otherwise you can create a loading image with this cool Ajax Loading Gif Generator.
  2. jQuery: We are creating this loading bar using jQuery so download jQuery latest version here.

jQuery Code within <head>..</head> tags

%MINIFYHTML39c8abdd681621d5b6fa145ffc7671bc19%%MINIFYHTML39c8abdd681621d5b6fa145ffc7671bc20%
javascript

HTML Code within <body>..</body>tags

Loading content, please wait.. loading..
html

Make sure you add this code just below the starting <body> tag so it should be downloaded first.

CSS Code for loading DIV

#loading {
    position:absolute;
    width:300px;
    top:0px;
    left:50%;
    margin-left:-150px;
    text-align:center;
    padding:7px 0 0 0;
    font:bold 11px Arial, Helvetica, sans-serif;
}
css

Use your imagination and create something nice & unique.

View Demo | Download Source Code

Your comment, suggestion and feedback is highly appreciated.

There’s more to come to stay tuned…

You may also like to read..

123 Comments on An easy way to create Loading Bar!


  1. Apr 25, 2013 / Cay Arcena:
    Is it possible for the loading bar to be shown in the middle of a video player or maybe a slideshow? Reply
    1. Apr 25, 2013 / Mohit Aneja:
      I am not sure what you ant to achieve by video player however, in a slideshow it can be programmed via jQuery and setInterval Javascript function. Reply
  2. Apr 19, 2013 / shweta:
    is it possible to show this loading bar at the bottom side of the page that contains other elements above it...? Reply
    1. Apr 23, 2013 / Mohit Aneja:
      Yes, You can change the CSS code to achieve the same. Reply
  3. Mar 24, 2013 / Gurmeet Singh:
    I have no words,how to say You done brillant work. That my first comment in site. Otherwise , i cannot comment anysite. I am beginner,and i learn jquery advanced topic. Help and Suggest me Thanks Reply
    1. Apr 23, 2013 / Mohit Aneja:
      Thanks. I am going to write tutorials on web development and cover a lot of topics. You can follow and learn with me. Reply
  4. Mar 24, 2013 / redet:
    nop but i went to use it for specific image or iframe, is it possible?thank you ! Reply
    1. Apr 23, 2013 / Mohit Aneja:
      Yes, You can have any content in the DIV tag and it will show up fine. You may consider the size and position of the same as per your desire. Reply
  5. Feb 19, 2013 / Ryan:
    Hey, just curious if you have the loading bar in any bigger size? BTW.. Thanks.... Reply
    1. Mar 02, 2013 / Mohit Aneja:
      Hello, You can create the gif image or create a stunning loading bar with jQuery animate function. Explore and have fun creating awesome stuff ;) Reply
    2. Apr 14, 2013 / Ahlam:
      just have the image in bigger dimensions Reply
  6. Feb 15, 2013 / CHoltzman:
    Is this compatible with IE (internet explorer) 6? or IE period?thanks Reply
    1. Mar 02, 2013 / Mohit Aneja:
      I haven't checked that in a while as I've abandoned IE for my personal work. You can check and if it doesn't work then you can apply the hacks. Reply
  7. Feb 03, 2013 / MAlik jeee:
    Thanks a lot! working for me :) Reply
  8. Jan 19, 2013 / ritik:
    Nice site Reply
  9. Jan 05, 2013 / BENJAMIN:
    Great tutorial! Reply
  10. Dec 19, 2012 / shubha:
    Thanks for providing a valuable tutorial. Reply
  11. Nov 25, 2012 / nk:
    Thanks so much! Reply
  12. Oct 16, 2012 / Jonathan:
    im trying to implement your code on an html page. brick wall each turn. any help is appreciated. Reply
  13. Aug 11, 2012 / Simi:
    Hey! I got some question about that load bar. Is that possible to implement such loading bar for script that is currently running??Thanks for help in advance! :) Simi Reply
    1. Apr 23, 2013 / Mohit Aneja:
      Yes, but you need to know that code and then implement and change the code as per your desire. Be careful, it may mess-up things if you do anything wrong. Reply
  14. Jul 23, 2012 / James:
    Thank you so much Mohit. I used your technique to make a full screen loading page: http://www.signaturedesign.co.za.thanks again! Reply
    1. Jul 23, 2012 / Mohit Aneja:
      I like the way you implemented the technique. Best of luck!! Reply
    2. Oct 07, 2012 / Arun:
      The Pagination in the Portfolio section is very difficult on other hand the loading part is observant.Thank You Reply
  15. Jul 12, 2012 / Manish Kumar:
    awsum man ! i got exactly same thing what i searching for :) Reply
  16. Jun 27, 2012 / sneha:
    Hi , Thanks a lot .its work for me. Reply
  17. Jun 24, 2012 / Menj:
    is it possible to redirect the loadingpage to a new page after the loading is complete? or just load the whole images and html when it reaches 100%? :) TY Reply
    1. Jul 23, 2012 / Mohit Aneja:
      Yes, you can use JS window.location to redirect users to another page once the loading is done. Reply
      1. Aug 08, 2012 / sensa:
        how can i creat a loading bar with percent(%) indicator ??????? Reply
        1. Apr 23, 2013 / Mohit Aneja:
          You can play with the CSS width property and change the same via jQuery .CSS method. Reply
      2. Oct 22, 2012 / Dennis:
        I have a project where I would like your process bar showing when an Button is press. the Button redirect to an other page. it takes some time before the page load, and I would like your indicator :D Hope you understand what I mean. Reply
        1. Mar 02, 2013 / Mohit Aneja:
          Hello Dennis,This could work however, when we click on the link which is directly linked to another page, the current page code stops working. You can try to implement the code but it may showup for a few seconds.. This could work really well with Ajax. Reply
  18. Jun 24, 2012 / Rezve Hasan:
    Thanks for usefull and short and practical tutorial. Reply
  19. May 22, 2012 / Shahbaz Ahmed Bhatti:
    nice work buddythank a lotssssssssssss Reply
  20. May 17, 2012 / Josu:
    Great.. thank you.. I'm using the jquery.js but hosted in google api instead of having it in my site. Great Job.... http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js Reply
  21. May 02, 2012 / ara:
    dear is it possible to have this loading bar in phpfox v3 because i am using phpfox v3 it is ajax browsing site , i have used the jQuery Code within .. tags but it did not worked if possible show a solution. thanks from your help Reply
    1. Apr 23, 2013 / Mohit Aneja:
      This code has nothing to do with php code, you just need to implement the required jQuery, HTML and CSS in your code and it will work. If you would like this work within the PHP functions, you would need to update or use the HTML and CSS of the code. Reply
  22. Mar 23, 2012 / Ritesh:
    what could be the possible reason for the loading code not to stop..?? it keeps on showing loading, even after the page has completely loaded. Reply
    1. Mar 28, 2012 / Mohit Aneja:
      Let me know the browser you are using. Try the demo in your browser and see if that works ok. If yes, please verify the code for ajax stop. Reply
    2. Apr 05, 2012 / Judy:
      Ritesh,After you downloaded the jquery file, did you rename it to jquery.js? Either that, or you can leave the jquery file name alone and change the script code to point to the jquery file you downloaded. You gotta do one or the other or it won't work. Reply
  23. Mar 18, 2012 / alcachofa:
    Unfortunately I can't use the Vitashine product, because of the soy. I'm really bummed about that. But it looks like there's a similar product that doesn't contain soy, that I may try. Has anyone had any experiences with this one? Reply
  24. Mar 03, 2012 / raj:
    i saw ur demo but its not working...?? Reply
    1. Mar 04, 2012 / Mohit Aneja:
      Hi Raj, I just checked the URL its working for me. http://www.cssjockey.com/files/downloads/code/loading/index.php Can you tell me the exact issue you are facing? Reply
  25. Mar 03, 2012 / syed mohammed ahmed:
    try this one Easy loading bar & logo effects with jQuery http://workwithphp.info/?p=38 Reply
    1. Mar 03, 2012 / Mohit Aneja:
      Nice trick, thanks for sharing. However, I believe loading these many images to show the loading bar would not be appropriate, you may combine the same into one image and use CSS sprites to have this kinda effect. Reply
  26. Mar 01, 2012 / Satu:
    Nope, you didn't delete my comment - I was trigger-happy on the 'submit' button... Sorry bro Reply
    1. Mar 01, 2012 / Mohit Aneja:
      You can display any content with this trick till the window loads completely, try the same and let me know if you face any issues. Note: Flash loading bar needs to be downloaded first to be displayed before the window loads all other content. Reply
  27. Mar 01, 2012 / Satu:
    Hey - you deleted my comment so I guess the answer is no, you can't incorporate a flash loading bar into this? Reply
  28. Feb 29, 2012 / Satu:
    This looks great, thank you!!Would it be possible to incorporate a flash loading bar, instead of an animated gif?Thanks! Reply
    1. May 11, 2013 / Mohit Aneja:
      Flash takes some time to load so I guess, we should avoid using flash .swf for loading as this may not give us the desired result. Reply
  29. Feb 26, 2012 / Benjamin:
    I used the code and everything works just fine. However, i can't really see my animation because the page loads so fast :( Reply
    1. Feb 27, 2012 / Mohit Aneja:
      Try to include a heavy image and refresh the page by clearing the cache. Command+F5 on MAC or CTRL+F5 on Windows should work. Reply
  30. Feb 16, 2012 / Mike:
    I'm trying to implement this on my site, but for some reason the loading div never disappears? Is there a common reason for this? Reply
    1. Feb 27, 2012 / Mohit Aneja:
      My be your page loads too fast, try including a high resolution image and refresh the with with cleared browser cache. Reply
  31. Dec 26, 2011 / rajendra:
    Superb. Fantastic I like so much. Thanks Reply
  32. Dec 20, 2011 / Lithxe:
    Thank you so much for this, it is exactly what I was looking for! :) Reply
  33. Dec 15, 2011 / Titis Kaifa:
    Thanks so much. :) Reply
  34. Dec 13, 2011 / Allison Reeta:
    Great tutorial! Added to favorites and bookmarked this site! Reply
  35. Dec 05, 2011 / Dominicanstan:
    Thanks!!! Reply
  36. Oct 17, 2011 / James:
    Thanks so much Mohit.So I'm a complete novice when it comes to Java. I was wondering how I can substitute the "$(window)" bit for a div so that when a certain div is finished loading it executes the "$("#loading").hide();" part, instead of wait Any ideas? I've tried the below but couldnt get it to work: $("#slideshow").load(function(){ $("#home-load").hide(); })Thanks again. Reply
    1. Oct 17, 2011 / James:
      Never mind! Found solution. It was to use an "onload" command on an image in a certain div on my page. That triggers the hide loadingscreen function.function loadingscreen() { $("#home-load").hide(); }I then did the following: <img src="images/Services-Sub4.png" alt="Printing" onload="loadingscreen()"My gallery is 8mb in size, so I didnt want the user waiting for that long while the whole gallery downloads, only a segment of it.:P Reply
  37. Sep 23, 2011 / gino:
    I have a gif file and want to add it as my loading screen page,but I am using wordpress and cannot figure out where to insert the code. Reply
    1. Nov 12, 2011 / Mohit Aneja:
      You can add the code in your theme files, use header.php or footer.php to insert the code for all pages. Reply
  38. Sep 02, 2011 / Shivam Sharma:
    mohit bro i need ur help :( i want to delete out going links from footer can u pls help me they r comin from theme server :( Reply
    1. Nov 12, 2011 / Mohit Aneja:
      Please send me more details to my email address and will discuss the same. Reply
  39. Jul 24, 2011 / Jocuri Mario:
    Cool blog! I really enjoy it. Reply
    1. Aug 07, 2011 / CSSJockey:
      Thanks, I am glad you like what I do :) Reply
  40. Jun 02, 2011 / pp:
    Hi, I was wondering where do you put the 'CSS Code for loading DIV' within the html script? :s Reply
  41. May 06, 2011 / Abal2:
    I have tried it in visual studio but it's not working. do you have any idea?thanks Abal2 Reply
    1. May 07, 2011 / CSSJockey:
      If you have written the same code, it should work. use firebug to debug and test. Reply
      1. May 10, 2011 / Abal2:
        Ok, I'll try. I'll ask you again, if I'm still confused. Thank you very much Reply
  42. May 04, 2011 / Orif Mahmanov:
    Thank you very much. It is very useful for me! Reply
  43. Apr 22, 2011 / jamsheed:
    First of all Thank you very much...!This is the One i am searching for the whole day...(Thanks to Google also)Well done..Keep posting...... Reply
  44. Apr 15, 2011 / Rob:
    Worked first time, 3rd i've tried, only one that works!Well Done! Reply
  45. Apr 08, 2011 / Gary:
    Great tutorial! Can you think of why it would not work in IE7? FF and EI8 it works like a charm, in EI7 I get the bar with no animation...I have jquery-1.2.6.min.js on the page and loaded on the server.Thank you for sharing.Gary Reply
    1. Apr 14, 2011 / CSSJockey:
      I guess with animation you mean the bar, its an image so check the paths.. Reply
      1. Apr 15, 2011 / Gary:
        Thank you for your reply, no I meant that the image does not animate in IE7, it displays the image, but it does not animate. It works perfect in FF, so it would seem to be a browser specific issue.In fact, I just checked your demo, and it does not work in IE7, however it is working in IE8, so I am guessing I must have some setting in my IE7 that is not allowing the animation...If you can think of anything, that would be great, if not, thank you for the code and for your reply.gary Reply
  46. Mar 11, 2011 / t.v.vignesh:
    Awesome!! Gr8 job.. Its perfectly working... Coool too.. Reply
  47. Mar 10, 2011 / ochusu:
    I have the same question as "Arjhun" I would like to know how to make my loading bar appear first and then once the page is done loading Have my contexts appear and were do i put the the "CSS Code for loading DIV" I'm new to this kind of things so I would be overly happy for any help you could provide. Reply
  48. Feb 28, 2011 / Ranjit:
    Its really interesting... Cool.. Thanks Jockey... Reply
  49. Feb 09, 2011 / Rahul:
    thnx a lot for this step by step procedure to incorporate a loading bar . Reply
    1. Feb 10, 2011 / CSSJockey:
      Your welcome, I am glad it helped!! Reply
  50. Jan 28, 2011 / EmiNarcissus:
    This passage helps a lot. I am creating my own greasemonkey tweats. So creating a loading layer just about to be the problem. Thx a lot~ Reply
  51. Dec 28, 2010 / Arif Samoon:
    Worked like a charm. Especially, the comments along with the code made things quick and easy.Thanks a lot. Reply
  52. Nov 03, 2010 / Shell:
    CAn yu make a loading bar to go in my signature on my phone someone got it but they want tell me how Reply
  53. Oct 20, 2010 / Martynas:
    This script is not working when content is being generated by PHP. My PHP content is generated by HTML DOM parser. Reply
    1. Oct 21, 2010 / CSSJockey:
      You would need to tweek the script as per your requirements.. I hope you get an idea of how its done ;) Reply
    2. Oct 21, 2010 / CSSJockey:
      You would need to tweak the script as per your requirements.. I hope you get an idea of how its done ;) Reply
  54. Oct 14, 2010 / vicky:
    thanks... its very simple........great work.....:D Reply
  55. Aug 24, 2010 / chestaz:
    thnk for sharing....if u dont mind can u sharing loading code for ur page.. Reply
    1. Aug 26, 2010 / CSSJockey:
      Sure, I'll try to write a tutorial on this next week. Thanks!! Reply
  56. Aug 18, 2010 / Saamiul Bashar:
    I see that you have updated your loading bar with a lightbox effect. I have tried combining them, but it didn't work. Would you be able to update your tutorial for this? Reply
    1. Aug 18, 2010 / CSSJockey:
      Replied to your previous comment, try that code. I'll try to write a tutorial for the same.. Reply
  57. Jul 25, 2010 / A.S:
    hi I insert the codes. How can i preview it in my local pc, before upload it to server? tnx Reply
    1. Jul 26, 2010 / CSSJockey:
      You need to install a local server on your computer to replicate similar environment on your local computer. For PC you can download Wamp and if you are using Mac or Linux you can download XAMPP or MAMP. Reply
  58. Jul 20, 2010 / snowflake:
    Thank you so much...useful tip Reply
  59. Jun 25, 2010 / bainur:
    great post.. nice and awesome. thank you... Reply
  60. Jun 02, 2010 / Joc:
    Well nice tutorial but this only waits until the DOM is loaded i think, and it doesnt really check if all the images and stuff have loaded.Oh, someone asked about a percentage loading bar: Well, you cant do a percentage loading bar for all loading things, especially for a webpage! Reply
  61. May 25, 2010 / Vivek Kumar Sharma:
    very nice tutorial. i wish a body which want get sure from it.thanks Reply
  62. May 13, 2010 / Michael Horton:
    Really Nice thanks. Reply
  63. May 10, 2010 / Wesker:
    Excellent!!!Thank you. I've already tested on my site and works perfect!!!! Reply
  64. Apr 26, 2010 / Louis Mark Johnson:
    Hello to all,What I want to do, is create a loading thing [ i already have mine ready for use ] but to show it for say 5 seconds then it re-direct to another webpage .. is there a way to do this.. well.. I'm sure there is tbh, Please help, thanks ! Reply
    1. May 19, 2010 / CSSJockey:
      You can use Javascript setTimeout() function to achieve this. Reply
  65. Jan 22, 2010 / Harry:
    Hi, Mohit. Another great tips after Santa's says on dec. I will try in myblog. Thanks Reply
  66. Jan 16, 2010 / destry:
    I see how this works for a page loading, but do you know how to do something like this if you are waiting for the content to be generated in php?Thanks Reply
    1. Jan 18, 2010 / CSSJockey:
      @destry: If you are using ajax you can call the loading bar within your code. In jQuery you can use the following code:$("#loading").ajaxStart(function(){ $(this).show(); }); Reply
  67. Jan 12, 2010 / Tran Tuan Anh:
    Huh, i can't see the preview image. Btw, nice work. Reply
  68. Jan 02, 2010 / Arjhun:
    well i would like to know how to make my loading bar appear first and then once the page is done loading it should redirect the person .. any ideas ?? please email me at arjhun.s@gmail.com .. thanx people Reply
  69. Dec 11, 2009 / DeKo:
    Great tip, thank you. Reply
  70. Nov 23, 2009 / Muhammad:
    Great work.. !! Thanks for sharing. Reply
  71. Sep 03, 2009 / A2f:
    Thanks for the tutorial, i will use that in my page. I wish it would also show the percantage... Reply
  72. Jul 09, 2009 / Mike:
    This is wonderful! Thank you so much!Quick question:How would I call that top function if a form was submitted? I have a file upload section I am working on and could use a cool loading bar like this when the upload form is submitted... Reply
    1. Jul 09, 2009 / CSSJockey:
      You can use this function on $("#formid").submit() and use $.ajax(options) to accomplish this. Here's an example:$.ajax({ type: "POST", url: "some.php", data: "name=John&location=Boston", success: function(msg){ alert( "Data Saved: " + msg ); } }); Reply
  73. May 26, 2009 / Cody:
    Thanks for the post. Relatively easy....it took me some time to get the jQuery to work. Reply
  74. Apr 30, 2009 / Tech @ InkAPoint:
    Good post dude. Reply
  75. Apr 27, 2009 / Ashok:
    hi i have tried progress bar in my site.it works fine. but it not displays all the time. Moreover while displaying this image, it looks displaying in separate page. i want to display it in my current page when the page takes more time to load......Any ideas... Reply
    1. Apr 27, 2009 / CSSJockey:
      Please share the link of your website where you're trying to display the loading/progress bar, so that I can take a look and help you out with any issues. Reply
  76. Mar 04, 2009 / Raymond Ho:
    Mohit Aneja,That was very helpful Mohit!! I never thought that you'll find my question in Stackoverflow!I'll definitely never forget your helpful spirit!How did you know about the question in Stackoverflow? You are not even registered user yet! Reply
    1. Mar 04, 2009 / CSSJockey:
      I saw a link back in WordPress Dashboard and checked your entry on Stackoverflow.com. I love to share best practices so thought answering this question will be a good start.You can join our Google Group and be a part of CJ community http://groups.google.com/group/cssjockey Reply
  77. Mar 04, 2009 / Abhinav Sood:
    Thanks for sharing - Nifty tip! Reply
  78. Mar 04, 2009 / sammie:
    excellent tutorial. Reply
    1. Aug 09, 2011 / CSSJockey:
      Thanks :) Reply
  79. Mar 04, 2009 / Fretsnkeys:
    Thanks for sharing, I will try this on my website... Reply

Leave a Reply

Stay up-to-date

Get latest tutorials and articles directly in your email.

Subscribe in RSS Reader

Connect via Facebook

Follow me on Twitter

Visit our Google+ Profile

Connect via Skype

I keep my Skype open all day long while I work on my computer.
Feel free to ping me to start conversation.

I love good conversations!!
If you have some big ideas, suggestions, feedback,
or want to discuss your project give me a shout.

 
%d bloggers like this: