Skip to content

Latest commit

 

History

History
14 lines (11 loc) · 442 Bytes

using-inline-styles.md

File metadata and controls

14 lines (11 loc) · 442 Bytes

Using inline styles within React

The style attribute accepts a JavaScript object with camelCased properties rather than a CSS string. This is consistent with the DOM style JavaScript property, is more efficient, and prevents XSS security holes. For example:

const divStyle = {
  color: 'blue',
  backgroundImage: 'url(' + imgUrl + ')',
};

function HelloWorldComponent() {
  return <div style={divStyle}>Hello World!</div>;
}