javascript style object code example

Example 1: adding styling to element using javascript

var elem = document.querySelector('#some-element');

// Set color to purple
elem.style.color = 'purple';

// Set the background color to a light gray
elem.style.backgroundColor = '#e5e5e5';

// Set the height to 150px
elem.style.height = '150px';

Example 2: javascript style

// background-color
<element>.style.backgroundColor = '#000';
// background
<element>.style.background = '#000';
// color
<element>.style.color = '#fff';
// box-sizing
<element>.style.boxSizing = 'border-box';
// font-family
<element>.style.fontFamily = '\'Times New Roman\', Times, serif';
// font-size
<element>.style.fontSize = '16px';
// margin
<element>.style.margin = 0;
// padding
<element>.style.padding = '20px';
// width
<element>.style.width = '100%';
// height
<element>.style.height = '100%';
// margin-left
<element>.style.marginLeft = 0;
// font-weight
<element>.style.fontWeight = 400;