Pen Settings



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


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


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.


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.


                  <div class="keys">
    <div data-key="65" class="key">
      <span class="sound">clap</span>
    <div data-key="83" class="key">
      <span class="sound">hihat</span>
    <div data-key="68" class="key">
      <span class="sound">kick</span>
    <div data-key="70" class="key">
      <span class="sound">openhat</span>
    <div data-key="71" class="key">
      <span class="sound">boom</span>
    <div data-key="72" class="key">
      <span class="sound">ride</span>
    <div data-key="74" class="key">
      <span class="sound">snare</span>
    <div data-key="75" class="key">
      <span class="sound">tom</span>
    <div data-key="76" class="key">
      <span class="sound">tink</span>

  <audio data-key="65" src=""></audio>
  <audio data-key="83" src="sounds/hihat.wav"></audio>
  <audio data-key="68" src="sounds/kick.wav"></audio>
  <audio data-key="70" src="sounds/openhat.wav"></audio>
  <audio data-key="71" src="sounds/boom.wav"></audio>
  <audio data-key="72" src="sounds/ride.wav"></audio>
  <audio data-key="74" src="sounds/snare.wav"></audio>
  <audio data-key="75" src="sounds/tom.wav"></audio>
  <audio data-key="76" src="sounds/tink.wav"></audio>


                html {
  font-size: 10px;
  background: url( bottom center;
  background-size: cover;

body,html {
  margin: 0;
  padding: 0;
  font-family: sans-serif;

.keys {
  display: flex;
  flex: 1;
  min-height: 100vh;
  align-items: center;
  justify-content: center;

.key {
  border: .4rem solid black;
  border-radius: .5rem;
  margin: 1rem;
  font-size: 1.5rem;
  padding: 1rem .5rem;
  transition: all .07s ease;
  width: 10rem;
  text-align: center;
  color: white;
  background: rgba(0,0,0,0.4);
  text-shadow: 0 0 .5rem black;

.playing {
  transform: scale(1.1);
  border-color: #ffc600;
  box-shadow: 0 0 1rem #ffc600;

kbd {
  display: block;
  font-size: 4rem;

.sound {
  font-size: 1.2rem;
  text-transform: uppercase;
  letter-spacing: .1rem;
  color: #ffc600;



                function playSound(e) {
    const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`)
    const key = document.querySelector(`.key[data-key="${e.keyCode}"]`)
    if(!audio) return //如果沒有audio存在就終止這個function(也就是此鍵盤按鈕沒有對應的audio標籤)
    audio.currentTime = 0 //每次撥放前都將音頻倒轉到最開始的地方
  function removeTransition(e) {
    if(e.propertyName !=='transform') return
  const keys = document.querySelectorAll('.key'
  keys.forEach(key => key.addEventListener('transitionend',removeTransition))
  window.addEventListener('keydown', playSound)