Skip to main content

camelCase vs snake_case: Which Naming Convention Should You Use?

camelCase and snake_case are two ways to write a name made of several words without spaces. camelCase joins the words and capitalizes each one after the first. snake_case writes every letter in lowercase and puts an underscore between words.

Follow the convention of the language or codebase you are working in. Converting a name from one to the other keeps its words, with two exceptions. A word that starts with a digit in snake_case joins the word before it in camelCase, so version_2_update becomes version2Update, which converts back as version2_update, and enable_2fa becomes enable2fa. Acronyms lose their capitals: getHTTPResponse becomes get_http_response, which converts back as getHttpResponse. The examples below come from the camelCase and snake_case converters.

Side by side

The same input in camelCase and snake_case
InputcamelCasesnake_caseWhat it shows
user account iduserAccountIduser_account_idPlain words.
parse HTML stringparseHtmlStringparse_html_stringAn acronym.
version 2 updateversion2Updateversion_2_updateA number.

The rules compared

How camelCase and snake_case differ
RulecamelCasesnake_case
Word boundariesMarked by a capital letter at the start of each word after the first.Marked by an underscore between words.
Letter caseThe first word is lowercase; each later word starts with a capital.Every letter is lowercase.
AcronymsTreated as ordinary words: HTML becomes Html after the first word.Lowercased like every other word: HTML becomes html.
NumbersJoined to the word before them: version 2 update becomes version2Update.Kept as their own word: version 2 update becomes version_2_update.
Where letter case is ignoredSystems that ignore case, such as some databases and file systems, lose the boundaries.The underscores keep the boundaries visible.

When to use each

camelCase

Variables and functions in JavaScript, TypeScript, and Java, and JSON field names in many APIs.

camelCase Converter

snake_case

Functions and variables in Python (PEP 8), Ruby, and Rust, and database table and column names.

snake_case Converter

Read more