Code to modify DOM element using DOM.style property
Inline style lengths require units. In quirks mode, browsers will assume pixels as the unit, if provided with an integer instead of a length. If you are not sure how the browser will handle the value, specify the units.


  The CSS parser interprets unitless numbers as px (except for line-height and any other properties where they have distinct meaning, and except in shorthands).


Bonus: Here is an extensible version of your script.



const state = {
  color : { r : 0, g : 255, b : 0 },
  dimensions : { width : 50, height : 300 }
}

const applyState = (el, state) =&gt; {
  Object.assign(el.style, {
    backgroundColor: `rgb(${state.color.r}, ${state.color.g}, ${state.color.b})`,
    width: `${state.dimensions.width}px`,
    height: `${state.dimensions.height}px`
  })
}

applyState(document.getElementById('my-div'), state)
&lt;div id="my-div"&gt;&lt;/div&gt;