cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

              .bar {
  transition: top .5s;
.bar__label, .label {
  display: inline-block;
  font-family: sans-serif;
  font-size: 10px;
  line-height: 20px;
  text-transform: uppercase;
  vertical-align: top;
.bar__label {
  text-align: right;
  width: 50px;

.bar__mark {
  background: orange;
  display: inline-block;
  height: 16px;
  margin-left: 10px;
  margin-top: 2px;
  transition: width 1s;

.switch__track {
  border-radius: 10px;
  box-shadow: inset 0px 1px 3px 0px rgba(0,0,0,0.50);
  display: inline-block;
  margin: 0 20px;
  position: relative;
  width: 60px;
  height: 20px;
  background: #c0c0c0;

.switch__thumb {
  background: #d6d6d5;
  border-radius: 10px;
  position: relative;
  left: 1px;
  top: 1px;
  width: 18px;
  height: 18px;
  transition: left .5s;

.switch__thumb.death {
  left: 41px;

.label {
              // dataset 'birthdeathrates' loaded from pen https://codepen.io/jckr/pen/JKXLVe
// form: array of objects with country, birth and death properties

class Chart extends React.Component {
   constructor(props) {
     this.state = {
       metric: 'birth',
  render() {
    const metric = this.state.metric;
    const data = this.props.data.sort((a,b) => b[metric] - a[metric])
      .map((d, i) => ({...d, rank: i}))
      .sort((a, b) => b.country > a.country);
    return <div className='chart'>
       <span className='label'>Birth rate</span>,
       <Switch metric={metric} updateMetric={(d) =>
            this.setState({metric: d})
       <span className='label'>Death rate</span>,
         {data.map(d => 
            country={d.country} value={d[metric]} rank={d.rank}/>

// using pure functional components for the rest 
function Switch({metric, updateMetric}) {
  return <div className = 'switch__track'
           onClick = {() => updateMetric(metric === 'birth' ? 'death' : 'birth')}
           <div className = {'switch__thumb ' + metric} />

function Bar({country, value, rank}) {
  return <div
    style={{position: 'absolute',
    top: 30 + 20 * rank,
    transition: 'top .5s'}} >
    <div className='bar__label'>{country}</div>
    <div className='bar__mark' 
      style={{width: 4 * value}}/>

const chart = <Chart data={birthdeathrates} />

ReactDOM.render(chart, document.querySelector('#root'));
Loading ..................