What Is snake_case in Programming? Rules and Examples | TitleCasePro
snake_case separates words with underscores and uses all lowercase. It is the standard naming convention in Python, Ruby, and SQL database schemas.
snake_case is a naming convention where words in an identifier are separated by underscores (_) and all letters are lowercase. The name comes from the visual resemblance to a snake lying flat — the underscores form a long, low shape between words.
Examples:
first_namebackground_colorget_user_by_idis_authenticatedcreated_at
Key rule: All letters are lowercase. Words are separated by underscores. No spaces, no hyphens, no capital letters — just
words_like_this.
Where snake_case Is Used
Python (official standard — PEP 8)
def get_user_profile(user_id):
first_name = db.query(user_id).first_name
return first_name
Python’s official style guide, PEP 8, mandates snake_case for variables, functions, methods, and module names.
Ruby
def calculate_total_price(items)
items.sum { |item| item.unit_price }
end
Database columns (SQL)
Most databases (PostgreSQL, MySQL, SQLite) use snake_case for table and column names because SQL is case-insensitive and underscores are cleaner than hyphens in SQL syntax:
SELECT first_name, last_name, created_at FROM user_profiles;
Rust
The Rust compiler actively enforces snake_case for variables and functions and emits a warning if you use any other convention.
Environment variables (CONSTANT_CASE)
When snake_case is written in all uppercase, it becomes CONSTANT_CASE (also called SCREAMING_SNAKE_CASE), which is the convention for constants and environment variables in most languages.
MAX_CONNECTIONS = 100
DATABASE_URL = os.environ["DATABASE_URL"]
snake_case vs. camelCase
These are the two most common naming conventions in programming — and the most common source of cross-language confusion.
| Convention | Example | Primary use |
|---|---|---|
snake_case | first_name | Python, Ruby, databases, Rust |
camelCase | firstName | JavaScript, TypeScript, Java, Swift |
PascalCase | FirstName | Classes, types, React components |
CONSTANT_CASE | FIRST_NAME | Constants, env variables |
kebab-case | first-name | URLs, CSS classes, HTML attributes |
⚠️ The most common mismatch: A Python API returns
{ "first_name": "Alice" }(snake_case). A JavaScript frontend expects{ firstName: "Alice" }(camelCase). Always check which convention your API uses and configure your serialization library to convert automatically.
Rules for Writing snake_case
- Lowercase all letters —
user_profile, notUser_ProfileorUSER_PROFILE. - Separate words with underscores —
get_user_by_id, notgetuserbyid. - No spaces or hyphens — only underscores as word separators.
- Abbreviations as single lowercase words —
html_parser,api_key,user_id(notHTML_parser,API_key). - Leading underscores — In Python,
_private_methodsignals internal/private use. In most other languages, avoid leading underscores unless the language has a specific convention for it.
CONSTANT_CASE (SCREAMING_SNAKE_CASE)
When you need to signal that a value is a constant — something that should never change at runtime — write it in all uppercase snake_case:
const MAX_RETRIES = 3;
const API_BASE_URL = process.env.API_BASE_URL;
MAX_CONNECTIONS = 100
DATABASE_URL = os.environ["DATABASE_URL"]
The all-caps signals to any reader: “this value is fixed, do not modify it.”
Converting Between Cases
When you need to convert between snake_case and other conventions — such as converting a database column name to a JavaScript variable — the case converter handles all conversions simultaneously.
Paste first_name and it immediately shows:
firstName(camelCase)FirstName(PascalCase)FIRST_NAME(CONSTANT_CASE)first-name(kebab-case)
All at once, with a single click to copy any format.
Ready to try it?
Use our free Case Converter to apply these rules instantly — no signup required.
Open Case Converter →Related articles
What Is Title Case? Rules, Examples, and Style Guides
Title case capitalizes principal words in headings. Learn the rules, see examples, and how APA, Chicago, AP, and MLA styles differ.
What Does Sentence Case Mean? Rules and Examples
Sentence case capitalizes only the first word and proper nouns. Learn when to use it, how it differs from title case, and where each is standard.
APA Title Case Rules: Complete Guide for 2026
APA 7th Edition title case lowercases all prepositions regardless of length. Complete rules, examples, and comparison with Chicago, AP, and MLA styles.
Chicago Style Title Case Rules Explained
Chicago Manual of Style title case capitalizes prepositions of 5+ letters but lowercases shorter ones. Complete CMOS 17 rules with examples.