Dash instead on underline writing convention reason

Firstly I would have put this the About HTML-CSS category, if I could have worked why. Sorry this is likely a very commonly asked question. Why it is that dashes are used in the to separate words (if you know what I mean) in like of property and class names as opposed to underline as in my experience common in other situations. Depending on the answer there may a follow up question.

I don’t know for sure. But it is a reasonable style for the category name. If it was changed we would be breaking a lot of links and bookmarks without very many benefits. I hope this helps answer your question.

It is an I wonder question if no one gives me know he a answer I can just accept that is way HTML/CSS does like other programming language differences. If I am honest I do not have the knowledge to understand your comment so I think it is probably best to ignore it.

there are many ways to write variables, and class names and id names

the way to write them (and this all for languages) depend both on what is allowed, and what style is preferred

here you can read about four common cases:

how it comes to what is preferred for what language, I am not sure. Like for HTML and CSS kebab-case is most common, but JavaScript prefers camelCase (and in some cases PascalCase) while python goes with snake case…

1 Like

If you are talking about HTML/CSS attributes, properties, etc. I assume Kebab case was selected for historical reasons (precursor document structuring languages like SGML/XML). With some amount of interoperability between languages and reuse of parser rules.

As for why it originally was selected for document structuring languages, again my assumption would be because hyphenated words (compound words) are already used in natural languages, as such it makes sense for document structuring languages.

HTML/CSS code author keep that style for consistency, even when it isn’t necessarily required.


This is all just assumptions. You could probably look up old specs and ISO standards for document structuring languages to find the answer.

1 Like

I consider both recent comments to be a solutions but can only tick one. I should have realised it is like comments there is no consistency or popular convention. I actually had studied casings in previous course I did but forgot about it. I will say using dashes felt very counter intuitive, however should make a lot of sense when you consider hyphenated words. Python is certainly the most recent language I got skilled in and other ones it is longer since I used them, so it makes sense its conventions stick in my head. I will also part of me felt like asking the question because I thought I might have a theory on a half answer. I have to do with other uses for underline taking priority in the language. I could say more but I have possibly said more than worthwhile already. Sorry expressing certainty in something did not have the knowledge in.

As mention in a comment below I also consider ILM comment a solution in a different way.