Kentico 13 EOS: Support ends Dec 31, 2026 - 218d 17h 56m left.

One Giant CSS File in Kentico: Why It Breaks Your Site and How to Fix It

DE
Devang
Nov 27, 2026 10 Minute Read
One Giant CSS File in Kentico: Why It Breaks Your Site and How to Fix It

Kentico CSS Conflicts: Fix the One Giant Stylesheet Problem

This blog explains what goes wrong when a Kentico website keeps all of its styles in one big CSS file, and how to split that file safely. The pattern is common. A project starts small, every new page or layout adds a few more rules to the end of style.css, and a year later the file holds thousands of lines that every visitor downloads on every page.

The result is slower pages, styles that overwrite each other and a team that is afraid to touch the stylesheet. The fix is not a rewrite. It is a clear structure: a small shared base, one stylesheet per layout, predictable class names, critical CSS for the first screen and a build tool that does the splitting for you. The examples below use Kentico Xperience 13 on ASP.NET Core, but the ideas apply to any .NET and Kentico setup.

The Problem: Every New Page Appends Styles to One Global Stylesheet

In a typical Kentico project, a developer builds a new page template or layout, writes the CSS it needs and pastes it at the bottom of the shared file. It is the quickest path, and on day one it works.

The trouble is that the stylesheet has no owner and no map. Nobody knows which rules belong to the home page, which belong to the blog layout and which are left over from a page that was deleted last spring. Deleting anything feels risky, so the file only grows.

Kentico adds a second pressure. Pages are built from layouts, page templates, widgets and sections, and editors can combine them in ways the developer never tested. A global file written for one layout meets a different layout on the same site, and the two do not always agree.

Why the Whole CSS Loads on Every Page

Browsers treat CSS as render-blocking. A page cannot paint until the browser has downloaded and parsed every stylesheet linked in the head. If a simple contact page links the same 400 KB file as your most complex landing page, the contact page pays for rules it never uses.

This affects real numbers that Google and your visitors care about:

  • Slower first paint. The browser waits for the full file before it shows anything.
  • Worse Core Web Vitals. Large blocking CSS can delay Largest Contentful Paint, especially on mobile networks.
  • More parsing work. Thousands of unused selectors still have to be parsed and matched against the page.
  • Poor caching. Change one line for one page and the whole file gets a new version, so every returning visitor downloads all of it again.

You can see the waste yourself. Open Chrome DevTools, go to the Coverage tab, reload a page and look at how much of the stylesheet is marked unused. On a long-lived site the answer is often most of it.

Style Conflicts Between Pages and Layouts

Because every rule lives in one global scope, a selector written for one page can change another. These are the conflicts Kentico teams meet most often:

  • Generic selectors. A rule such as .card { padding: 40px; } added for a service page quietly changes every card on the site.
  • Order-dependent overrides. Two rules with the same specificity are decided by which one comes last. Appending new CSS at the end of the file means the newest page always wins, even where it should not.
  • Specificity wars. To beat an old rule, someone adds a longer selector or !important. The next developer does the same, and the file turns into a pile of overrides.
  • Widget surprises. A widget looks right on the page it was designed for and breaks when an editor drops it into a different section or layout.

The root cause is the same each time: styles are not tied to the layout or component that needs them. The four solutions below fix that step by step. You do not have to use all of them, but they work well together.

Solution 1: Layout-Specific CSS Bundles

Since each Kentico page uses a layout, the layout is the natural place to decide which CSS loads. Split your CSS into a small base file shared by every page (reset, variables, typography, header and footer) and one file per layout (home, blog, landing, product and so on).

A suggested structure:

wwwroot/
  css/
    base.css            (shared on every page)
    layouts/
      home.css
      blog.css
      landing.css

Load the base file in the main layout and give each page layout a place to add its own stylesheet using a Razor section:

<!-- Views/Shared/_Layout.cshtml -->
<head>
    <link rel="stylesheet" href="/~/css/base.css" asp-append-version="true" />
    @await RenderSectionAsync("Styles", required: false)
    <page-builder-styles />
</head>
<!-- Views/Blog/Index.cshtml -->
@section Styles {
    <link rel="stylesheet" href="/~/css/layouts/blog.css" asp-append-version="true" />
}

Now the blog page downloads the base file plus the blog file, and nothing else. The asp-append-version attribute adds a content hash to the URL, so browsers cache each file for a long time and refetch it only when it changes. Keep the <page-builder-styles /> tag in the head so the Page Builder keeps working in the Kentico admin.

Solution 2: Scoped CSS with Page-Level Classes or BEM Naming

Splitting files reduces what loads. Naming rules well reduces what collides. BEM (Block, Element, Modifier) gives every class a name that shows where it belongs:

/* Block */        .service-card { }
/* Element */      .service-card__title { }
/* Modifier */     .service-card--featured { }

With BEM, the .card clash from earlier disappears. The service page uses .service-card and the blog uses .post-card, so neither can overwrite the other.

For layout-wide styles, add a class to the body or the page wrapper and use it as a scope:

<body class="layout-blog">

.layout-blog .hero { min-height: 320px; }
.layout-landing .hero { min-height: 640px; }

Two rules help the team stay consistent. Never style a bare element or a generic class like .title outside the base file, and never use !important to fix an order problem. If you need it, the structure is wrong.

Solution 3: Critical CSS Plus Lazy Loading the Rest

Critical CSS is the small set of rules needed to draw the part of the page the visitor sees first, usually the header, hero and first heading. You place it inline in the head, so the browser can paint straight away. The remaining CSS loads without blocking the first paint.

<style>
    /* inline critical CSS for this layout */
</style>
<link rel="preload" href="/~/css/layouts/blog.css" as="style"
      onload="this.onload=null;this.rel='stylesheet'" />
<noscript><link rel="stylesheet" href="/~/css/layouts/blog.css" /></noscript>

Tools such as the critical npm package can generate the inline block for each layout during your build. Be careful with two things. Keep the inline block small, because it is repeated in every HTML response. And test on a slow connection, since a badly chosen critical set can cause a flash of unstyled content. This step pays off most on landing pages where speed matters for conversions.

Solution 4: Using Webpack or Vite to Split CSS per Layout

Doing all of this by hand does not scale. A build tool lets you write CSS in small source files, then outputs the minified, hashed bundles for each layout automatically. Vite is a light option:

// vite.config.js
import { defineConfig } from 'vite';

export default defineConfig({
  build: {
    outDir: 'wwwroot/dist',
    manifest: true,
    rollupOptions: {
      input: {
        base:    'src/css/base.css',
        home:    'src/css/layouts/home.css',
        blog:    'src/css/layouts/blog.css',
        landing: 'src/css/layouts/landing.css'
      }
    }
  }
});

Each entry becomes its own file with a content hash in its name. The generated manifest.json maps the source name to the hashed file, and a small Razor helper can read it so your layouts always link the right version. If your project already uses Webpack, the same result comes from multiple entry points together with MiniCssExtractPlugin.

Build tools also give you extras for free: minification, autoprefixing and PurgeCSS to remove selectors that no template uses. Add the build step to your CI pipeline so every deployment ships fresh bundles. One warning for Kentico projects: widgets and Page Builder content may use classes that appear only in the database or in the editor, so always configure PurgeCSS to keep those classes in its safelist.

Before vs After: Page Load Comparison

The table below shows a typical improvement for a site that moves from one global file to layout bundles. The figures are illustrative. Your own results will vary, so measure before and after with Lighthouse or WebPageTest on the same page and the same network setting.

MeasureBefore (One Global File)After (Layout Bundles)
CSS downloaded per pageAbout 400 KB on every pageAbout 60 to 120 KB, depending on the layout
Unused CSS (Coverage tab)Often 70 to 90 percentOften under 30 percent
Render-blocking CSSOne large fileSmall base file plus critical inline CSS
Cache behaviourAny change invalidates everythingOnly the changed layout file is refetched
Risk of style conflictsHigh, with global scopeLow, with scoped names and separate files

Best Practices Checklist

  1. Audit first. Run the Coverage tab on your five most visited pages and note how much CSS is unused.
  2. Create a small shared base. Keep only truly global rules in it: variables, reset, typography, header and footer.
  3. One stylesheet per layout. Load it through a Razor section so each layout controls its own CSS.
  4. Adopt one naming convention. BEM works well, and the whole team should use the same one.
  5. Ban generic selectors and !important. Add a lint rule such as Stylelint to enforce this in code review.
  6. Inline critical CSS for key pages. Start with landing pages and your home page.
  7. Automate the build. Use Vite or Webpack, with hashed file names and a CI step.
  8. Test in the Page Builder. Check widgets in the Kentico admin, in preview and on the live site, because each one loads styles differently.
  9. Remove dead CSS carefully. Delete in small steps and test each layout after each change.

The End Result

A single giant stylesheet is easy to start with and expensive to keep. It slows every page, causes style conflicts between layouts and makes each change risky. Moving to a small base file, layout-specific bundles, clear naming, critical CSS and an automated build gives each page only the CSS it needs and gives your team a structure they can trust.

You do not need to do it all at once. Start with the audit, split out your heaviest layout and measure the difference. Once the first bundle ships and the numbers improve, the rest of the migration becomes much easier to justify.

Frequently Asked Questions

Why does my Kentico site load all of its CSS on every page?

Most often because the main layout links one shared stylesheet and every new page adds its rules to that same file. Kentico does not split CSS for you, so the structure has to come from your front-end code.

How do I load different CSS for different layouts in Kentico?

Add a Razor section such as Styles to your main layout, then use @section Styles in each page view or layout to link its own stylesheet. Keep a small base file in the main layout for shared styles.

Will splitting CSS break the Kentico Page Builder?

It should not, as long as you keep the Page Builder styles tag in the head and test your widgets in the admin. Check each widget in edit mode, preview and the live site after the change.

Is BEM enough to stop CSS conflicts?

It prevents most naming clashes, but it does not reduce the file size. Combine BEM with layout-specific bundles to fix both the conflicts and the performance problem.

Should I use Vite or Webpack for a Kentico project?

Either one works. Vite is lighter and faster to set up for new work, while Webpack is a sensible choice if your project already uses it. The important part is producing hashed, per-layout bundles automatically.

Need Help With Your Kentico Website?

At DotStark, we help teams clean up front-end structure, speed up Kentico sites and build maintainable .NET solutions. Contact us to talk about your project.

Devang
About the Author Devang

Devang Bhardwaj is an AIML Engineer at DotStark Technologies (India) Pvt. Ltd., specializing in machine learning, deep learning, and GenAI-driven systems. With hands-on experience building end-to-end intelligent solutions  - from data preparation and model development to API integration and deployment - he has worked on projects spanning RAG systems, computer vision, forecasting, and fine-tuning workflows. Skilled in Python, SQL, FastAPI, LangChain, PyTorch/TensorFlow, Docker, and vector database-based architectures, Devang is passionate about solving real-world problems through practical AI and continuously building systems that are both intelligent and production-ready.

Follow on LinkedIn
Share this article: Share on LinkedIn Copy Link
TAGS: Kentico