CSS

The Power of CSS Modules

In modern web development, managing CSS at scale can be a nightmare. Global naming collisions, dead code, and dependency management are constant struggles. While utility-first frameworks like Tailwind CSS are popular, CSS Modules offer a compelling alternative, especially for projects requiring complex, creating animations and a unique design system.

What are CSS Modules?

CSS Modules are CSS files in which all class names and animation names are scoped locally by default. This means you can use generic names like .button or .title in different components without worrying about conflicts.

Example: A Neon Button

Let's create a reusable Button component with a glow effect.

Button.module.css

.button { background: #000; color: #0ff; border: 1px solid #0ff; padding: 10px 20px; border-radius: 5px; cursor: pointer; transition: all 0.3s ease; box-shadow: 0 0 5px #0ff; } .button:hover { background: #0ff; color: #000; box-shadow: 0 0 20px #0ff; }

Button.tsx

import styles from './Button.module.css'; export default function Button({ text }: { text: string }) { return <button className={styles.button}>{text}</button>; }

Why I Choose CSS Modules

  1. Scoped Styles: No more !important or specific selectors to override global styles.
  2. Clean JSX: Your markup isn't cluttered with dozens of utility classes. It stays semantic.
  3. Power of CSS: You can use the full power of CSS, including complex animations (@keyframes), pseudo-elements (::before, ::after), and media queries, exactly how you learned them.

For a portfolio site like this, where visual flair and uniqueness are key, CSS Modules give me the control I need to craft exact pixel-perfect designs.