{"id":4820,"date":"2024-06-13T17:04:09","date_gmt":"2024-06-13T11:34:09","guid":{"rendered":"https:\/\/namastedev.com\/blog\/?p=4820"},"modified":"2024-06-13T17:04:09","modified_gmt":"2024-06-13T11:34:09","slug":"how-to-eliminate-flash-of-unstyled-text-fout-with-preload","status":"publish","type":"post","link":"https:\/\/namastedev.com\/blog\/how-to-eliminate-flash-of-unstyled-text-fout-with-preload\/","title":{"rendered":"How to Eliminate Flash of Unstyled Text (FOUT) with Preload"},"content":{"rendered":"<h1>Understanding the Flash of Unstyled Text (FOUT)<\/h1>\n<p>Have you ever noticed that when a website loads, the text initially appears in the browser&#8217;s default font before switching to the site&#8217;s specified font? This phenomenon, known as Flash of Unstyled Text (FOUT), can be a jarring experience for users and detracts from the site&#8217;s overall polish.<\/p>\n<h1>Why Does FOUT Happen?<\/h1>\n<p>FOUT occurs because the browser prioritizes loading other resources over your custom font files. As a result, the custom font is applied only after it has been fully loaded, leading to a noticeable shift from the default font to the custom font.<\/p>\n<h1>The Solution: Using Preload<\/h1>\n<p>To prevent FOUT, you can instruct the browser to load your font files as a priority. This is achieved using the <strong>rel=&#8221;preload&#8221;<\/strong> attribute in your HTML. By preloading your fonts, you ensure they are fetched earlier in the page load process, allowing the text to render with the correct font from the start.<\/p>\n<h1>Implementation Example<\/h1>\n<p>you are creating a simple website and on that website, you have two files first is\u00a0<strong>index.html<\/strong>\u00a0and second is\u00a0<strong>index.css<\/strong>. Now we want to use fonts on our website and the most common way to add font is something like this-<\/p>\n<pre class=\"ql-syntax\">&lt;link as=\"font\" href=\"https:\/\/fonts.googleapis.com\/css?family=Sofia\"&gt;\n<\/pre>\n<p>or you can add font using the font-face method &#8211;<\/p>\n<pre class=\"ql-syntax\">@font-face { font-family: Sofia; src: URL(https:\/\/fonts.googleapis.com\/css?\nfamily=Sofia); }\n<\/pre>\n<p>Now when your website renders the files there is a possibility that your font file will not fetch on priority and you will face problem of unStyled text. to solve this you can you use <strong>preload.<\/strong><\/p>\n<pre class=\"ql-syntax\">&lt;link rel=\"preload\" as=\"font\" href=\"https:\/\/fonts.googleapis.com\/css?\nfamily=Sofia\" type=\"font\/woff2\" crossorigin=\"anonymous\"&gt;\n<\/pre>\n<h1>Key Points to Remember<\/h1>\n<ol>\n<li><strong>Preload Only Critical Fonts<\/strong>: Use preload only for the fonts essential for initial rendering. Overusing preload can lead to other critical resources being delayed.<\/li>\n<li><strong>Specify the Type and Crossorigin<\/strong>: Ensure you specify the type of font and add crossorigin=&#8221;anonymous&#8221; if the font is hosted on a different origin.<\/li>\n<\/ol>\n<h1>Conclusion<\/h1>\n<p>By preloading your font resources, you can significantly improve the user experience on your website by eliminating FOUT. This simple yet effective technique ensures that your custom fonts are loaded as a priority, providing a seamless and visually consistent experience from the moment your page starts to load. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understanding the Flash of Unstyled Text (FOUT) Have you ever noticed that when a website loads, the text initially appears in the browser&#8217;s default font before switching to the site&#8217;s specified font? This phenomenon, known as Flash of Unstyled Text (FOUT), can be a jarring experience for users and detracts from the site&#8217;s overall polish.<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[231,334,183,182,262,172],"tags":[335,330],"class_list":{"0":"post-4820","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-article","7":"category-best-practices","8":"category-css","9":"category-html","10":"category-html-css","11":"category-javascript","12":"tag-best-practices","13":"tag-javascript"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/4820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/comments?post=4820"}],"version-history":[{"count":1,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/4820\/revisions"}],"predecessor-version":[{"id":4826,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/4820\/revisions\/4826"}],"wp:attachment":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/media?parent=4820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/categories?post=4820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/tags?post=4820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}