Skip to main content Accessibility Feedback


Get and set inline styles for an element.

var elem = document.querySelector('#sandwich');

// Get a style
// If this style is not set as an inline style directly on the element, it returns an empty string
// ex. <div id="sandwich" style="background-color: green"></div>
var bgColor =; // this will return "green"
var fontWeight =; // this will return ""

// Set a style = 'purple';