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
| Input | camelCase | snake_case | What it shows |
|---|---|---|---|
| user account id | userAccountId | user_account_id | Plain words. |
| parse HTML string | parseHtmlString | parse_html_string | An acronym. |
| version 2 update | version2Update | version_2_update | A number. |
The rules compared
| Rule | camelCase | snake_case |
|---|---|---|
| Word boundaries | Marked by a capital letter at the start of each word after the first. | Marked by an underscore between words. |
| Letter case | The first word is lowercase; each later word starts with a capital. | Every letter is lowercase. |
| Acronyms | Treated as ordinary words: HTML becomes Html after the first word. | Lowercased like every other word: HTML becomes html. |
| Numbers | Joined 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 ignored | Systems 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 Convertersnake_case
Functions and variables in Python (PEP 8), Ruby, and Rust, and database table and column names.
snake_case Converter