CSS Attribute Name in JavaScript

By Xah Lee. Date: . Last updated: .

CSS attribute names are dash separated, example: font-size.

The corresponding property in JavaScript is camelCase: fontSize.

Here's a table of setting styles in CSS and in JavaScript:

CSS Syntax vs JavaScript DOM Syntax
CSSJavaScript
padding:1emele.style.padding="1em"
border:solid thin redele.style.border="solid thin red"
background-color:redele.style.backgroundColor="red"
font-size:largeele.style.fontSize="large"
font-family:"DejaVu Sans",sans-serifele.style.fontFamily='"DejaVu Sans",sans-serif'
Google Chrome browser console completion
Google Chrome browser console JavaScript keyword completion

A easy way to check style attribute is to use browser's JavaScript console completion feature. Type document.body.style. then press Tab, it'll show a list. [see JS: How to Use Browser Console]

DOM How-To


Web Scripting Overview


HTML Input


Web Scripting Examples


Web Scripting Misc


jQuery


node.js

Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials