<!DOCTYPE html>
<html>
	<head>
		<meta charaset="UTF-8">
		<title> Piano/Synthesizer </title>
	</head>
	<body>
    <section class="wrap">
  <h1>Name Your Piano</h1>
    <section id="main">
      <div class="nowplaying"></div>
	  <div class="keys">
     <div data-key="65" class="key"> <span class="hints">A</span> </div>
		    
	      <div data-key="87" class="key sharp" > <span class="hints">W</span> </div>
		    
	      <div data-key="83" class="key" > <span class="hints">S</span> </div>
		    
	      <div data-key="69" class="key sharp" > <span class="hints">E</span> </div>
		    
	      <div data-key="68" class="key" > <span class="hints">D</span> </div>
		    
		<div data-key="70" class="key" > <span class="hints">F</span> </div>

		<div data-key="84" class="key sharp" > <span class="hints">T</span> </div>

		<div data-key="71" class="key" > <span class="hints">G</span> </div>

		<div data-key="89" class="key sharp" > <span class="hints">Y</span> </div>

		<div data-key="72" class="key" > <span class="hints">H</span> </div>

		<div data-key="85" class="key sharp" > <span class="hints">U</span> </div>

		<div data-key="74" class="key" > <span class="hints">J</span> </div>

		<div data-key="75" class="key" > <span class="hints">K</span> </div>

		<div data-key="79" class="key sharp" > <span class="hints">O</span> </div>

		<div data-key="76" class="key" > <span class="hints">L</span> </div>
		  
		<div data-key="80" class="key sharp" > <span class="hints">P</span> </div>
		  
		<div data-key="186" class="key" > <span class="hints">;</span> </div>
   </div>
</div>
         <audio data-key="65" src="http://carolinegabriel.com/demo/js-keyboard/sounds/040.wav"></audio>
         <audio data-key="65" src="http://carolinegabriel.com/demo/js-keyboard/sounds/040.wav"></audio>
         <audio data-key="65" src="http://carolinegabriel.com/demo/js-keyboard/sounds/040.wav"></audio>
         <audio data-key="65" src="http://carolinegabriel.com/demo/js-keyboard/sounds/040.wav"></audio>
         <audio data-key="65" src="http://carolinegabriel.com/demo/js-keyboard/sounds/040.wav"></audio>
         <audio data-key="65" src="http://carolinegabriel.com/demo/js-keyboard/sounds/040.wav"></audio>
         <audio data-key="65" src="http://carolinegabriel.com/demo/js-keyboard/sounds/040.wav"></audio>
         <audio data-key="65" src="http://carolinegabriel.com/demo/js-keyboard/sounds/040.wav"></audio>
         <audio data-key="65" src="http://carolinegabriel.com/demo/js-keyboard/sounds/040.wav"></audio>
         <audio data-key="65" src="http://carolinegabriel.com/demo/js-keyboard/sounds/040.wav"></audio>
         <audio data-key="65" src="http://carolinegabriel.com/demo/js-keyboard/sounds/040.wav"></audio>

  </section>
</section>
	</body>
</html>
html  {
    background: white;
    font-family: 'Noto Serif', serif;
    -webkit-font-smoothing: antialiased;
    text-align: center;
}
	
body {
  background-color: white;
}

h1 {
      color: black;
      font-family: 'Bungee';
      font-size: 50px;
      font-weight: 400;
      letter-spacing: 0.18em;
      text-transform: uppercase;
      margin: 0;
}	
.nowplaying {
    font-size: 120px;
    line-height: 1;
    color: #eee;
    text-shadow: 0 0 5rem #028ae9;
    transition: all .07s ease;
    min-height: 120px;
}
.keys {
    display: block;
    width: 100%;
    height: 350px;
    max-width: 880px;
    position: relative;
    margin: 40px auto 0;
    cursor: none;
}
.key {
    position: relative;
    border: 4px solid black;
    border-radius: .5rem;
    transition: all .07s ease;
    display: block;
    box-sizing: border-box;
    z-index: 2;
}

.key:not(.sharp) {
    float: left;
    width: 10%;
    height: 100%;
    background: rgba(255, 255, 255, .8);    
}

.key.sharp {
    position: absolute;
    width: 6%;
    height: 60%;
    background: #818285;
    color: #eee;
    top: 0;
    z-index: 3;
}

.key[data-key="87"] {
    left: 7%;
}

.key[data-key="69"] {
    left: 17%;
}

.key[data-key="84"]  {
    left: 37%;
}

.key[data-key="89"] {
    left: 47%;
}

.key[data-key="85"] {
    left: 57%;    
}

.key[data-key="79"] {
    left: 77%;    
}

.key[data-key="80"] {
    left: 87%;    
}

.playing {
    transform: scale(.95);
    border-color: #028ae9;
    box-shadow: 0 0 1rem #028ae9;
}

.hints {
    display: block;
    width: 100%;
    opacity: 0;
    position: absolute;
    bottom: 7px;
    transition: opacity .3s ease-out;
    font-size: 20px;
}

.keys:hover .hints {
    opacity: 1;
}
.playing {
    transform: scale(.95);
    border-color: #028ae9;
    box-shadow: 0 0 1rem #028ae9;
}

.hints {
    display: block;
    width: 100%;
    opacity: 0;
    position: absolute;
    bottom: 7px;
    transition: opacity .3s ease-out;
    font-size: 20px;
}

.keys:hover .hints {
    opacity: 1;
}
const keys = document.querySelectorAll(".key"),
  note = document.querySelector(".nowplaying"),
  hints = document.querySelectorAll(".hints");

function playNote(e) {
  const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`),
    key = document.querySelector(`.key[data-key="${e.keyCode}"]`);

  if (!key) return;

  const keyNote = key.getAttribute("data-note");

  key.classList.add("playing");
  note.innerHTML = keyNote;
  audio.currentTime = 0;
  audio.play();
}
window.addEventListener("keydown", playNote);
function removeTransition(e) {
  if (e.propertyName !== "transform") return;
  this.classList.remove("playing");
}

function hintsOn(e, index) {
  e.setAttribute("style", "transition-delay:" + index * 50 + "ms");
}

hints.forEach(hintsOn);

keys.forEach(key => key.addEventListener("transitionend", removeTransition));

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.