get/set CSS props

// get: 
elem.style.color                // ไฝฟ็”จ <elem style="...">
getComputedStyle(elem).color    // โญ๏ธ computed style โ‰  elem.style.colorโ—๏ธ

// set: 
elem.style.color = 'pink';           // ่จญๅฎšๅ…งๅปบๆจฃๅผ
elem.styleProp('--css-var', '4px');  // ่จญๅฎš่‡ช่จ‚ css var

CSS vs. DOM style prop names

CSS prop (kebab case)
DOM prop (camel case)

'background-color'

elem.style.backgroundColor

'z-index'

elem.style.zIndex

'border-left-width'

elem.style.borderLeftWidth

code example

Last updated

Was this helpful?