Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="um">
  <h1>Chave de temas com ES6</h1>
  <button type="button">Tema default</button>
  <button type="button">Tema vermelho</button>  
  <button type="button">Tema verde</button>
  <button type="button">Tema roxo</button>
</div>
              
            
!

CSS

              
                body {
  font: 100%/1.4 sans-serif;
  background: #dddddd;
  margin: 5px 0;
}
.um {
  width: 70vw;
  height: 90vh;  
  margin: 0 auto;
  padding-top: 20px;
  text-align: center;
  background: #ffffcc;
  color: #b2544d;
  border: 8px solid #0d5eb2;
}
button {
  border: 2px solid #ddd;
  background: #0d5eb2;
  color: #ffffcc;
  margin: 10px 5px;
  padding: 5px 15px;
  border-radius: 4px;
  cursor: pointer;
}
              
            
!

JS

              
                const cores = [
  { bgDiv: "#ffffcc", //Default
    corDiv: "#b2544d", 
    corBorda: "#0d5eb2",
    bgBody: "#dddddd",
  },

  { bgDiv: "#b22222",  //Vermelho
    corDiv: "#fffff0", 
    corBorda: "#d17a7a",
    bgBody: "#9cbfbb",
  },
  
  { bgDiv: "#3cb371",  //Verde
    corDiv: "#b20064", 
    corBorda: "#8ad1aa",
    bgBody: "#7fbfbd",
  },

  { bgDiv: "#9932cc",  //Roxo
    corDiv: "#003300", 
    corBorda: "#c284e0",
    bgBody: "#bbe5e0",
}
];
const secaoHead = document.querySelector('head'); 
const um = document.querySelector('.um');
let btn = document.querySelectorAll('button');	
  btn.forEach(function(bt, chave){
    bt.addEventListener('click', function(){
      //chave é o índice do botão ( 4 botões ==> 0 até 3)
const estilos = `
  <style rel="stylesheet">
    body { 
      background-color: ${ cores[chave].bgBody };
    }   
    .um { 
      background-color: ${ cores[chave].bgDiv };
      color: ${ cores[chave].corDiv };
      border-color: ${ cores[chave].corBorda };     
    }
    button {
      background-color: ${ cores[chave].corBorda };
      color: ${ cores[chave].bgDiv };
   }       
  </style>
`;
  secaoHead.insertAdjacentHTML('beforeend', estilos);	
	})
  });
              
            
!
999px

Console