Course contentsShow
← Web Development
Lesson 1349 of 2,98224. CSS Architecture and MaintainabilityFree lesson

Naming Hash Configuration

Customizing the generated class name format for development debugging and production optimization in CSS Modules.

Naming Hash Configuration

You'll learn how to customize the auto-generated class names in CSS Modules for better debugging and optimized production builds.

Why Customize the Hash?

By default, CSS Modules generates cryptic class names like _23_aKvs-b8bW2Vg3fwHozO. While this guarantees uniqueness, it makes debugging in development frustrating—you can't tell which component a style belongs to just by looking at the browser inspector.

Think of it like package tracking numbers: A random string like "XK29JF7" works perfectly for the system, but "Amazon-Order-Books-Dec2024" would be much easier for humans to understand.

Configuring the Hash Format

CSS Modules build tools (like webpack's css-loader) let you customize the generated class name pattern using placeholders:

  • [name] - The CSS file name
  • [local] - The original class name you wrote
  • [hash:base64:5] - A unique hash (you control the length)

Development configuration example:

localIdentName: '[name]__[local]___[hash:base64:5]'

This might generate: Button__primary___2x9kL—instantly readable! You see the file name, the class you wrote, and a short hash for uniqueness.

Production configuration:

localIdentName: '[hash:base64:8]'

This generates minimal hashes like a3f9k2m1, keeping your CSS file size small.

Development vs Production Strategy

Use descriptive patterns during development for easier debugging, then switch to short hashes in production for performance. Most build tools let you configure this per-environment, giving you the best of both worlds.

Key Takeaway: Customizing CSS Modules' hash configuration lets you balance human-readable class names during development with optimized, compact hashes in production—improving both developer experience and end-user performance.