var myStyles = [ {width:200, name : 'John', color:'red'}, {width:300, name : 'Barry', color:'green'}, {width:19, name : 'Mary', color:'blue'}, {width:68, name : 'Helen', color:'black'}, {width:340, name : 'Colin', color:'pink'}, ] d3.selectAll('#chart').selectAll('div') .data(myStyles) .enter().append('div') .classed('item', true) .text(function(d){ return d.name; }) .style({ 'color':'white', 'background': function(d){ return d.color; }, 'width': function(d){ return d.width+'px'; } })