lmirosevic
lmirosevic

Reputation: 16317

What's the name for hyphen-separated case?

This is PascalCase: SomeSymbol

This is camelCase: someSymbol

This is snake_case: some_symbol

So my questions is whether there is a widely accepted name for this: some-symbol? It's commonly used in urls.

Upvotes: 718

Views: 262894

Answers (15)

Ben Lee
Ben Lee

Reputation: 53349

This is known as dash-case or kebab-case.

No other terms have achieved wide adoption, though there are various other coinings out there including hyphen-case, caterpillar-case, lisp-case, train-case, url-case, slug-case, and css-case.

It seems kebab-case in particular has entered the lexicon of several javascript code libraries.

Upvotes: 605

Guillaume Husta
Guillaume Husta

Reputation: 4385

As the character (-) is referred to as "hyphen" or "dash", it seems more natural to name this "dash-case", or "hyphen-case" (less frequently used).

As mentioned in Wikipedia, "kebab-case" is also used. Apparently (see answer) this is because the character would look like a skewer... It needs some imagination though.
Used in lodash lib for example.

Recently, "dash-case" was used by

Upvotes: 22

Cameron McKenzie
Cameron McKenzie

Reputation: 3920

I've always known it as kebab-case.

On a funny note, I've heard people call it a SCREAM-KEBAB when all the letters are capitalized.

Kebab Case Warning

I've always liked kebab-case as it seems the most readable when you need whitespace. However, some programs interpret the dash as a minus sign, and it can cause problems as what you think is a name turns into a subtraction operation.

first-second  // first minus second?
ten-2 // ten minus two?

Also, some frameworks parse dashes in kebab cased property. For example, GitHub Pages uses Jekyll, and Jekyll parses any dashes it finds in an md file. For example, a file named 2020-1-2-homepage.md on GitHub Pages gets put into a folder structured as \2020\1\2\homepage.html when the site is compiled.

Snake_case vs kebab-case

A safer alternative to kebab-case is snake_case, or SCREAMING_SNAKE_CASE, as underscores cause less confusion when compared to a minus sign.

Upvotes: 8

Gaurang Patel
Gaurang Patel

Reputation: 532

There is no standardized name.

Libraries like jquery and lodash refer it as kebab-case. So does Vuejs javascript framework. However, I am not sure whether it's safe to declare that it's referred as kebab-case in javascript world.

Upvotes: 6

Shadi Alnamrouti
Shadi Alnamrouti

Reputation: 13298

This is the most famous case and It has many names

  • kebab-case: It's the name most adopted by official software
  • caterpillar-case
  • dash-case
  • hyphen-case or hyphenated-case
  • lisp-case
  • spinal-case
  • css-case
  • slug-case
  • friendly-url-case

Upvotes: 25

MgSam
MgSam

Reputation: 12813

This casing can also be called a "slug", and the process of turning a phrase into it "slugify".

https://hexdocs.pm/slugify/Slug.html

Upvotes: 1

Christoph Bühler
Christoph Bühler

Reputation: 2923

My ECMAScript proposal for String.prototype.toKebabCase.

String.prototype.toKebabCase = function () {
  return this.valueOf().replace(/-/g, ' ').split('')
    .reduce((str, char) => char.toUpperCase() === char ?
      `${str} ${char}` :
      `${str}${char}`, ''
    ).replace(/ * /g, ' ').trim().replace(/ /g, '-').toLowerCase();
}

Upvotes: 1

Ramanraj Saxena
Ramanraj Saxena

Reputation: 45

In Salesforce, It is referred as kebab-case. See below

https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.js_props_names

Upvotes: 4

albfan
albfan

Reputation: 12970

Worth to mention from abolish:

https://github.com/tpope/vim-abolish/blob/master/doc/abolish.txt#L152

dash-case or kebab-case

Upvotes: 5

Wray Smallwood
Wray Smallwood

Reputation: 87

Here is a more recent discombobulation. Documentation everywhere in angular JS and Pluralsight courses and books on angular, all refer to kebab-case as snake-case, not differentiating between the two.

Its too bad caterpillar-case did not stick because snake_case and caterpillar-case are easily remembered and actually look like what they represent (if you have a good imagination).

Upvotes: 2

Mike Campbell
Mike Campbell

Reputation: 7978

I've always called it, and heard it be called, 'dashcase.'

Upvotes: 11

Jem Marsh
Jem Marsh

Reputation: 89

I'd simply say that it was hyphenated.

Upvotes: 5

user666
user666

Reputation: 1172

Adding the correct link here Kebab Case

which is All lowercase with - separating words.

Upvotes: 17

jwfearn
jwfearn

Reputation: 29627

It's referred to as kebab-case. See lodash docs.

Upvotes: 524

tim_yates
tim_yates

Reputation: 171154

It's also sometimes known as caterpillar-case

Upvotes: 39

Related Questions