3tej home

What is snake_case Converter?

A snake_case Converter converts data from one format to another using a deterministic mapping. It parses the input, transforms it according to the relevant standard, and returns a ready-to-use result. Paste any phrase and convert to snake_case: lowercase letters joined by underscores.

snake_case Converter

Paste any phrase and convert it to snake_case: lowercased words joined by underscores.

Browser-onlyInstantFree foreverWorks offlineNo signup
← Utilities

TLDR

Lowercases your input and replaces any run of non-alphanumeric characters with a single underscore. Strips leading and trailing underscores.

0 words · 0 chars
Runs entirely in your browser. No upload, no signup, no logging. Output is for personal or commercial use; we don't claim any rights.

About snake_case

snake_case is the identifier style in which words are joined by underscores and every letter is lowercase: user_first_name, get_full_url, parse_json_response. The name is a visual metaphor for the underscore lying low between segments, in contrast to the humps of camelCase or the hyphens of kebab-case. It is the official identifier style for Python (PEP 8), Ruby, Rust, Elixir, and Erlang variables and functions, the conventional column-naming style for PostgreSQL and MySQL, and the recommended file-naming style across most Linux and POSIX shells.

Underscores were chosen as separators in early Unix and C because they sit on the home row, do not break visual flow in monospace fonts, and are allowed inside C identifiers (unlike hyphens, which collide with subtraction). When the Python style guide PEP 8 was published in 2001, snake_case was already idiomatic in CPython's own source, and it has propagated to every modern dynamic language that draws cultural lineage from Python: NumPy, pandas, Django, Flask, FastAPI, and SQLAlchemy all use it religiously.

How the converter works

step 1: lowercase the whole input
step 2: replace /[^a-z0-9]+/g with a single underscore
step 3: strip leading and trailing underscores
result = trim(input.toLowerCase().replace(/[^a-z0-9]+/g, '_'), '_')
  • Lowercase first. Any uppercase letters fold down before separator detection so the result is uniformly lowercase.
  • Coalesce separators. Spaces, hyphens, dots, slashes, parentheses, and other punctuation collapse together into one underscore, no matter how many are adjacent.
  • Trim edges. If the input started or ended with punctuation, the underscores at the front or back are removed so the result reads cleanly.
  • Digits preserved. Numbers stay where they were, but a leading digit (2024_revenue) will not be moved or stripped; you may need to rename if your target language disallows it.

Worked example

Input: a CSV header copied from a marketing dashboard:

Customer's Email Opens (Q3 2026) - Top 10%
  1. Lowercase. customer's email opens (q3 2026) - top 10%.
  2. Coalesce punctuation. The apostrophe, space, parenthesis, hyphen, and percent sign all reduce to underscores: customer_s_email_opens_q3_2026_top_10_.
  3. Trim trailing underscore. customer_s_email_opens_q3_2026_top_10.
Result: customer_s_email_opens_q3_2026_top_10
A legal PostgreSQL identifier, a legal Python variable, and a portable filename across Linux, macOS, and Windows.

You may want to drop the stray _s from the genitive apostrophe and rename to customer_email_opens_q3_2026_top_10. Edits like that are a five-second post-process. The converter does the bulk renaming.

Convention reference by ecosystem

Language or systemVariables / functionsTypes / classesConstants
Python (PEP 8)snake_casePascalCaseUPPER_SNAKE
Rubysnake_casePascalCaseUPPER_SNAKE
Rustsnake_casePascalCaseUPPER_SNAKE
Elixir, Erlangsnake_casePascalCase (modules)UPPER_SNAKE
PostgreSQL, MySQL, SQLitesnake_case (unquoted)snake_caseUPPER_SNAKE
Bash, POSIX shellssnake_case or UPPER_SNAKEn/aUPPER_SNAKE
YAML, TOML config keyssnake_casen/an/a
JavaScript, Java, Swift, C#camelCasePascalCaseUPPER_SNAKE
HTML attributes, CSS classeskebab-casen/an/a

Pitfalls to watch for

  • camelCase input is not split. firstName becomes firstname, not first_name. To split on internal capital letters you need to pre-process with a regex like /([a-z])([A-Z])/g -> $1 $2, or use a dedicated camel-to-snake tool.
  • Leading digits are not stripped. 2024 revenue produces 2024_revenue, which is fine for SQL but invalid as a Python identifier. Rename to revenue_2024.
  • Hyphens vanish silently. background-color becomes background_color, the conventional Python or SQL form. If you wanted to keep it as the React style key (backgroundColor), use the camelCase converter instead.
  • Quoted identifiers hide casing bugs. Postgres lets you write CREATE TABLE "MyTable", but you must quote it in every subsequent query, including joins. Stick to unquoted snake_case.
  • Non-Latin characters are stripped. piñata becomes pi_ata; Cyrillic and CJK identifiers are erased entirely. If you need Unicode identifiers, Python 3 allows them but PEP 8 still recommends ASCII.
  • Long names exceed identifier limits. PostgreSQL caps identifiers at 63 bytes, MySQL at 64, Oracle at 30. Long snake_case names from CSV headers can be truncated silently, breaking foreign-key joins.

Related case-conversion tools

Frequently asked questions

Does the converter split camelCase or PascalCase input correctly?

No. firstName becomes firstname, not first_name, because the splitter only treats non-alphanumeric runs as boundaries. To split camelCase, insert spaces or hyphens between the words first (firstName becomes first Name), then convert. A full camel-to-snake converter would need to look at uppercase letters as implicit boundaries, which this lightweight version does not.

How are accented letters, emoji, and CJK characters treated?

The converter normalises to ASCII [a-z0-9] plus underscores. Accented characters like ñ, é, and ü are treated as separators and become underscores, so 'piñata' becomes 'pi_ata'. Emoji and CJK ideographs are also stripped. If you need accented identifiers, paste the result into your editor and restore the characters manually, but most SQL and Python style guides recommend ASCII-only identifiers anyway.

What is the difference between snake_case, SCREAMING_SNAKE_CASE, and kebab-case?

snake_case is all lowercase with underscores between words (user_first_name), used for Python and Ruby variables, SQL column names, and filenames. SCREAMING_SNAKE_CASE is uppercase with underscores (USER_FIRST_NAME), used for constants and environment variables. kebab-case uses hyphens (user-first-name), used for URL slugs, CSS class names, and HTML attributes.

Is snake_case valid as a SQL column name and a Python identifier?

Yes in both cases as long as the first character is a letter or underscore, not a digit. SQL ANSI identifiers may start with a letter or underscore, contain letters, digits, and underscores, and be up to 63 characters in PostgreSQL or 64 in MySQL. Python 3 allows Unicode letters in identifiers but PEP 8 recommends ASCII snake_case. '2024_q3_revenue' is illegal in Python; rename to 'q3_revenue_2024'.

Why do PostgreSQL and MySQL prefer snake_case over camelCase?

Both databases fold unquoted identifiers to lowercase: PostgreSQL to lowercase, MySQL by default also to lowercase on case-insensitive filesystems (the default on Windows and macOS). camelCase columns silently become lowercase mush. Quoting ("userFirstName") preserves the case but is required everywhere, including in joins and views, which is a maintenance burden. snake_case identifiers need no quoting and stay readable.