Developer Guide

CamelCase vs Snake_Case vs Kebab-Case: A Developer's Guide

Master the art of naming variables, functions, and files across different programming languages and frameworks.

15 min read Coding Standards

Why Naming Conventions Matter

In programming, naming conventions are more than style preferences—they're fundamental to code readability, maintainability, and collaboration. Consistent naming helps developers quickly understand code structure, reduces cognitive load, and prevents bugs caused by naming conflicts.

Different programming languages and ecosystems have evolved distinct naming conventions based on their syntax requirements, historical context, and community standards. While JavaScript developers use camelCase, Python programmers prefer snake_case, and web developers employ kebab-case for URLs and CSS.

This guide breaks down the four primary naming conventions, explains when and where to use each, and provides practical examples from real-world codebases.

Quick Reference

camelCase → JavaScript, Java variables/functions
PascalCase → Classes, React Components
snake_case → Python, Ruby, SQL databases
kebab-case → URLs, CSS classes, HTML attributes

camelCase

The JavaScript standard for variables and functions

What is camelCase?

In camelCase (also called lower camel case), the first word starts with a lowercase letter, and each subsequent word begins with an uppercase letter. No spaces, hyphens, or underscores separate the words. The name comes from the "humped" appearance of capital letters in the middle of identifiers.

Pattern:

firstWordSecondWordThirdWord

Where to Use camelCase

📜 JavaScript / TypeScript

  • ✓ Variables and constants
  • ✓ Function names
  • ✓ Object properties
  • ✓ Method names

Java

  • ✓ Variable names
  • ✓ Method names
  • ✓ Parameter names
  • ✓ Local variables

🍎 Swift / Objective-C

  • ✓ Properties
  • ✓ Methods
  • ✓ Function parameters
  • ✓ Local variables

⚙️ C# / .NET

  • ✓ Private fields (with prefix _)
  • ✓ Local variables
  • ✓ Method parameters
  • ✓ Lambda expressions

Code Examples

JavaScript Variables & Functions:

// Variable declarations
let userName = 'John Doe';
const maxLoginAttempts = 5;
let isUserLoggedIn = false;

// Function declarations
function calculateTotalPrice(items, taxRate) {
  return items.reduce((total, item) => total + item.price, 0) * (1 + taxRate);
}

// Object methods
const user = {
  firstName: 'Jane',
  lastName: 'Smith',
  getFullName() {
    return `${this.firstName} ${this.lastName}`;
  }
};

Java Methods & Variables:

public class UserService {
    private String emailAddress;
    private int accountBalance;
    
    public void sendWelcomeEmail(String recipientName) {
        String messageBody = "Welcome " + recipientName;
        // Email sending logic
    }
    
    public int calculateMonthlyPayment(int loanAmount, double interestRate) {
        return loanAmount * interestRate / 12;
    }
}

Best Practices

  • • Use descriptive names: getUserData() not get()
  • • Boolean variables should start with is, has, or can
  • • Keep acronyms consistent: loadHTMLFile() or loadHtmlFile(), but not mixed

snake_case

The Python and database standard

What is snake_case?

Snake_case uses lowercase letters with underscores (_) separating words. It's called "snake case" because the underscores create a visual pattern resembling a snake slithering along the ground. This convention prioritizes readability and is particularly popular in languages that emphasize explicit, readable code.

Pattern:

first_word_second_word_third_word

Where to Use snake_case

🐍 Python

  • ✓ Variables and constants
  • ✓ Function names
  • ✓ Method names
  • ✓ Module names (files)

💎 Ruby

  • ✓ Variables
  • ✓ Method names
  • ✓ Symbol names
  • ✓ File names

🗄️ SQL / Databases

  • ✓ Table names
  • ✓ Column names
  • ✓ Index names
  • ✓ View names

🔧 C / C++

  • ✓ Variable names
  • ✓ Function names
  • ✓ Macro names (UPPER_SNAKE)
  • ✓ Struct members

Code Examples

Python Functions & Variables (PEP 8 Standard):

# Variable declarations
user_name = 'Alice Johnson'
max_retry_attempts = 3
is_authenticated = True

# Function definitions
def calculate_discount_price(original_price, discount_percentage):
    discount_amount = original_price * (discount_percentage / 100)
    return original_price - discount_amount

# Class with methods (note: class names use PascalCase)
class UserAccount:
    def __init__(self, email_address, account_type):
        self.email_address = email_address
        self.account_type = account_type
    
    def send_verification_email(self):
        verification_code = self.generate_random_code()
        # Send email logic

SQL Database Schema:

-- Table creation with snake_case columns
CREATE TABLE user_profiles (
    user_id INT PRIMARY KEY,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    email_address VARCHAR(100),
    date_of_birth DATE,
    account_created_at TIMESTAMP,
    is_email_verified BOOLEAN
);

-- Query example
SELECT 
    u.user_id,
    u.first_name,
    u.last_name,
    o.order_total
FROM user_profiles u
JOIN order_history o ON u.user_id = o.user_id
WHERE o.order_status = 'completed';

Ruby Methods & Variables:

# Variable assignments
user_email = 'user@example.com'
total_items = 42
is_premium_member = true

# Method definition
def calculate_shipping_cost(weight_in_kg, destination_country)
  base_rate = 5.00
  per_kg_rate = 2.50
  
  base_rate + (weight_in_kg * per_kg_rate)
end

# Class definition
class ShoppingCart
  attr_accessor :cart_items, :discount_code
  
  def add_item_to_cart(item)
    @cart_items << item
  end
end

Best Practices

  • • Use descriptive names: get_user_by_email() not get()
  • • Constants use UPPER_SNAKE_CASE: MAX_CONNECTION_TIMEOUT
  • • Avoid abbreviations unless widely understood: http_response is OK, resp is not

kebab-case

The web standard for URLs and CSS

What is kebab-case?

Kebab-case (also called dash-case, lisp-case, or spinal-case) uses lowercase letters with hyphens (-) separating words. The name "kebab case" comes from the visual similarity to food on a skewer. It's the de facto standard for web URLs because hyphens are readable and SEO-friendly, unlike underscores which can be problematic in URLs.

Pattern:

first-word-second-word-third-word

Where to Use kebab-case

🌐 URLs & Slugs

  • ✓ Page URLs
  • ✓ Blog post slugs
  • ✓ API endpoints
  • ✓ Route parameters

🎨 CSS / SCSS

  • ✓ Class names (BEM methodology)
  • ✓ ID selectors
  • ✓ Custom property names
  • ✓ Animation names

📄 HTML

  • ✓ Custom data attributes
  • ✓ ARIA attributes
  • ✓ Custom element names
  • ✓ File names

📦 Package Names

  • ✓ npm packages
  • ✓ Git repository names
  • ✓ Docker image names
  • ✓ Project folders

Code Examples

URL Slugs & Route Paths:

// SEO-friendly URL structures
https://example.com/blog/how-to-learn-javascript
https://example.com/products/wireless-bluetooth-headphones
https://example.com/user-profile/settings/privacy-preferences

// API endpoint naming
GET /api/v1/user-accounts
POST /api/v1/create-order
PUT /api/v1/update-shipping-address
DELETE /api/v1/remove-cart-item

// Next.js / React Router file-based routing
/pages/about-us.tsx
/pages/contact-form.tsx
/pages/blog/[post-slug].tsx

CSS Class Names (BEM Methodology):

/* Component classes */
.navigation-bar {
  display: flex;
  background-color: #ffffff;
}

.navigation-bar__menu-item {
  padding: 10px 20px;
}

.navigation-bar__menu-item--active {
  font-weight: bold;
  color: #0066cc;
}

/* Utility classes */
.text-center { text-align: center; }
.margin-top-large { margin-top: 2rem; }
.background-primary-color { background: var(--primary-color); }

/* Animation names */
@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

HTML Data Attributes & Custom Elements:

<!-- Custom data attributes -->
<div 
  class="product-card"
  data-product-id="12345"
  data-category-name="electronics"
  data-is-in-stock="true">
  <h3>Wireless Headphones</h3>
</div>

<!-- ARIA attributes for accessibility -->
<button
  aria-label="Close navigation menu"
  aria-expanded="true"
  aria-controls="mobile-menu">
  Close
</button>

<!-- Custom Web Components -->
<user-profile-card user-id="789"></user-profile-card>
<shopping-cart-widget></shopping-cart-widget>

NPM Packages & File Names:

// package.json - npm package names
{
  "name": "react-router-dom",
  "dependencies": {
    "lodash-es": "^4.17.21",
    "date-fns": "^2.29.0",
    "styled-components": "^5.3.0"
  }
}

// Project file structure
my-awesome-project/
├── user-authentication.js
├── database-connection.js
├── email-service-config.js
└── payment-gateway-integration.js

Important: URLs vs Underscores

Google treats hyphens as word separators but underscores as word joiners. Use best-seo-practices not best_seo_practices for URLs to improve search engine optimization.

Best Practices

  • • Keep URLs short and descriptive: /blog/react-hooks-guide
  • • Use BEM for CSS: .block__element--modifier
  • • Avoid redundancy: nav-menu not navigation-menu-nav
💡

Pro Tip: When to Use PascalCase

UpperCamelCase for classes and components

What is PascalCase?

PascalCase (also called UpperCamelCase) is identical to camelCase except the first letter is also capitalized. It's the universal standard for class names and constructors across nearly all programming languages.

FirstWordSecondWordThirdWord

⚛️ React / Vue Components

// React component
function UserProfileCard() {
  return <div>...</div>;
}

// Vue component
export default {
  name: 'ShoppingCartWidget'
}

🏗️ Classes & Constructors

// JavaScript class
class DatabaseConnection {
  constructor(config) {
    // ...
  }
}

// Python class
class UserAccount:
  pass

Common Use Cases:

  • UserService - Class names
  • NavBar - React components
  • PaymentGateway - Interfaces
  • DatabaseAdapter - Abstract classes
  • HttpClient - Constructor functions
  • AuthProvider - Type definitions

Quick Comparison Table

Convention Example Primary Use Languages
camelCase myVariableName Variables, Functions JavaScript, Java, Swift
PascalCase MyClassName Classes, Components All OOP languages
snake_case my_variable_name Variables, Functions, DB Columns Python, Ruby, SQL
kebab-case my-variable-name URLs, CSS Classes, File Names HTML, CSS, Web URLs
SCREAMING_SNAKE MAX_CONNECTIONS Constants, Environment Variables All languages

Convert Text to Any Naming Convention

Use our text formatter to instantly convert between camelCase, snake_case, kebab-case, and PascalCase. Perfect for developers working across multiple languages.