Guides/Snake_case vs kebab-case
Snake_case vs kebab-case
Both styles replace spaces with a separator and usually lowercase every word. The separator is the difference: underscore (_) vs hyphen (-).
What they look like
- snake_case:
hello_world_example - kebab-case:
hello-world-example - Same words; different glue. Neither is “more correct” — context decides.
When to use snake_case
- Python variables and functions (PEP 8 style).
- Many database column names and some API JSON fields.
- File names in communities that prefer underscores.
When to use kebab-case
- URL slugs:
/guides/snake-case-vs-kebab-case - CSS class names and many HTML data attributes.
- Package names on some registries; readable multi-word paths.
Worked examples
- Input:
Hello World Example Text
snake_case → hello_world_example_text
kebab-case → hello-world-example-text - API field vs CSS:
user_countin JSON;user-countas a class is fine if your team agrees. - URL: prefer kebab-case over spaces or underscores for public web paths (hyphens are the web norm).
Common mistakes
- Putting spaces or camelCase in URLs when a kebab slug was expected.
- Mixing separators in one codebase (
user_idnext touser-namewithout a rule). - Using hyphens in languages where
-means minus (Python identifiers cannot be kebab-case).
Convert instantly
Paste into the freeCase Converterand tap snake_case or kebab-case. For headline casing, seetitle case vs sentence case.
Related:Title vs sentence case·camelCase vs PascalCase·Word Counter