{"id":17824742,"date":"2020-08-21T03:23:06","date_gmt":"2020-08-21T03:23:06","guid":{"rendered":"http:\/\/315_17824742"},"modified":"2020-12-03T05:45:15","modified_gmt":"2020-12-03T05:45:15","slug":"optimize-cumulative-layout-shift-for-better-visual-stability","status":"publish","type":"post","link":"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/","title":{"rendered":"Optimize Cumulative Layout Shift for better visual stability"},"content":{"rendered":"<p>\u00a0<\/p>\n<p><span data-preserver-spaces=\"true\">Cumulative Layout Shift deals with the issue of users facing unexpected layout shifts throughout their session. Let\u2019s say you are reading an interesting article, and suddenly something abrupt happens on the page, or maybe you click on a specific button and the whole layout shifts. It gets pretty annoying, and users tend to leave the site immediately.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">Before we begin, you can take a look at:<\/span><\/p>\n<p><strong><a href=\"https:\/\/blog.readwhere.com\/article\/optimizing-largest-contentful-paint-lcp-for-faster-loading-and-better-user\/315_17613402\">Optimizing Largest Contentful Paint (LCP) for faster loading and better user experience.<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/blog.readwhere.com\/article\/optimizing-first-input-delay-fid-for-better-interactivity-with-the\/315_17795970\">Optimizing First Input Delay (FID) for better interactivity with the user.<\/a><\/strong><\/p>\n<p><strong><span data-preserver-spaces=\"true\">What is the layout shift?<\/span><\/strong><\/p>\n<p><span data-preserver-spaces=\"true\">It is the unexpected behaviour or movement on a page that may usually occur due to existing elements changing their start position or when new elements are added, and as a result, the visible elements start to change their positions. The layout shift score is a product of two measures of that movement:-<\/span><\/p>\n<p><strong><span data-preserver-spaces=\"true\">Impact Fraction:\u00a0<\/span><\/strong><span data-preserver-spaces=\"true\">The impact fraction measures how unstable elements impact the viewport area between two frames where the areas of all unstable elements for the previous and current frame are measured.<\/span><\/p>\n<p><strong><span data-preserver-spaces=\"true\">Distance Fraction:\u00a0<\/span><\/strong><span data-preserver-spaces=\"true\">The distance fraction measures the distance that unstable elements have moved, relative to the viewport.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">A layout shift score is calculated as mentioned below:<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">Layout shift score = impact fraction * distance fraction<\/span><\/p>\n<p><a href=\"https:\/\/blog.readwhere.com\/article\/understanding-the-core-metrics-of-web-vitals-for-seamless-web-user\/315_17256191\"><strong>Understanding the core metrics of web vitals in detail.<\/strong><\/a><\/p>\n<p><strong><span data-preserver-spaces=\"true\">What is a good CLS score?<\/span><\/strong><\/p>\n<p><span data-preserver-spaces=\"true\">The sum total of all individual shift scores for each unexpected layout shift occurring is considered as CLS score. To provide a good user experience, the CLS score should be less than 0.1. A score between 0.1 and 0.25 needs improvement, and a score of more than 0.25 is considered to be poor.<\/span><\/p>\n<p><strong><span data-preserver-spaces=\"true\">Causes for poor CLS:<\/span><\/strong><\/p>\n<p><span data-preserver-spaces=\"true\">Let us take a look at the leading causes that lead to unexpected layout shifts and further a poor CLS.<\/span><\/p>\n<p><strong><span data-preserver-spaces=\"true\">Images without dimensions:\u00a0<\/span><\/strong><span data-preserver-spaces=\"true\">Back in earlier days, the developers used to mention width and height attributes to the images. Further, when they started using CSS to resize images, these attributes were no longer considered.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">However, in order to avoid layout shifting, one must include the width and height size attributes on the image and video elements. For responsive images, srcset defines the images you allow the browser to select between and what size each image is.\u00a0<\/span><\/p>\n<p><strong><a href=\"https:\/\/mobi.readwhere.com\/\">Choose Readwhere CMS to build a user-friendly website and boost your revenue.<\/a><\/strong><\/p>\n<p><strong><span data-preserver-spaces=\"true\">Ads, embeds, and iFrames without dimensions:\u00a0<\/span><\/strong><span data-preserver-spaces=\"true\">One of the major reasons for layout shifts is ads as usually the dynamic ad sizes are considered. At times, these ads push the visible content down the page and make the layout look clustered.\u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">One can follow the mentioned steps to reduce ad shifts:<\/span><\/p>\n<ol>\n<li><span data-preserver-spaces=\"true\">Reserve a space for ad slot<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Look after placing non- sticky ads near the top of the viewport.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Consider historical data for choosing a size for ad slots.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Reserve the largest possible size of the ad slot to eliminate shifts<\/span><\/li>\n<\/ol>\n<p><span data-preserver-spaces=\"true\">Platforms offering embeds can cause layout shifts as they do not always reserve enough space for the same. As the embeds can take a number of forms like inline HTML snippet, iframe embeds, HTML fallback and a JavaScript tag transforming the fallback into a fancy embed.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">Here is how you can deal with embeds:<\/span><\/p>\n<ol>\n<li><span data-preserver-spaces=\"true\">Obtain the height of your final embed by inspecting it with your browser developer tools<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Once the embed loads, the contained iframe will resize to fit so that its contents will fit.<\/span><\/li>\n<\/ol>\n<p><strong><span data-preserver-spaces=\"true\">Dynamically injected content:<\/span><\/strong><\/p>\n<p><span data-preserver-spaces=\"true\">Inserting new content above the existing content is also a significant reason for layout shifting. If you wish to have a good CLS score, avoid inserting new content above the existing one. You can experience layout shifts due to the UI that pops-in at the top or bottom of the viewport when you try to load a site. Instead, you can reserve sufficient space in the viewport for it in advance. Whenever it loads, it will not cause any shifts in the content.<\/span><\/p>\n<p><strong><span data-preserver-spaces=\"true\">Web Fonts causing FOIT\/ FOUT:<\/span><\/strong><\/p>\n<p><span data-preserver-spaces=\"true\">Having new font styles and emojis may look cool, but it can also cause layout shifts in the mentioned ways:<\/span><\/p>\n<ol>\n<li><span data-preserver-spaces=\"true\">The fallback font is swapped with a new font (FOUT &#8211; flash of unstyled text)<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">&#8220;Invisible&#8221; text is displayed until a new font is rendered (FOIT &#8211; flash of invisible text)<\/span><\/li>\n<\/ol>\n<p><span data-preserver-spaces=\"true\">The solution to the same can be obtained by using various developer tools.\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/web.dev\/optimize-cls\/\"><strong>Click here to know more about optimizing CLS and all the tools that can be used for sorting this out.\u00a0<\/strong><\/a><\/p>\n<p>You can always write to us at\u00a0<a href=\"mailto:helpdesk@readwhere.com\">helpdesk@readwhere.com<\/a>\u00a0if you wish to get going with web vitals for your business.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>       Optimizing a website for better user experience consists of various factors like load time, responsiveness, interactivity and visual stability. We have learned about core metrics of web vitals, Largest Contentful Paint deals with load time and First Input Delay deals with Interactivity. Now let us move further towards the last core metric, Cumulative Layout Shift (CLS) that deals with the visual stability of a site. <\/p>\n","protected":false},"author":3,"featured_media":28175146,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,5],"tags":[],"class_list":["post-17824742","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-next-gen-ux","category-readwhere-cms"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Optimize Cumulative Layout Shift for better visual stability - Readwhere Blog<\/title>\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.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Optimize Cumulative Layout Shift for better visual stability - Readwhere Blog\" \/>\n<meta property=\"og:description\" content=\"Optimizing a website for better user experience consists of various factors like load time, responsiveness, interactivity and visual stability. We have learned about core metrics of web vitals, Largest Contentful Paint deals with load time and First Input Delay deals with Interactivity. Now let us move further towards the last core metric, Cumulative Layout Shift (CLS) that deals with the visual stability of a site.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/\" \/>\n<meta property=\"og:site_name\" content=\"Readwhere Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-21T03:23:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-12-03T05:45:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.readwhere.com\/blog\/wp-content\/uploads\/2020\/08\/5f3f965ec40c5_new.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"700\" \/>\n\t<meta property=\"og:image:height\" content=\"466\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Neha Gore\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Neha Gore\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/\",\"url\":\"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/\",\"name\":\"Optimize Cumulative Layout Shift for better visual stability - Readwhere Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.readwhere.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.readwhere.com\/blog\/wp-content\/uploads\/2020\/08\/5f3f965ec40c5_new.jpg\",\"datePublished\":\"2020-08-21T03:23:06+00:00\",\"dateModified\":\"2020-12-03T05:45:15+00:00\",\"author\":{\"@id\":\"https:\/\/www.readwhere.com\/blog\/#\/schema\/person\/854eb40e61f8ea262f50c17bf7634f7d\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/#primaryimage\",\"url\":\"https:\/\/www.readwhere.com\/blog\/wp-content\/uploads\/2020\/08\/5f3f965ec40c5_new.jpg\",\"contentUrl\":\"https:\/\/www.readwhere.com\/blog\/wp-content\/uploads\/2020\/08\/5f3f965ec40c5_new.jpg\",\"width\":700,\"height\":466,\"caption\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.readwhere.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Optimize Cumulative Layout Shift for better visual stability\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.readwhere.com\/blog\/#website\",\"url\":\"https:\/\/www.readwhere.com\/blog\/\",\"name\":\"Readwhere Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.readwhere.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.readwhere.com\/blog\/#\/schema\/person\/854eb40e61f8ea262f50c17bf7634f7d\",\"name\":\"Neha Gore\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.readwhere.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c5f167cf3d09a2da0110801c8043e515018bb54db91f7008e3b8cfc34eb0a820?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c5f167cf3d09a2da0110801c8043e515018bb54db91f7008e3b8cfc34eb0a820?s=96&d=mm&r=g\",\"caption\":\"Neha Gore\"},\"url\":\"https:\/\/www.readwhere.com\/blog\/author\/neha-gore\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Optimize Cumulative Layout Shift for better visual stability - Readwhere Blog","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.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/","og_locale":"en_US","og_type":"article","og_title":"Optimize Cumulative Layout Shift for better visual stability - Readwhere Blog","og_description":"Optimizing a website for better user experience consists of various factors like load time, responsiveness, interactivity and visual stability. We have learned about core metrics of web vitals, Largest Contentful Paint deals with load time and First Input Delay deals with Interactivity. Now let us move further towards the last core metric, Cumulative Layout Shift (CLS) that deals with the visual stability of a site.","og_url":"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/","og_site_name":"Readwhere Blog","article_published_time":"2020-08-21T03:23:06+00:00","article_modified_time":"2020-12-03T05:45:15+00:00","og_image":[{"width":700,"height":466,"url":"https:\/\/www.readwhere.com\/blog\/wp-content\/uploads\/2020\/08\/5f3f965ec40c5_new.jpg","type":"image\/jpeg"}],"author":"Neha Gore","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Neha Gore","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/","url":"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/","name":"Optimize Cumulative Layout Shift for better visual stability - Readwhere Blog","isPartOf":{"@id":"https:\/\/www.readwhere.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/#primaryimage"},"image":{"@id":"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/#primaryimage"},"thumbnailUrl":"https:\/\/www.readwhere.com\/blog\/wp-content\/uploads\/2020\/08\/5f3f965ec40c5_new.jpg","datePublished":"2020-08-21T03:23:06+00:00","dateModified":"2020-12-03T05:45:15+00:00","author":{"@id":"https:\/\/www.readwhere.com\/blog\/#\/schema\/person\/854eb40e61f8ea262f50c17bf7634f7d"},"breadcrumb":{"@id":"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/#primaryimage","url":"https:\/\/www.readwhere.com\/blog\/wp-content\/uploads\/2020\/08\/5f3f965ec40c5_new.jpg","contentUrl":"https:\/\/www.readwhere.com\/blog\/wp-content\/uploads\/2020\/08\/5f3f965ec40c5_new.jpg","width":700,"height":466,"caption":""},{"@type":"BreadcrumbList","@id":"https:\/\/www.readwhere.com\/blog\/optimize-cumulative-layout-shift-for-better-visual-stability\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.readwhere.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Optimize Cumulative Layout Shift for better visual stability"}]},{"@type":"WebSite","@id":"https:\/\/www.readwhere.com\/blog\/#website","url":"https:\/\/www.readwhere.com\/blog\/","name":"Readwhere Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.readwhere.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.readwhere.com\/blog\/#\/schema\/person\/854eb40e61f8ea262f50c17bf7634f7d","name":"Neha Gore","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.readwhere.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c5f167cf3d09a2da0110801c8043e515018bb54db91f7008e3b8cfc34eb0a820?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c5f167cf3d09a2da0110801c8043e515018bb54db91f7008e3b8cfc34eb0a820?s=96&d=mm&r=g","caption":"Neha Gore"},"url":"https:\/\/www.readwhere.com\/blog\/author\/neha-gore\/"}]}},"_links":{"self":[{"href":"https:\/\/www.readwhere.com\/blog\/wp-json\/wp\/v2\/posts\/17824742","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.readwhere.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.readwhere.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.readwhere.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.readwhere.com\/blog\/wp-json\/wp\/v2\/comments?post=17824742"}],"version-history":[{"count":1,"href":"https:\/\/www.readwhere.com\/blog\/wp-json\/wp\/v2\/posts\/17824742\/revisions"}],"predecessor-version":[{"id":29326426,"href":"https:\/\/www.readwhere.com\/blog\/wp-json\/wp\/v2\/posts\/17824742\/revisions\/29326426"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.readwhere.com\/blog\/wp-json\/wp\/v2\/media\/28175146"}],"wp:attachment":[{"href":"https:\/\/www.readwhere.com\/blog\/wp-json\/wp\/v2\/media?parent=17824742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.readwhere.com\/blog\/wp-json\/wp\/v2\/categories?post=17824742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.readwhere.com\/blog\/wp-json\/wp\/v2\/tags?post=17824742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}