camelCase vs snake_case vs kebab-case: Which đến Dùng
camelCase cho JavaScript, snake_case cho Python và databases, kebab-case cho CSS và URLs. Where each naming convention belongs và how đến convert miễn phí.
Đăng ngày · 5 phút đọc
camelCase vs snake_case vs kebab-case là mostly a question of where name lives. JavaScript và Java use camelCase (firstName), Python, Ruby và SQL use snake_case (first_name), và CSS, HTML attributes và URLs use kebab-case (first-name). Follow language's convention và của bạn team's style guide. To switch văn bản between cases, free case converter và free URL slug generator cover most of work in của bạn browser.
camelCase vs snake_case vs kebab-case at a glance
| Style | Example | Where bạn'll see it |
|---|---|---|
| camelCase | userFirstName |
JavaScript và TypeScript variables và functions, Java methods, JSON từ many web APIs |
| PascalCase | UserFirstName |
Class names in most languages, React components, C# methods |
| snake_case | user_first_name |
Python variables và functions, Ruby, SQL column names, many JSON APIs |
| SCREAMING_SNAKE_CASE | USER_FIRST_NAME |
Constants in many languages, environment variables |
| kebab-case | user-first-name |
CSS properties và class names, HTML attributes, URLs, tệp names, CLI flags |
The names come từ shapes: camelCase has humps of capital letters, snake_case lies flat on underscores, và kebab-case words là skewered on hyphens.

Language by language
JavaScript và TypeScript. Variables và functions là camelCase (getUserName), classes và React components là PascalCase (UserCard), và constants là often SCREAMING_SNAKE_CASE (MAX_RETRIES). The language's own built-ins follow this, like getElementById và toLowerCase.
Python. PEP 8, Python's style guide, uses snake_case cho functions, variables và module names, CapWords (PascalCase) cho classes, và upper case với underscores cho constants. Writing getUserName in Python works, but it sẽ look out of place đến every Python developer who reads it.
CSS và HTML. CSS properties là kebab-case (background-color, font-size), và most class-naming systems follow suit (.nav-item, .card-title). HTML data- attributes là kebab-case too, và browsers convert them cho JavaScript: data-user-id becomes element.dataset.userId. That one line là a neat summary of why both conventions exist.
SQL và databases. Column và table names là usually snake_case (created_at, order_items). Many databases fold unquoted names đến one case, so createdAt có thể quietly become createdat unless bạn quote it every time. snake_case avoids that.
URLs và tệp names. Dùng kebab-case. Google's URL structure guidance recommends hyphens rather than underscores đến separate words, because hyphens clearly mark word boundaries. Lowercase also avoids broken links on servers that treat About.html và about.html as different files. See what a URL slug is và our URL slug best practices.
JSON và APIs. There's no single rule. Many JavaScript-centred APIs use camelCase và many Python hoặc Ruby back ends return snake_case. Pick one per API và never mix them in same response.
Which là easiest đến read?
All three là readable once bạn're used đến them. A few practical differences:
- snake_case và kebab-case keep a clear gap between words, which helps với long names và acronyms (
html_parservshtmlParservsHTMLParser). - camelCase là shorter và needs no extra characters.
- kebab-case có thể't be used cho variable names in most languages, because
user-namereads asuser minus name. - Double-clicking selects a whole snake_case hoặc camelCase name in most editors, but usually stops at hyphens in kebab-case.
The real rule là consistency. A tệp that mixes userName, user_name và UserName là harder đến read than any one style used everywhere.
Converting between cases
You'll need đến convert khi moving data between layers: a Python API's created_at becoming a JavaScript createdAt, a page title becoming a URL, hoặc a setting name becoming an environment variable.
To kebab-case hoặc snake_case: use slug generator. Paste words, one name per line, và choose Hyphens (-) cho kebab-case hoặc Underscores (_) cho snake_case. It lowercases everything, turns accents into plain letters và drops symbols. It treats any symbol as a word break, so user_first_name becomes user-first-name và back again. It does not split camelCase, though: userFirstName comes out as userfirstname. Put spaces between words first.
To SCREAMING_SNAKE_CASE. Make snake_case version in slug generator, then paste it into free case converter và click UPPERCASE. Going other way, lowercase turns MAX_RETRIES into max_retries.
To camelCase hoặc PascalCase. There isn't a one-click button. The quickest route: type words với spaces, click Capitalized Case in case converter (user first name becomes User First Name), then delete spaces cho PascalCase và lowercase first letter cho camelCase.
Many names at once, inside code. For a large rename, use của bạn editor's find-và-replace với a regular expression. Test pattern first in free regex tester: cho example, _([a-z]) finds each underscore followed by a letter, spot where snake_case would need a capital in camelCase. Many editors có thể upper-case captured letter in replacement; check của bạn editor's documentation cho syntax.
Things đến watch khi converting
- Acronyms. Decide whether it's
userIdhoặcuserID,HtmlParserhoặcHTMLParser, và stick với it. - Numbers.
address_line_2converts cleanly;addressLine2là fine; just don't drop digit. - Public names. Renaming a JSON field hoặc URL breaks whoever uses it. Add a redirect cho URLs và keep old field names working cho a while in APIs.
Convert của bạn văn bản
Dùng free case converter cho UPPERCASE, lowercase và Capitalized Case, và slug generator cho kebab-case và snake_case. Both run in của bạn browser, và nothing bạn paste leaves của bạn device.
Câu hỏi thường gặp
- Điều gì là difference between camelCase và snake_case?
- camelCase joins words và capitalises each one after first (
firstName). snake_case keeps words lowercase và joins them với underscores (first_name). - Tôi có nên use camelCase hoặc snake_case in JSON?
- Either là fine. Match language most of của bạn clients use và stay consistent within API.
- Vì sao does CSS use kebab-case?
- CSS was designed với hyphenated property names like
font-size, và class names usually follow same style. Hyphens có thể't be used in most programming-language variable names, which là why JavaScript uses camelCase cho same properties. - Is kebab-case good cho URLs?
- Yes. Google recommends hyphens đến separate words in URLs, và lowercase avoids case-sensitivity problems.
- Can case converter make camelCase?
- Not in one click. Dùng Capitalized Case, then remove spaces và lowercase first letter. For kebab-case và snake_case, use URL slug generator.
Công cụ văn bản
Dùng thử Đổi chữ hoa chữ thường
Miễn phí, không cần đăng ký, chạy trên trình duyệt. Dán văn bản và đổi sang CHỮ HOA, chữ thường, Viết hoa đầu câu, Kiểu Tiêu Đề hoặc Viết Hoa Mỗi Từ chỉ với một cú nhấp, rồi sao chép.
Cũng hữu ích
- Tạo slug URLBiến tiêu đề hoặc văn bản bất kỳ thành slug URL gọn gàng, chữ thường như "my-first-blog-post". Dấu được chuyển đổi (café thành cafe), ký hiệu bị xóa, và bạn có thể bỏ các từ nhỏ, đặt độ dài tối đa hoặc tạo slug cho cả danh sách tiêu đề cùng lúc.
- Kiểm tra regexKiểm tra biểu thức chính quy với văn bản của bạn và xem mọi kết quả khớp được tô sáng ngay khi gõ, kèm bảng các nhóm bắt (cả nhóm có tên) và bản xem trước tìm và thay thế trực tiếp. Công cụ theo quy tắc regex của JavaScript, và mẫu chạy quá lâu sẽ bị dừng thay vì làm treo trang.