CSS Property Names in JavaScript

By Xah Lee. Date: . Last updated: .

Hypen in Name or Not

CSS property names are hyphen separated, e.g. font-size.

JavaScript property names are camelCase: e.g. fontSize.

Here is a table of setting styles in CSS and in JavaScript:

CSS Syntax vs JavaScript DOM Syntax
CSS JavaScript
background-color x.style.backgroundColor
font-size x.style.fontSize
font-family x.style.fontFamily

How to Find the Exact CSS Property Name in JavaScript

A easy way to check style property is to use browser's JavaScript console name completion feature. Type document.body.style. then press Tab, it'll show a list. γ€”see How to Use Browser Console〕

Google Chrome browser console completion
Google Chrome browser console JavaScript keyword completion

JavaScript DOM, Change CSS