Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 1.02 KB

02-inline-styles.md

File metadata and controls

25 lines (20 loc) · 1.02 KB
id title layout permalink next prev
inline-styles
Inline Styles
tips
inline-styles.html
if-else-in-JSX.html
introduction.html

In React, inline styles are not specified as a string. Instead they are specified with an object whose key is the camelCased version of the style name, and whose value is the style's value, usually a string (more on that later):

/** @jsx React.DOM */

var divStyle = {
  color: 'white',
  backgroundImage: 'url(' + imgUrl + ')',
  WebkitTransition: 'all', // note the capital 'W' here
  msTransition: 'all' // 'ms' is the only lowercase vendor prefix
};

React.renderComponent(<div style={divStyle}>Hello World!</div>, mountNode);

Style keys are camelCased in order to be consistent with accessing the properties on DOM nodes from JS (e.g. node.style.backgroundImage). Vendor prefixes other than ms should begin with a capital letter. This is why WebkitTransition has an uppercase "W".