Loading...

Pascal Case vs Kebab Case: A Developer's Guide to Naming Conventions in 2025

Master modern naming conventions in programming. Learn when to use Pascal Case vs Kebab Case, with practical examples from React, TypeScript, and modern frameworks.

Pascal Case vs Kebab Case: A Developer's Guide to Naming Conventions in 2025

Pascal Case vs Kebab Case: Modern Naming Conventions

This guide reflects the latest naming conventions used in modern frameworks like React, Next.js 15, and TypeScript 5.4.

Choosing the right naming convention is crucial for code readability and maintainability. Let's explore when and how to use Pascal Case and Kebab Case effectively in modern web development.

Pascal Case (PascalCase)

Pascal Case capitalizes the first letter of each word with no separators.

When to Use Pascal Case

  1. React Components

tsx

// Good practice: Use PascalCase for React components
export const UserProfile: React.FC<UserProfileProps> = ({ user }) => {
  return <div>Profile for {user.name}</div>;
};
 
// Bad: Don't use kebab-case for components
export const user-profile = ({ user }) => {
  return <div>Profile for {user.name}</div>;
};
  1. TypeScript Types and Interfaces

typescript

//  Good: Types and interfaces in PascalCase
interface UserData {
  id: string;
  firstName: string;
  lastName: string;
}
 
type ApiResponse<T> = {
  data: T;
  status: number;
};
 
// Bad: Don't use other cases for types
interface user_data {
  id: string;
}
  1. Class Definitions

typescript

// Good: Classes in PascalCase
class UserRepository {
  private users: User[] = [];
 
  async findById(id: string): Promise<User | null> {
    return this.users.find(user => user.id === id) ?? null;
  }
}
 
// Bad: Don't use kebab-case for classes
class user-repository {
  // This won't even work in JavaScript/TypeScript
}

Kebab Case (kebab-case)

Kebab Case uses lowercase letters with hyphens between words.

When to Use Kebab Case

  1. File Names

bash

# Good: File names in kebab-case
src/
  components/
    user-profile.tsx
    login-form.tsx
    nav-bar.tsx
 
# Bad: Don't mix cases in file names
src/
  components/
    UserProfile.tsx
    loginForm.tsx
    Nav_Bar.tsx
  1. URL Paths

typescript

// Good: URL paths in kebab-case
const routes = {
  userProfile: '/user-profile',
  settingsPage: '/settings/account-preferences',
  blogPost: '/blog/how-to-code-well'
};
 
// Bad: Don't use PascalCase or camelCase in URLs
const routes = {
  userProfile: '/UserProfile',  // Avoid
  settingsPage: '/settings/accountPreferences'  // Avoid
};
  1. CSS Classes

tsx

// Good: CSS classes in kebab-case
const UserCard = () => (
  <div className="user-card dark-theme">
    <div className="user-avatar-wrapper">
      <img className="user-avatar" src="..." alt="User avatar" />
    </div>
  </div>
);
 
// Bad: Don't use camelCase or PascalCase in CSS classes
const UserCard = () => (
  <div className="UserCard darkTheme">  // Avoid
    <div className="userAvatarWrapper">  // Avoid
      <img className="userAvatar" src="..." alt="User avatar" />
    </div>
  </div>
);

Modern Framework Conventions

Next.js 15 File Convention

bash

#  Good: Next.js file naming
app/
  layout.tsx                # Reserved names in lowercase
  page.tsx                 # Reserved names in lowercase
  blog/
    [slug]/
      page.tsx
    categories/
      [category]/
        page.tsx
  components/
    user-profile.tsx       # Component files in kebab-case
    UserProfile.tsx        # Alternative: Component files in PascalCase

React Component Organization

typescript

// Good: Component and file organization
// UserProfile.tsx or user-profile.tsx
import { type FC } from 'react';
 
interface UserProfileProps {
  userId: string;
  displayName: string;
}
 
export const UserProfile: FC<UserProfileProps> = ({
  userId,
  displayName
}) => {
  return (
    <div className="user-profile">
      {displayName}
    </div>
  );
};

CSS Modules

typescript

// Good: CSS Modules naming
// user-profile.module.css
.userProfile {
  display: flex;
  gap: 1rem;
}
 
.avatarWrapper {
  border-radius: 50%;
}
 
// user-profile.tsx
import styles from './user-profile.module.css';
 
export const UserProfile = () => (
  <div className={styles.userProfile}>
    <div className={styles.avatarWrapper}>
      {/* Content */}
    </div>
  </div>
);

Special Cases and Exceptions

Constants

typescript

//  Good: Constants in SCREAMING_SNAKE_CASE
const API_BASE_URL = "https://api.example.com";
const MAX_RETRY_ATTEMPTS = 3;
 
// Environment variables
const env = {
  NEXT_PUBLIC_API_KEY: process.env.NEXT_PUBLIC_API_KEY,
  DATABASE_URL: process.env.DATABASE_URL,
};

Event Handlers

typescript

// Good: Event handlers in camelCase with 'handle' prefix
const UserForm = () => {
  const handleSubmit = (event: React.FormEvent) => {
    event.preventDefault();
  };
 
  const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    // Handle input change
  };
 
  return (
    <form onSubmit={handleSubmit}>
      <input onChange={handleInputChange} />
    </form>
  );
};

Tools for Enforcing Naming Conventions

ESLint Configuration

javascript

// .eslintrc.js
module.exports = {
  extends: ["next/core-web-vitals", "plugin:@typescript-eslint/recommended"],
  rules: {
    // Enforce PascalCase for React components
    "@typescript-eslint/naming-convention": [
      "error",
      {
        selector: "variable",
        format: ["PascalCase"],
        filter: {
          regex: "^.*Component$",
          match: true,
        },
      },
    ],
    // Enforce camelCase for functions
    camelcase: ["error", { properties: "never" }],
  },
};

VS Code Settings

json

{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "files.associations": {
    "*.css": "css",
    "*.module.css": "css"
  },
  "typescript.preferences.importModuleSpecifier": "non-relative"
}

Best Practices Summary

  1. Component Names

    • Use PascalCase for React components
    • Match component name with file name
    • Be descriptive but concise
  2. File Names

    • Use kebab-case for most files
    • Exception: Component files can use PascalCase
    • Be consistent within your project
  3. CSS Classes

    • Use kebab-case for class names
    • Consider BEM methodology for complex components
    • Keep names semantic and meaningful
  4. URLs and Routes

    • Always use kebab-case
    • Avoid special characters
    • Make them RESTful and descriptive

Common Mistakes to Avoid

  1. Inconsistent Casing

typescript

// Bad: Mixed casing styles
const UserProfile = () => {
  return <div className="UserCard user_avatar"></div>;
};
 
// Good: Consistent casing
const UserProfile = () => {
  return <div className="user-card user-avatar"></div>;
};
  1. Unclear Abbreviations

typescript

// Bad: Unclear abbreviations
const UsrPrfl = () => {
  return <div>Profile</div>;
};
 
//  Good: Clear, descriptive names
const UserProfile = () => {
  return <div>Profile</div>;
};
  1. Semantic Mismatches

typescript

//  Bad: Name doesn't match functionality
const Button = () => {
  return <div onClick={handleClick}>Click me</div>;
};
 
//  Good: Name matches functionality and semantics
const Button = () => {
  return <button onClick={handleClick}>Click me</button>;
};

React Server Components

typescript

//  Good: Server component naming
 
export const UserProfileServer = async ({ id }: { id: string }) => {
  const user = await fetchUser(id);
  return <UserProfileClient user={user} />;
};

Tools and Resources