Snake Case: snake_case vs camelCase vs kebab-case
November 11, 2026 · 10 min read
Snake Case Explained: snake_case vs camelCase vs kebab-case
Snake case writes a multi-word name in lowercase letters with an underscore between each word, as in user_profile_data. Python, Ruby and Rust use it for functions and variables, many SQL schemas use it for columns, and its all-caps form names constants and environment variables. This page shows when to pick it over camelCase or kebab-case, and the evidence behind each choice.
Here's where each style usually belongs:
| Context | Usual style | Example |
|---|---|---|
| Python, Ruby and Rust functions and variables | snake_case | send_invoice |
| Constants and environment variables | SCREAMING_SNAKE_CASE | MAX_RETRIES |
| JavaScript, Java and C# variables | camelCase | sendInvoice |
| Classes and types in most languages | PascalCase | InvoiceSender |
| SQL tables and columns | snake_case | created_at |
| URL slugs, CSS classes, HTML attributes | kebab-case | send-invoice |
| Names inside Markdown prose | Any, wrapped in backticks | `send_invoice` |
What Is Snake Case and Why Is It Called That?
The style joins words with underscores and keeps every letter lowercase. Spaces aren't allowed in identifiers, so the underscore stands in for one:
order_total = 0
first_name = "Ada"
def send_welcome_email(user_id): ...
Each line is a valid Python name. The underscores keep the word boundaries visible without breaking the name in two.
The name comes from the shape. A row of lowercase words lying flat along their underscores looks a little like a snake. Wikipedia traces the earliest known Usenet use of the term to Gavin Kistner, in a 2004 post to the Ruby newsgroup comp.lang.ruby. The style is far older than its nickname, though. C code used underscores as word separators decades earlier, and Python's PEP 8 style guide simply calls it lower_case_with_underscores.
SCREAMING_SNAKE_CASE for Constants and Environment Variables
Switch every letter to uppercase and keep the underscores, and you get SCREAMING_SNAKE_CASE, sometimes called upper or capital snake case. It signals a value that shouldn't change.
PEP 8 asks for module-level constants written in capitals with underscores, and gives MAX_OVERFLOW as an example. The Rust API guidelines use the same form for constants and statics. C macros, Java constants and JavaScript values such as Number.MAX_SAFE_INTEGER follow it too.
Environment variables are the other big home for screaming snake case. Here's a typical pair of exports.
export DATABASE_URL=postgres://localhost/shop
export MAX_UPLOAD_MB=25
POSIX.1-2024 says the variables its shell utilities use contain only uppercase letters, digits and underscores, and never start with a digit. It reserves names containing lowercase letters for applications. That's why config keys in .env files and CI settings nearly always shout.
Snake Case vs Camel Case: Side by Side
Every camel case vs snake case argument starts from one difference: how each style marks a word break. snake_case inserts an underscore. camelCase drops the separator and capitalises the first letter of each word after the first.
| snake_case | camelCase | |
|---|---|---|
| Example | order_total | orderTotal |
| Word break | Underscore | Capital letter |
| Capitals | None (all caps for constants) | Every word except the first |
| Default for variables in | Python, Ruby, Rust | JavaScript, Java, C#, Go |
| Acronyms | parse_http_response, no capitals to decide | parseHTTPResponse or parseHttpResponse |
| Length | One extra character per break | Shortest form |
PascalCase is camelCase with the first letter capitalised too, as in OrderTotal, and most languages reserve it for class and type names. Our guide to camelCase vs PascalCase covers which form each language uses and the acronym rules.
Neither style wins on its own merits. Each language picked one early, and its standard library, linters and tutorials all reinforced the choice. If you write Python with camelCase variables, the code runs fine, but every library call you make still uses snake_case, so your file ends up mixing both.
Is camelCase or snake_case Easier to Read? What the Studies Found
Look up camelCase vs snake case readability and the same two studies keep coming up. They point in slightly different directions.
Binkley et al., 2009 ("To CamelCase or Under_score", ICPC 2009) tested 135 programmers and non-programmers. The authors report that camel case led to higher accuracy for all subjects regardless of training. People trained in camel case also recognised camel case identifiers faster than underscored ones, though across all subjects camel case names took longer to find.
Sharif and Maletic, 2010 ("An Eye Tracking Study on camelCase and under_score Identifier Styles", ICPC 2010) repeated the idea with eye-tracking equipment and 15 programmers. Almost every answer was correct, so accuracy couldn't separate the styles, but participants recognised underscored identifiers more quickly. They had been trained mainly in the underscore style, which may have favoured it.
Put together, the evidence says training shapes the result. The 2010 authors saw the gap narrow with experience without disappearing, though that trend wasn't statistically significant. You read fastest in the convention you use every day. So the practical rule is to follow your ecosystem's style guide and let a linter enforce it.
We prefer snake_case in Python and SQL, camelCase in JavaScript, and never a mix of the two in one file. Switching style between files is fine. Switching inside one file is what slows readers down.
Kebab Case vs Snake Case in URLs, CSS and File Names
Kebab-case joins lowercase words with hyphens: order-total. It looks like snake_case with a different separator, but it can't name a variable in most languages. The hyphen is the minus operator, so Python reads order-total = 5 as an attempt to assign to order - total and raises a SyntaxError.
That limits kebab-case to places where names are plain strings:
- URLs. Google's URL structure guidance recommends hyphens over underscores to separate words, because hyphens clearly mark a word boundary. This page's slug,
snake-case, follows that advice. - CSS and HTML. Properties such as
background-color, custom properties like--brand-color, class names anddata-user-idattributes are all hyphenated. - Many file names. Web assets and Markdown files often use hyphens, as in
getting-started.md.
Python modules are the exception for files. You import a module by its file name, and import my-module is a syntax error, so PEP 8 recommends short lowercase module names and allows underscores where they help readability.
Should You Use Camel Case or Snake Case in Python?
Python wants underscored lowercase names for almost everything. PEP 8 sets these naming rules:
- Functions, methods, variables and modules: lowercase words joined by underscores.
- Classes: CapWords, the PEP's name for PascalCase.
- Module-level constants: capitals with underscores.
MAX_RETRIES = 3
class InvoiceExporter:
def export_to_csv(self, invoice_id):
row_count = 0
return row_count
Here InvoiceExporter is a class, export_to_csv is a method, invoice_id and row_count are variables, and MAX_RETRIES is a constant. Two linters check these rules for you. Pylint reports bad names as invalid-name (C0103), and Ruff's pep8-naming rules include N801 for class names, N802 for function names and N806 for variables inside functions.
The one place camelCase shows up in Python is older code that mirrors another API, such as the logging module's getLogger. PEP 8 accepts mixedCase where it's already the prevailing style, but new code shouldn't copy it.
Snake Case in SQL Columns, JSON Keys and Config Files
Databases favour underscores too. PostgreSQL folds unquoted identifiers to lowercase, so an unquoted CreatedAt column is stored as createdat, and keeping the capitals means quoting the name in every query. Names like created_at and user_id survive that folding and stay readable.
JSON keys are split. Many APIs built for JavaScript clients use camelCase keys like createdAt, while GitHub's REST API returns snake_case keys such as html_url and created_at. Pick the convention your consumers expect and keep it the same across every endpoint. When one side differs, convert at the boundary in one serializer instead of renaming in scattered places.
YAML front matter keys follow whatever the site generator documents, so check its docs before guessing. Our front matter guide shows typical keys.
Why snake_case Doesn't Turn Italic in Markdown
Markdown uses underscores for emphasis, so you might expect user_profile_data to italicise its middle word. It doesn't. The CommonMark spec forbids intraword emphasis with underscores: an underscore with letters or digits on both sides can't open or close emphasis. GitHub Flavored Markdown follows the same rule.
The trap is a name that starts and ends with underscores. Python's dunder methods are the classic case:
Python calls __init__ when it builds an object.
Python calls `__init__` when it builds an object.
The first line renders init in bold with the underscores gone. The second shows the name exactly, in code formatting. Backticks are the fix for any identifier, and a backslash before each underscore also works. Our guide to Markdown escape characters covers the backslash rules.
Edit the demo below. The snake_case names and table columns stay literal, while the dunder name and the wrapped words turn bold or italic.
For docs with lots of code names, our Markdown style guide recommends asterisks for emphasis, so underscores only ever appear inside names.
Converting Between snake_case, camelCase and kebab-case
To convert a list of names, paste them into our case converter and pick snake_case, camelCase, kebab-case or CONSTANT_CASE (the tool's name for SCREAMING_SNAKE_CASE). It runs in your browser and converts the text you paste, one line at a time. Our letter case converter guide covers the prose styles too, such as Title Case and sentence case.
It doesn't rename identifiers inside your code files. For a real rename across a project, use your IDE's rename refactoring, which updates every reference to the symbol rather than every matching string. The converter splits words on case boundaries, so userID becomes user_id and parseHTTPResponse becomes parse_http_response. Going back loses acronyms, though: parse_http_response comes out as parseHttpResponse, so restore any capitals your style guide keeps.
Snake case is the right default for Python, Ruby and Rust names, SQL columns, and, in capitals, for constants and environment variables. Use camelCase where the language expects it, kebab-case for URLs and CSS, and wrap code names in backticks when you write about them in Markdown. Convert a batch of names with the case converter, then check how they render in the editor before you commit your docs.