Remove unused CSS  |  Lighthouse  |  Chrome for Developers (2024)

The Opportunities section of your Lighthouse report listsall stylesheets with unused CSS with a potential savings of 2 KiB or more.Remove the unused CSSto reduce unnecessary bytes consumed by network activity:

Remove unused CSS | Lighthouse | Chrome for Developers (1)

How unused CSS slows down performance

Using a <link> tag is a common way to add styles to a page:

<!DOCTYPE html><html> <head> <link href="main.css" rel="stylesheet" /> ... </head></html>

The main.css file that the browser downloads is known as an external stylesheet,because it's stored separately from the HTML that uses it.

By default, a browser must download, parse, and process all external stylesheetsthat it encounters before it can display, or render, any content to a user's screen.It wouldn't make sense for a browser to attempt to display contentbefore the stylesheets have been processed,because the stylesheets may contain rules that affect the styling of the page.

Each external stylesheet must be downloaded from the network.These extra network trips can significantly increase the timethat users must wait before they see any content on their screens.

Unused CSS also slows down a browser's construction of therender tree.The render tree is like the DOM tree, except that it also includes the styles for each node.To construct the render tree, a browser must walk the entire DOM tree, and check which CSS rules apply to each node.The more unused CSS there is,the more time that a browser might potentially need to spend calculating the styles for each node.

How to detect unused CSS

The Coverage tab of Chrome DevTools can help you discover critical and uncritical CSS.See View used and unused CSS with the Coverage tab.

Remove unused CSS | Lighthouse | Chrome for Developers (2)

Inline critical CSS and defer non-critical CSS

Similar to inlining code in a <script> tag,inline critical styles required for the first paintinside a <style> block at the head of the HTML page.Then load the rest of the styles asynchronously using the preload link.

Consider automating the process of extracting and inlining "Above the Fold" CSSusing the Critical tool.

Learn more in Defer non-critical CSS.

Stack-specific guidance

Drupal

Consider removing unused CSS rules. Only attach the needed Drupal librariesto the relevant page or component in a page. See the Defining a libraryfor details.

Joomla

Consider reducing, or switching, the number of Joomla extensions loading unused CSS in your page.

WordPress

Consider reducing, or switching, the number of WordPress plugins loading unused CSS in your page.

Resources

Remove unused CSS  |  Lighthouse  |  Chrome for Developers (2024)

FAQs

Should I remove unused CSS? ›

Even if you use just one type of button on a page, it'll load all button styles. That's unused CSS. Reducing or removing unused CSS will improve your page speed performance and SEO.

How to get rid of unnecessary CSS? ›

How to manually remove unused CSS
  1. From the Show Coverage option, select a CSS file. ...
  2. Then, click on CSS Overview:
  3. Next, click on Capture Overview, and you'll be presented with the CSS overview page, as shown below:
  4. On this page, navigate to the Unused declarations option, and you'll be shown the page in the image below:
Aug 4, 2023

How do I remove unused CSS asset CleanUp? ›

Asset CleanUp Page Options

In the Manage CSS & JS page option, set the CSS that should not be loading on the page or post to be unloaded and when you save and refresh that page in your browser. The disabled/removed unused CSS assets will no longer be loading on the page or post.

How to find out unused CSS in a website? ›

To find unused code in your page, use the Coverage tool:
  1. To open DevTools, right-click the webpage, and then select Inspect. ...
  2. In DevTools, open the Command Menu. ...
  3. Start typing coverage, press the Down Arrow key to highlight the Show Coverage command, and then press Enter:
Dec 7, 2023

What is the impact of unused CSS? ›

Unused CSS also slows down a browser's construction of the render tree. The render tree is like the DOM tree, except that it also includes the styles for each node. To construct the render tree, a browser must walk the entire DOM tree, and check which CSS rules apply to each node.

Is there such a thing as too much CSS? ›

Solution (1): Yes, there is a thing such as using too much CSS. Everything must be used within limits, as overdoing negatively impacts the overall purpose. CSS is used to style the content and make a webpage visually appealing and presentable.

How do I clean up my CSS? ›

Table of Contents
  1. Best practices to write a clean and efficient CSS code.
  2. 1.1. Start with a framework.
  3. 1.2. CSS reset.
  4. 1.3. Maintain consistency.
  5. 1.4. Ensure it's readable.
  6. 1.5. Avoid the ! important tag.
  7. 1.6. Keep it DRY.
  8. 1.7. The right usage of CSS shorthand.

What does reduce unused CSS mean? ›

The Remove Unused CSS feature removes all CSS and stylesheets that are not used while keeping only the used CSS for each page. This feature can be enabled under the File Optimization tab, inside the Optimize CSS delivery feature, like this: Remove Unused CSS is the recommended method of optimizing your CSS.

Can I delete CSS files? ›

The number of unused CSS files has no effect on how your site ranks in Google, but if you want to delete files you don't want there is always the delete key.

What plugin removes unused CSS and JS? ›

Debloat – Remove Unused CSS, Optimize JS.

Does PostCSS remove unused CSS? ›

js simply bundles all CSS rules into some optimized files through PostCSS. In other words, it does not automatically remove unused CSS rules. Here is where PurgeCSS comes into play! Let's learn what PurgeCSS is, how it works, and how to configure it in a Next.

Can I extract CSS from a website? ›

SnipCSS extracts all CSS styles associated with any portion of a webpage. It works on all websites, and after a few clicks you get the CSS, HTML and Images associated with the section of the website you are trying to recreate. ANY COOL DESIGN YOU SEE ON THE WEB CAN BE YOUR PERSONAL TEMPLATE FOR QUICK PROTOTYPING!

How does tailwind remove unused CSS? ›

For example, Tailwind uses PurgeCSS to remove unused CSS from final builds automatically. Netflix Top 10 uses Tailwind on its entire website and only requires 6.5kB for the CSS file. The CSS file would be ten times the final build size without removing unused CSS.

How to reduce the number of used CSS files? ›

Here are some steps you can follow to achieve this:
  1. Use a performance analysis tool. Use a performance analysis tool like Google PageSpeed Insights, GTmetrix to identify the unused JavaScript and CSS on your website. ...
  2. Minimize your files. ...
  3. Use lazy loading. ...
  4. Remove unused apps and themes. ...
  5. Optimize images. ...
  6. Minimize HTTP requests.
Mar 6, 2023

Should you keep all CSS in one file? ›

If you're using static pages, each with its own styles, you absolutely want to split your CSS into separate files. It will distinctly reduce the size of your payload with each page delivered. If every page has to deliver the CSS of all other pages, every time they load, that's a lot of unnecessary traffic.

Why disable CSS? ›

By disabling CSS , the page content is displayed in the order of appearance in the code, so it's easy to check that the content is understandable in that order.

Top Articles
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 6755

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.