• Inline Styles

    Inline Styles

    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):

    1. var divStyle = {
    2. color: 'white',
    3. backgroundImage: 'url(' + imgUrl + ')',
    4. WebkitTransition: 'all', // note the capital 'W' here
    5. msTransition: 'all' // 'ms' is the only lowercase vendor prefix
    6. };
    7. ReactDOM.render(<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”.