Skip to header Skip to main navigation Skip to main content Skip to footer
Cookies UI
Alaa Haddad Offers Exceptional Drupal Custom Theming and Modules in Austin TX Alaa Haddad - Drupal Expert
Main navigation
  • Professional Profile
  • Drupal Services
    • Drupal Development
    • Drupal Developer
    • Drupal Themer
    • Drupal Architect
    • Drupal Consultant
  • My Drupal Modules & Themes
      • Cloudflare Purge
      • Solo Copy Blocks
      • W3CSS Paragraphs
      • Paragraphs Bundles
      • Acquia Purge Varnish
      • Reference Blocked Users
      • Module Matrix
      • Paragraphs Bundles Import
      • Selectify
      • Solo Utilities
      • Utilikit
      • Solo
      • Amun
      • Anhur
      • Amunet
      • W3CSS Theme
      • 3D Carousel
      • 3D FlipBox
      • Accordion
      • Carousel
      • Hero
      • Lightbox
      • Parallax
      • Reveal
      • Slideshow
      • Tabs
  • Blog
  • Videos
  • Contact
  • Hire Me (opens in new tab)
Search form
User login
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
  • Reset your password
User account menu
  • Hire Me (opens in new tab)
  • Drupal Services
  • Blog
Site branding
Alaa Haddad - Drupal Expert
Consultant • Architect • Developer • Themer - Expert Drupal Solutions
Article Title Image - Block 1

SMACSS in Drupal .libraries.yml: Weights, Groups, Load Order

Content Info - Article Info
 
  10:55 PM CDT, Sun September 13, 2026
Share

Breadcrumbs

Breadcrumb

  • Home
  • Drupal Theme
  • SMACSS in Drupal .libraries.yml: Weights, Groups, Load Order

Main page content

The SMACSS category you nest a stylesheet under in .libraries.yml is not documentation — it sets a numeric weight that decides load order, and Drupal adds any weight you also declare on top of it. Most theme developers know the five category names. Far fewer know that the weights are additive, and almost nobody knows that the aggregation group is compared before the weight, which is why a module's "theme" stylesheet still loads before your theme's "base" one.

Get those three facts straight and a whole category of cascade bugs stops happening. Every figure and behaviour below was read out of Drupal 11.4.6 core on disk.

The five categories and their weights

SMACSS is a way of classifying stylesheets by what kind of job they do. Drupal adopted the vocabulary and attached a number to each name, defined as constants in core/includes/common.inc:

Drupal's SMACSS categories, their constants and their default weights
Category keyConstantWeightWhat belongs here
baseCSS_BASE-200Rules that style bare HTML elements: resets, typography defaults
layoutCSS_LAYOUT-100Page-level structure and grids
componentCSS_COMPONENT0Discrete reusable pieces: a card, a button, a pager
stateCSS_STATE100State variations not shipped with the component itself
themeCSS_THEME200Purely visual skin applied over a component

Nesting is not optional. Drupal asserts that every CSS entry in a library sits under one of these keys, and it derives the constant name mechanically by upper-casing the key you wrote. A misspelled category does not fall back to a default — there is no constant to look up.

The part that is not in the tutorials: the weights add

When Drupal parses a library it takes the weight you declared on the file — zero if you declared none — and adds the category constant to it. It does not replace it.

global-styling:
  css:
    layout:
      css/layout.css: {}              # weight becomes -100
      css/layout-wide.css: { weight: 10 }   # weight becomes -90
    theme:
      css/skin.css: { weight: 999 }   # weight becomes 1199

This is genuinely useful once you know it. Ordering two files inside the same category is a small positive or negative number, and the category keeps them in the right band relative to everything else. It is also a trap: a large weight, copied from an example somewhere, can push a file clean out of its category's band and past files it was never meant to overtake.

Load-order problems are the cheapest thing to fix badly and the most expensive to fix twice — Drupal theming covers doing it once.

The part that surprises everyone: group beats weight

Before Drupal compares weights at all, it compares aggregation groups. Module CSS is placed in the default aggregate group; theme CSS — along with single-directory component stylesheets — is placed in the theme aggregate group, which sorts later. The comparison is group first, weight second, and only then does insertion order break remaining ties.

The consequence is worth stating plainly, because it contradicts what the weights alone imply: every stylesheet a theme declares loads after every stylesheet any module declares, whatever category either of them used. A module file nested under theme at weight 200 still loads before your theme's file nested under base at weight -200. The 400-point difference in weight never gets consulted.

So SMACSS categories order assets within your theme. They are not a mechanism for beating a module. If you need to override module CSS, you already win on order by virtue of being a theme, and if you are still losing, the cause is specificity rather than order — which is a different diagnosis with a different fix, covered in the sub-theme CSS diagnostic order.

Structuring a theme's libraries this way

The pattern that holds up on real projects is one global library carrying only what genuinely appears on every page, plus small named libraries attached where they are needed.

global-styling:
  css:
    base:
      css/base/reset.css: {}
      css/base/typography.css: {}
    layout:
      css/layout/page.css: {}
    component:
      css/components/button.css: {}
      css/components/card.css: {}
    theme:
      css/theme/colors.css: {}

article-styling:
  css:
    component:
      css/components/article.css: {}

Declare the global one in your theme's .info.yml under libraries:, and attach the conditional ones where they apply — from a preprocess function via $variables['#attached']['library'][], or directly in a Twig template with {{ attach_library('mytheme/article-styling') }}. The point is not tidiness for its own sake: a page that never renders an article should not download the article stylesheet.

For a worked example of a theme that does this at scale, the Solo theme's library file declares 288 named libraries with per-file weights inside categories, which is what lets it load fonts, menu variants and colour schemes only where they are used. The evaluation checklist for free Drupal themes covers how to judge that kind of structure when you are picking a base.

What SMACSS categorisation does not do

  • It does not fix specificity. Order and specificity are independent. A later file with a weaker selector still loses.
  • It does not reduce the number of requests. That is aggregation, a separate setting under Configuration → Development → Performance.
  • It does not enforce anything about the contents of the file. Nothing stops you putting a colour in base. The categories are a promise you make to your future self.
  • It does not let you order across extensions. As above — that is the group, and you do not control it from a category key.

Common questions

What happens if I misspell a category?

In development, with assertions active, Drupal tells you directly that the category is invalid and points at the documentation. Assertions are normally compiled out in production, and the code path then tries to read a constant that does not exist, so treat a category typo as something to catch before deployment rather than something that degrades gracefully. Test the exact behaviour on your own build if it matters — needs checking for your PHP configuration.

Can I skip categories and just use weights?

No. Drupal asserts that CSS is nested under a category, and the parser iterates the category keys rather than the file list, so an un-nested file is not merely unweighted — it is not read as a stylesheet at all.

Are the weights the same in Drupal 10 and 11?

The constants read from core on disk here are from 11.4.6 and are unchanged from the values Drupal has used since 8.x. If you are targeting Drupal 12, read them in your own copy of core rather than trusting this page.

Does this apply to JavaScript too?

Not in the same way. JS has its own groups and, notably, Drupal throws an exception if a library declares a positive weight on a JS file — the message tells you to declare accurate dependencies instead. Ordering scripts is a dependency problem, not a weight problem.

Getting this right once

The payoff for categorising properly is not aesthetic. It is that six months later, when a rule is not applying, you can reason about why in thirty seconds instead of adding an !important and hoping.

If you are building or inheriting a theme and the library file is already a mess, untangling it is a contained piece of work with a clear finish line. That is Drupal theming; if it comes with a broader front-end rebuild, the Drupal developer side of it covers the preprocess and template work that usually comes with it.

Drupal Theme
Slide 1 of 27
Acquia Purge Varnish - API V2 (Drupal Module)
Slide 2 of 27
Amun - W3CSS Sub-Theme (Drupal Theme)
Slide 3 of 27
Amunet - W3CSS Sub-Theme (Drupal Theme)
Slide 4 of 27
Anhur - W3CSS Sub-Theme (Drupal Theme)
Slide 5 of 27
Cloudflare Purge (Drupal Module)
Slide 6 of 27
Module Matrix (Drupal Module)
Slide 7 of 27
Paragraphs Bundles (Drupal Module)
Slide 8 of 27
Paragraphs Bundles Import (Drupal Module)
Slide 9 of 27
Reference Blocked Users (Drupal Module)
Slide 10 of 27
Selectify (Drupal Module)
Slide 11 of 27
Solo (Drupal Theme)
Slide 12 of 27
Solo Copy Blocks (Drupal Module)
Slide 13 of 27
Solo Utilities (Drupal Module)
Slide 14 of 27
Utilikit (Drupal Module)
Slide 15 of 27
Views 3D Carousel (Drupal Module)
Slide 16 of 27
Views 3D FlipBox (Drupal Module)
Slide 17 of 27
Views Accordion (Drupal Module)
Slide 18 of 27
Views Carousel (Drupal Module)
Slide 19 of 27
Views Hero (Drupal Module)
Slide 20 of 27
Views Lightbox (Drupal Module)
Slide 21 of 27
Views Parallax (Drupal Module)
Slide 22 of 27
Views Reveal (Drupal Module)
Slide 23 of 27
Views Slideshow (Drupal Module)
Slide 24 of 27
Views Tabs (Drupal Module)
Slide 25 of 27
VVJ Core (Drupal Module)
Slide 26 of 27
W3CSS Paragraphs (Drupal Module)
Slide 27 of 27
W3CSS Theme (Drupal Theme)
1 of 27

Our mission is to make Drupal more accessible and user-friendly, empowering businesses of all sizes, especially small enterprises with powerful tools that streamline content customization and enhance digital experiences.

Need help with your Drupal project? Hire Me through Flash Web Center, LLC.

Search

The Drupal 11 Module and Theme Stack, With Versions Checked

ARIA Live Regions in Drupal 11: What Core Does, What You Add

Drupal Architect: The Decisions Expensive to Reverse

Drupal Services: Development, Theming, Upgrades | Austin TX

Paragraphs Bundles

Drupal Module - Paragraphs Bundles

Drupal Theme - Solo

Drupal Theme - Solo

Drupal Work List - Drupal Work

Reference Blocked Users (Drupal Module)

Solo Utilities (Drupal Module)

Views Hero (Drupal Module)

Solo (Drupal Theme)

Paragraphs Bundles Import (Drupal Module)

Drupal Theme - W3CSS Theme

Drupal Theme - W3CSS Theme

Drupal Module - W3CSS Paragraphs

Drupal Module - W3CSS Paragraphs

Inspiration

Inspiration is the fuel that powers our creative engine, often coming from our surroundings, experiences, or the works of others. It's that magical moment when something clicks inside your brain, and you suddenly see a path forward that you hadn't noticed before. Inspiration can strike at any time, providing the motivation and energy needed to explore new possibilities and bring your ideas to life.

Unique Ideas

Unique Ideas

Unique ideas are the seeds of innovation, representing original thoughts or concepts that stand out from the usual. They're the sparks that ignite the process of creating something new and different, often leading to unexpected and groundbreaking solutions or products. Whether in art, science, business, or technology, unique ideas challenge the status quo and pave the way for progress.

Brainstorming

Brainstorming

Brainstorming is a creative group activity designed to generate a large number of ideas or solutions to a problem. It's a free-flowing and open-ended discussion where every suggestion is welcomed and considered, no matter how outlandish it may seem. Brainstorming encourages thinking outside the box, fostering an environment where creativity and collaboration lead to innovative solutions.

Planning

Planning

Planning is the blueprint for turning your ideas into reality. It involves setting goals, outlining steps, and organizing resources in a way that makes achieving your objectives possible. Good planning considers potential challenges and opportunities, making it easier to navigate the journey from concept to completion. It's about preparing the groundwork so that your projects can grow and flourish.

Drupal Developer

A Drupal Developer stands as the technical powerhouse behind dynamic websites, wielding expertise in PHP, custom module development, and Drupal's sophisticated API ecosystem. This role transforms business requirements into functional, secure, and scalable web solutions that power everything from small business sites to enterprise platforms serving millions of users. A Drupal Developer's expertise spans the entire development lifecycle—from architecting custom modules and integrating third-party services to optimizing performance and ensuring security compliance. Discover the complete guide to Drupal Developer skills, career paths, and hiring strategies.

Drupal Themer

A Drupal Themer serves as the artistic craftsperson who transforms wireframes and design mockups into pixel-perfect, accessible, and responsive user experiences using Twig templates, CSS, and JavaScript. This specialized role bridges the gap between design vision and technical implementation, ensuring every website not only looks exceptional but performs flawlessly across all devices and meets WCAG accessibility standards. A Drupal Themer's work encompasses the entire front-end ecosystem—from creating custom theme architectures and optimizing Core Web Vitals to implementing complex responsive designs and ensuring seamless integration with Drupal's rendering system. Explore the comprehensive guide to Drupal Themer expertise, theming best practices, and career advancement.

Drupal Architect

A Drupal Architect emerges as the strategic visionary of web construction, armed with encyclopedic knowledge of enterprise architecture patterns, infrastructure design, and Drupal's extensive technological ecosystem. This senior role operates at the highest technical level, making critical decisions that determine whether complex implementations scale successfully or collapse under real-world demands. A Drupal Architect's responsibilities begin long before development starts—during strategic planning phases where the foundation for secure, performant, and maintainable systems is established through careful evaluation of technology stacks, integration strategies, and scalability requirements. Learn about Drupal Architect skills, enterprise architecture strategies, and career progression to principal roles.

Footer menu

  • Contact
  • Professional Resume
  • Resume Summary
  • Technical Skills
  • Privacy Policy
  • Terms & Conditions
  • Search
  • Login
  • Sitemap

Copyright © 2026 Flash Web Center, LLC - All rights reserved

Developed & Designed by Alaa Haddad