{"id":28847,"date":"2020-01-11T23:25:20","date_gmt":"2020-01-11T15:25:20","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=28847"},"modified":"2025-04-04T02:52:03","modified_gmt":"2025-04-03T18:52:03","slug":"animated-favicon-loader-javascript","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/","title":{"rendered":"How to Create an Animated Favicon Loader with JavaScript"},"content":{"rendered":"<p><strong>Favicons<\/strong> are a crucial part of online branding, they <strong>give a visual cue<\/strong> to users, and help them <strong>distinguish your site<\/strong> from others. Although most favicons are static, it is possible to <strong>create animated favicons<\/strong> as well.<\/p>\n<p>A constantly moving favicon is certainly annoying for most users, and also <a href=\"https:\/\/www.hongkiat.com\/blog\/accessibility-design-needs\/\">harms accessibility<\/a>, however when it\u2019s only animated for a short time <strong>in response to a user action or a background event<\/strong>, such as a page load, it can <strong>provide extra visual information<\/strong>\u2014therefore improving user experience.<\/p>\n<div class=\"ref-block ref-block--post\" id=\"ref-post-1\">\n\t\t\t\t\t<a href=\"https:\/\/www.hongkiat.com\/blog\/favicons-importance\/\" class=\"ref-block__link\" title=\"Read More: Let\u2019s Talk About the Importance of Favicons\" rel=\"bookmark\"><span class=\"screen-reader-text\">Let\u2019s Talk About the Importance of Favicons<\/span><\/a>\n<div class=\"ref-block__thumbnail img-thumb img-thumb--jumbo\" data-img='{ \"src\" : \"https:\/\/assets.hongkiat.com\/uploads\/thumbs\/250x160\/favicons-importance.jpg\" }'>\n\t\t\t\t\t\t\t<noscript>\n<style>.no-js #ref-block-post-16513 .ref-block__thumbnail { background-image: url(\"https:\/\/assets.hongkiat.com\/uploads\/thumbs\/250x160\/favicons-importance.jpg\"); }<\/style>\n<\/noscript>\n\t\t\t\t\t\t<\/div>\n<div class=\"ref-block__summary\">\n<h4 class=\"ref-title\">Let\u2019s Talk About the Importance of Favicons<\/h4>\n<p class=\"ref-description\">\n\t\t\t\t\t\tDiscover the importance of favicons for your website and learn how to create and implement them. Improve your...\t\t\t\t\t\t<span>Read more<\/span><\/p>\n<\/div>\n<\/div>\n<p>In this post, I\u2019ll show you how to create an <strong>animated circular loader in a HTML canvas<\/strong>, and how you can use it as a favicon. An <strong>animated favicon loader<\/strong> is a great tool to <strong>visualize the progress of any action<\/strong> performed on a page, such as file uploading or image processing. You can have a look at the <strong>demo belonging to this tutorial<\/strong> on <strong><a href=\"https:\/\/hongkiat.github.io\/favicon-canvas-loader\/\" target=\"_blank\" rel=\"noopener noreferrer\">Github<\/a><\/strong> as well.<\/p>\n<figure><a href=\"https:\/\/github.com\/hongkiat\/favicon-canvas-loader\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/animated-favicon-loader-javascript\/canvas-loader.gif\" width=\"700\" height=\"478\" alt=\"Canvas Loader Gif Demo\"><\/a><\/figure>\n<h2>1. Create the <code>&lt;canvas&gt;<\/code> element<\/h2>\n<p>First, we need to <strong>create a canvas animation<\/strong> that <strong>draws a full circle, 100 percent in total<\/strong> (this will be important when we need to increment the arc).<\/p>\n<pre>\r\n&lt;button id=lbtn&gt;Load&lt;\/button&gt;\r\n&lt;canvas id=cvl width=16 height=16&gt;&lt;\/canvas&gt;\r\n<\/pre>\n<p>I\u2019m using the standard favicon size, 16*16 pixels, for the canvas. You can use a size bigger than that if you want, but note that the canvas image will be <strong>scaled down to the 16<sup>2<\/sup> pixel area<\/strong> when it\u2019s applied as a favicon.<\/p>\n<h2>2. Check if <code>&lt;canvas&gt;<\/code> is supported<\/h2>\n<p>Inside the <a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/API\/GlobalEventHandlers\/onload\" target=\"_blank\" rel=\"noopener noreferrer\"><code>onload()<\/code><\/a> event handler, we <strong>get a reference for the canvas element<\/strong> [<code>cv<\/code>] using the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Document\/querySelector\" target=\"_blank\" rel=\"noopener noreferrer\"><code>querySelector()<\/code><\/a> method, and refer <strong>its 2D drawing context object<\/strong> [<code>ctx<\/code>] with the help of the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/HTMLCanvasElement\/getContext\" target=\"_blank\" rel=\"noopener noreferrer\"><code>getContext()<\/code> method<\/a>.<\/p>\n<pre>\r\nonload = function() {\r\n    cv = document.querySelector('#cvl'),\r\n    ctx = cv.getContext('2d');\r\n\r\n    if (!!ctx) {\r\n        \/* ... *\/\r\n    }\r\n};\r\n<\/pre>\n<p>We also need to check <strong>if the canvas is supported by the <abbr title=\"User Agent\">UA<\/abbr><\/strong> by making sure that the drawing context object [<code>ctx<\/code>] <strong>exists and isn\u2019t undefined<\/strong>. We\u2019ll place <strong>all the code belonging to the load event<\/strong> into this <code>if<\/code> condition.<\/p>\n<div class=\"ref-block ref-block--post\" id=\"ref-post-2\">\n\t\t\t\t\t<a href=\"https:\/\/www.hongkiat.com\/blog\/dom-manipulation-javascript-methods\/\" class=\"ref-block__link\" title=\"Read More: Master DOM Manipulation with 15 Essential JavaScript Methods\" rel=\"bookmark\"><span class=\"screen-reader-text\">Master DOM Manipulation with 15 Essential JavaScript Methods<\/span><\/a>\n<div class=\"ref-block__thumbnail img-thumb img-thumb--jumbo\" data-img='{ \"src\" : \"https:\/\/assets.hongkiat.com\/uploads\/thumbs\/250x160\/dom-manipulation-javascript-methods.jpg\" }'>\n\t\t\t\t\t\t\t<noscript>\n<style>.no-js #ref-block-post-28165 .ref-block__thumbnail { background-image: url(\"https:\/\/assets.hongkiat.com\/uploads\/thumbs\/250x160\/dom-manipulation-javascript-methods.jpg\"); }<\/style>\n<\/noscript>\n\t\t\t\t\t\t<\/div>\n<div class=\"ref-block__summary\">\n<h4 class=\"ref-title\">Master DOM Manipulation with 15 Essential JavaScript Methods<\/h4>\n<p class=\"ref-description\">\n\t\t\t\t\t\tAs a web developer, you frequently need to manipulate the DOM, the object model that is used by...\t\t\t\t\t\t<span>Read more<\/span><\/p>\n<\/div>\n<\/div>\n<h2>3. Create the initial variables<\/h2>\n<p>Let\u2019s create <strong>three more global variables<\/strong>, <code>s<\/code> for the <strong>starting angle of the arc<\/strong>, <code>tc<\/code> for the <strong>id for the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/WindowTimers\/setInterval\" target=\"_blank\" rel=\"noopener noreferrer\"><code>setInterval()<\/code><\/a> timer<\/strong>, and <code>pct<\/code> for the <strong>percentage value of the same timer<\/strong>. The code <code>tc = pct = 0<\/code> assigns 0 as the <strong>initial value<\/strong> for the <code>tc<\/code> and <code>pct<\/code> variables.<\/p>\n<pre>\r\nonload = function() {\r\n    cv = document.querySelector('#cvl'),\r\n    ctx = cv.getContext('2d');\r\n\r\n    if (!!ctx) {\r\n        s = 1.5 * Math.PI,\r\n        tc = pct = 0;\r\n    }\r\n};\r\n<\/pre>\n<p>To show how the value of <code>s<\/code> was calculated, let me quickly explain how <strong>arc angles<\/strong> work.<\/p>\n<h3>Arc angles<\/h3>\n<p>The <strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/Subtended_angle\" target=\"_blank\" rel=\"noopener noreferrer\">subtended angle<\/a><\/strong> (the angle composed of the two rays that define an arc) <strong>of the circumference of a circle<\/strong> is <strong>2\u03c0 rad<\/strong>, where <strong>rad<\/strong> is the <a href=\"https:\/\/www.wikiwand.com\/en\/Radian\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">radian<\/a> unit symbol. This makes the <strong>angle for a quarter arc<\/strong> equal to <strong>0.5\u03c0 rad<\/strong>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/animated-favicon-loader-javascript\/arc-angles.gif\" alt=\"subtended angle of circumference\" width=\"450\" height=\"450\"><\/figure>\n<p>When <strong>visualizing the loading progress<\/strong>, we want the circle on the canvas to be drawn <strong>from the top position<\/strong> rather than the default right.<\/p>\n<p><strong>Going clockwise<\/strong> (default direction arc is drawn on the canvas) <strong>from the right position<\/strong>, the top point is <strong>reached after three quarters<\/strong>, i.e. at an angle of <strong>1.5\u03c0 rad<\/strong>. Hence, I\u2019ve created the variable <code>s = 1.5 * Math.PI<\/code> to later <strong>denote the starting angle for the arcs<\/strong> to be drawn from on the canvas.<\/p>\n<h2>4. Style the circle<\/h2>\n<p>For the drawing context object, we define the <strong><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/CanvasRenderingContext2D\/lineWidth\" target=\"_blank\" rel=\"noopener noreferrer\"><code>lineWidth<\/code><\/a> and <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/CanvasRenderingContext2D\/strokeStyle\" target=\"_blank\" rel=\"noopener noreferrer\"><code>strokeStyle<\/code><\/a> properties of the circle<\/strong> we are going to draw in the next step. The <code>strokeStyle<\/code> property stands for its color.<\/p>\n<pre>\r\nonload = function() {\r\n    cv = document.querySelector('#cvl'),\r\n    ctx = cv.getContext('2d');\r\n\r\n    if (!!ctx) {\r\n        s = 1.5 * Math.PI,\r\n        tc = pct = 0;\r\n\r\n        ctx.lineWidth = 2;\r\n        ctx.strokeStyle = 'fuchsia';\r\n    }\r\n};\r\n<\/pre>\n<h2>5. Draw the circle<\/h2>\n<p>We <strong>add a click event handler<\/strong> to the <span class=\"key\">Load<\/span> button [<code>#lbtn<\/code>] which <strong>triggers a <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/WindowTimers\/setInterval\" target=\"_blank\" rel=\"noopener noreferrer\">setInterval<\/a> timer of 60 milliseconds<\/strong>, that executes the function responsible for drawing the circle [<code>updateLoader()<\/code>] every 60ms till the circle is fully drawn.<\/p>\n<p>The <code>setInterval()<\/code> method <strong>returns a timer id<\/strong> to identify its timer which is assigned to the <code>tc<\/code> variable.<\/p>\n<pre>\r\nonload = function() {\r\n    cv = document.querySelector('#cvl'),\r\n    ctx = cv.getContext('2d');\r\n\r\n    if (!!ctx) {\r\n        s = 1.5 * Math.PI,\r\n        tc = pct = 0,\r\n        btn = document.querySelector('#lbtn');\r\n\r\n        ctx.lineWidth = 2;\r\n        ctx.strokeStyle = 'fuchsia';\r\n\r\n        btn.addEventListener('click', function() {\r\n            tc = setInterval(updateLoader, 60);\r\n        });\r\n    }\r\n};\r\n<\/pre>\n<h2>6. Create the <code>updateLoader()<\/code> custom function<\/h2>\n<p>It\u2019s time to create the custom <code>updateLoader()<\/code> function that is to be <strong>called by the <code>setInterval()<\/code> method<\/strong> when the button is clicked (the event is triggered). Let me show you the code first, then we can go along with the explanation.<\/p>\n<pre>\r\nfunction updateLoader() {\r\n    ctx.clearRect(0, 0, 16, 16);\r\n    ctx.beginPath();\r\n    ctx.arc(8, 8, 6, s, (pct * 2 * Math.PI \/ 100 + s));\r\n    ctx.stroke();\r\n\r\n    if (pct === 100) {\r\n        clearInterval(tc);\r\n        return;\r\n    }\r\n\r\n    pct++;\r\n}\r\n<\/pre>\n<p>The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/CanvasRenderingContext2D\/clearRect\" target=\"_blank\" rel=\"noopener noreferrer\"><code>clearRect()<\/code><\/a> method <strong>clears the rectangular area of the canvas<\/strong> defined by its parameters: the (x, y) coordinates of the top-left corner. The <code>clearRect(0, 0, 16, 16)<\/code> line <strong>erases everything<\/strong> in the 16*16 pixels canvas we have created.<\/p>\n<p>The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/CanvasRenderingContext2D\/beginPath\" target=\"_blank\" rel=\"noopener noreferrer\"><code>beginPath()<\/code><\/a> method <strong>creates a new path<\/strong> for the drawing, and the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/CanvasRenderingContext2D\/stroke\" target=\"_blank\" rel=\"noopener noreferrer\"><code>stroke()<\/code><\/a> method <strong>paints on that newly created path<\/strong>.<\/p>\n<p>At the end of the <code>updateLoader()<\/code> function, the <strong>percentage count [<code>pct<\/code>] is incremented by 1<\/strong>, and prior to the increment we <strong>check if it equals to 100<\/strong>. When it\u2019s 100 percent, the <code>setInterval()<\/code> <strong>timer<\/strong> (identified by the timer id, <code>tc<\/code>) <strong>is cleared<\/strong> with the help of the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/WindowTimers\/clearInterval\" target=\"_blank\" rel=\"noopener noreferrer\"><code>clearInterval()<\/code><\/a> method.<\/p>\n<p>The first three parameters of the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/CanvasRenderingContext2D\/arc\" target=\"_blank\" rel=\"noopener noreferrer\"><code>arc()<\/code><\/a> method are the <strong>(x, y) coordinates of center of the arc<\/strong> and <strong>its radius<\/strong>. The fourth and fifth parameters represent the <strong>start and end angles<\/strong> at which the drawing of the arc begins and ends.<\/p>\n<p>We already decided the starting point of the loader circle, which is at the angle <code>s<\/code>, and it\u2019ll be the <strong>same in all the iterations<\/strong>.<\/p>\n<p>The end angle however will <strong>increment with the percent count<\/strong>, we can calculate the <strong>size of the increment<\/strong> in the following way. Say 1% (the value 1 out of 100) is <strong>equivalent to angle \u03b1 out of 2\u03c0 in a circle<\/strong> (2\u03c0 = angle of the whole circumference), then the same can be written as the following equation:<\/p>\n<pre>1\/100 = \u03b1\/2\u03c0<\/pre>\n<p>On rearranging the equation:<\/p>\n<pre>\r\n\u03b1 = 1 * 2\u03c0 \/100\r\n\u03b1 = 2\u03c0\/100\r\n<\/pre>\n<p>So, 1% is equivalent to the angle 2\u03c0\/100 in a circle. Thus, the end angle during each percent increment is <strong>computed by multiplying 2\u03c0\/100 by the percentage value<\/strong>. Then the result is <strong>added to <code>s<\/code> (start angle)<\/strong>, so the arcs are <strong>drawn from the same starting position<\/strong> every time. This is why we used the <code>pct * 2 * Math.PI \/ 100 + s<\/code> formula to calculate the end angle in the code snippet above.<\/p>\n<h2>7. Add the favicon<\/h2>\n<p>Let\u2019s place a <strong>favicon link element<\/strong> into the HTML <code>&lt;head&gt;<\/code> section, either directly or via JavaScript.<\/p>\n<pre>\r\n&lt;link rel=\"icon\" type=\"image\/ico\" &gt;\r\n<\/pre>\n<p>In the <code>updateLoader()<\/code> function, first we <strong>fetch the favicon<\/strong> using the <code>querySelector()<\/code> method, and assign it to the <code>lnk<\/code> variable. Then we need to <strong>export the canvas image<\/strong> every time an arc is drawn <strong>into an <a href=\"https:\/\/www.hongkiat.com\/blog\/css-encoded-image\/\">encoded image<\/a><\/strong> by using the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/HTMLCanvasElement\/toDataURL\" target=\"_blank\" rel=\"noopener noreferrer\"><code>toDataURL()<\/code><\/a> method, and <strong>assign that data URI content as the favicon image<\/strong>. This creates an animated favicon which is the <strong>same as the canvas loader<\/strong>.<\/p>\n<pre>\r\nonload = function() {\r\n    cv = document.querySelector('#cvl'),\r\n    ctx = cv.getContext('2d');\r\n\r\n    if (!!ctx) {\r\n        s = 1.5 * Math.PI,\r\n        tc = pct = 0,\r\n        btn = document.querySelector('#lbtn'),\r\n        lnk = document.querySelector('link[rel=\"icon\"]');\r\n\r\n        ctx.lineWidth = 2;\r\n        ctx.strokeStyle = 'fuchsia';\r\n\r\n        btn.addEventListener('click', function() {\r\n            tc = setInterval(updateLoader, 60);\r\n        });\r\n    }\r\n};\r\n\r\nfunction updateLoader() {\r\n    ctx.clearRect(0, 0, 16, 16);\r\n    ctx.beginPath();\r\n    ctx.arc(8, 8, 6, s, (pct * 2 * Math.PI \/ 100 + s));\r\n    ctx.stroke();\r\n\r\n    lnk.href= cv.toDataURL('image\/png');\r\n\r\n    if (pct === 100) {\r\n        clearTimeout(tc);\r\n        return;\r\n    }\r\n\r\n    pct++;\r\n}\r\n<\/pre>\n<p>You can have a look at the full code <strong><a href=\"https:\/\/github.com\/hongkiat\/favicon-canvas-loader\" target=\"_blank\" rel=\"noopener noreferrer\">on Github<\/a><\/strong>.<\/p>\n<h2>Bonus: Use the loader for async events<\/h2>\n<p>When you need to use this canvas animation <strong>in conjunction with a loading action<\/strong> in a web page, assign the <code>updateLoader()<\/code> function <strong>as the event handler for the <a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/API\/XMLHttpRequest\/Using_XMLHttpRequest#Monitoring_progress\" target=\"_blank\" rel=\"noopener noreferrer\"><code>progress()<\/code><\/a> event of the action<\/strong>.<\/p>\n<p class=\"note\"> <strong>Recommended Reading:<\/strong> <a href=\"https:\/\/www.hongkiat.com\/blog\/synchronous-asynchronous-javascript\/\">Understanding Synchronous and Asynchronous JavaScript \u2013 Part 1<\/a><\/p>\n<p>For instance, our JavaScript will change like this <strong>in AJAX<\/strong>:<\/p>\n<pre>\r\nonload = function() {\r\n    cv = document.querySelector('#cvl'),\r\n    ctx = cv.getContext('2d');\r\n\r\n    if (!!ctx) {\r\n        s = 1.5 * Math.PI,\r\n        lnk = document.querySelector('link[rel=\"icon\"]');\r\n\r\n        ctx.lineWidth = 2;\r\n        ctx.strokeStyle = 'fuchsia';\r\n    }\r\n\r\n    var xhr = new XMLHttpRequest();\r\n    xhr.addEventListener('progress', updateLoader);\r\n    xhr.open('GET', 'https:\/\/xyz.com\/abc');\r\n    xhr.send();\r\n};\r\n\r\nfunction updateLoader(evt) {\r\n    ctx.clearRect(0, 0, 16, 16);\r\n    ctx.beginPath();\r\n    ctx.arc(8, 8, 6, s, (evt.loaded*2*Math.PI\/evt.total+s));\r\n    ctx.stroke();\r\n\r\n    lnk.href = cv.toDataURL('image\/png');\r\n}\r\n<\/pre>\n<p>In the <code>arc()<\/code> method, replace the percentage value [<code>pct<\/code>] with the <strong><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/ProgressEvent\/loaded\" target=\"_blank\" rel=\"noopener noreferrer\"><code>loaded<\/code><\/a> property of the event<\/strong>\u2014it denotes how much of the file has been loaded, and in place of <code>100<\/code> use the <strong><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/ProgressEvent\/total\" target=\"_blank\" rel=\"noopener noreferrer\"><code>total<\/code><\/a> property of the ProgressEvent<\/strong>, which denotes the total amount to be loaded.<\/p>\n<p>There\u2019s <strong>no need for <code>setInterval()<\/code><\/strong> in such cases, as the <code>progress()<\/code> event is <strong>automatically fired<\/strong> as the loading progresses.<\/p>","protected":false},"excerpt":{"rendered":"<p>Favicons are a crucial part of online branding, they give a visual cue to users, and help them distinguish your site from others. Although most favicons are static, it is possible to create animated favicons as well. A constantly moving favicon is certainly annoying for most users, and also harms accessibility, however when it\u2019s only&hellip;<\/p>\n","protected":false},"author":145,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392],"tags":[826,4117,511],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Create an Animated Favicon Loader with JavaScript - Hongkiat<\/title>\n<meta name=\"description\" content=\"Favicons are a crucial part of online branding, they give a visual cue to users, and help them distinguish your site from others. Although most favicons\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create an Animated Favicon Loader with JavaScript\" \/>\n<meta property=\"og:description\" content=\"Favicons are a crucial part of online branding, they give a visual cue to users, and help them distinguish your site from others. Although most favicons\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-11T15:25:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-03T18:52:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/animated-favicon-loader-javascript\/canvas-loader.gif\" \/>\n<meta name=\"author\" content=\"Preethi Ranjit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Preethi Ranjit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/\"},\"author\":{\"name\":\"Preethi Ranjit\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\"},\"headline\":\"How to Create an Animated Favicon Loader with JavaScript\",\"datePublished\":\"2020-01-11T15:25:20+00:00\",\"dateModified\":\"2025-04-03T18:52:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/\"},\"wordCount\":1117,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/animated-favicon-loader-javascript\\\/canvas-loader.gif\",\"keywords\":[\"Favicons\",\"Javascripts\",\"Web Developers\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/\",\"name\":\"How to Create an Animated Favicon Loader with JavaScript - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/animated-favicon-loader-javascript\\\/canvas-loader.gif\",\"datePublished\":\"2020-01-11T15:25:20+00:00\",\"dateModified\":\"2025-04-03T18:52:03+00:00\",\"description\":\"Favicons are a crucial part of online branding, they give a visual cue to users, and help them distinguish your site from others. Although most favicons\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/animated-favicon-loader-javascript\\\/canvas-loader.gif\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/animated-favicon-loader-javascript\\\/canvas-loader.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/animated-favicon-loader-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create an Animated Favicon Loader with JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\",\"name\":\"Preethi Ranjit\",\"description\":\"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/preethi\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Create an Animated Favicon Loader with JavaScript - Hongkiat","description":"Favicons are a crucial part of online branding, they give a visual cue to users, and help them distinguish your site from others. Although most favicons","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to Create an Animated Favicon Loader with JavaScript","og_description":"Favicons are a crucial part of online branding, they give a visual cue to users, and help them distinguish your site from others. Although most favicons","og_url":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2020-01-11T15:25:20+00:00","article_modified_time":"2025-04-03T18:52:03+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/animated-favicon-loader-javascript\/canvas-loader.gif","type":"","width":"","height":""}],"author":"Preethi Ranjit","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Preethi Ranjit","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/"},"author":{"name":"Preethi Ranjit","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3"},"headline":"How to Create an Animated Favicon Loader with JavaScript","datePublished":"2020-01-11T15:25:20+00:00","dateModified":"2025-04-03T18:52:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/"},"wordCount":1117,"commentCount":2,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/animated-favicon-loader-javascript\/canvas-loader.gif","keywords":["Favicons","Javascripts","Web Developers"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/","url":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/","name":"How to Create an Animated Favicon Loader with JavaScript - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/animated-favicon-loader-javascript\/canvas-loader.gif","datePublished":"2020-01-11T15:25:20+00:00","dateModified":"2025-04-03T18:52:03+00:00","description":"Favicons are a crucial part of online branding, they give a visual cue to users, and help them distinguish your site from others. Although most favicons","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/animated-favicon-loader-javascript\/canvas-loader.gif","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/animated-favicon-loader-javascript\/canvas-loader.gif"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/animated-favicon-loader-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create an Animated Favicon Loader with JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3","name":"Preethi Ranjit","description":"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.","url":"https:\/\/www.hongkiat.com\/blog\/author\/preethi\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-7vh","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/28847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/145"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=28847"}],"version-history":[{"count":3,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/28847\/revisions"}],"predecessor-version":[{"id":73745,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/28847\/revisions\/73745"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=28847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=28847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=28847"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=28847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}