什么是短横线命名法? | AI生成和翻译

Home 2026.01

Question: 什么是 kebab case?

Answer:

Kebab case(也称为 kebab-casekebab styledash case)是一种命名规范,其特点是:

Examples:

my-variable-name
user-profile-picture
api-key-secret
dark-mode-toggle
get-user-by-id
background-color-red-500

Comparison with other common naming conventions

Naming style Example Description Common usage
kebab-case user-profile-picture lowercase + hyphens CSS classes, HTML attributes, URLs
snake_case user_profile_picture lowercase + underscores Python, Ruby, Rust, PostgreSQL
camelCase userProfilePicture first word lowercase, others capitalized JavaScript variables, JSON keys
PascalCase UserProfilePicture every word capitalized Java, C#, TypeScript class names
SCREAMING_SNAKE_CASE USER_PROFILE_PICTURE uppercase + underscores Constants, environment variables

Where kebab-case is most commonly used (2025–2026)

Quick memory tip:
想象一下真实的 kebab(烤肉串)—— 每一块肉被 sticks(签子)分隔 → 每个单词被 dashes(短横线)分隔。

References:


Back

x-ai/grok-4.1-fast

Donate