Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does vanilla HTML/JS (and React) use camelCase for stylings, while CSS does not? [closed]

Different pieces of technology regarding styling require different conventions for naming certain properties, mainly camelCase vs. hyphenated-style

Setting styles directly on an HTML DOM Node via JS - element.style.paddingTop = "12px";

Setting styles inline in React - < Component style={{paddingTop: "12px"}} />

Setting it in a .CSS file - .selector {padding-top: 12px}

What is the underlying reason for the different rules? I don't see why this is better than all of HTML/CSS/JS using camelCase, or all of it using hyphenated-style.

like image 617
Inco Gnito Avatar asked Dec 12 '25 01:12

Inco Gnito


1 Answers

In JavaScript, kebab-case doesn't fit because of syntax rule. - is not allowed in identifier so padding-top is not valid for variable or property name.

In CSS, camelCase is not a good practice because CSS is case-insensitive. className and classname is the same identifier for CSS.

like image 111
zmag Avatar answered Dec 14 '25 14:12

zmag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!