CSS is a hyphen-delimited syntax language which means while writing HTML attributes we can use hyphen(-).
font-size, line-height, background-color, etc...
There are various reasons to preferring hyphen(-):
- In CSS, one can use underscore(_) instead of hyphen(-) for CSS selectors(class, id, span, …), but preference is given based on its ease to use.
- Underscores require hitting the Shift key and are therefore harder to type. On the other hand, CSS already uses hyphen or dash as the part of their official code so it makes more convenient to use a hyphen rather than using underscore.
- Instead of using dashes, we can also use camel case to write but it has issues to use it like, it is harder to read and whitespace between the word makes them more clear to read.
- There is also one more benefit of using dashes that it makes the code more readable.
From the above code, it is clear that using dash is a more appropriate way of writing program instead of using a camel case or underscore and thus, due to this fact dashes are preferred for CSS selectors/HTML attributes.
- What is Redux Toolkit and why it is more preferred?
- CSS | Selectors Complete Reference
- Advanced Selectors in CSS
- Wildcard Selectors (*, ^ and $) in CSS for classes
- CSS | Syntax and Selectors
- Which characters are valid in CSS class names/selectors?
- CSS Child vs Descendant selectors
- 10 CSS Selectors Every Developer Should Know
- JQuery | Multiple ID selectors
- SASS | Placeholder Selectors
- HTML | Attributes
- HTML | Id Attributes
- HTML | data-* Attributes
- HTML | DOM attributes Property
- HTML | Attributes Complete Reference
- Difference between 'hidden' and 'aria-hidden' attributes in HTML
- Tags vs Elements vs Attributes in HTML
- What is the difference between properties and attributes in HTML?
- jQuery | Set Content and Attributes
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.