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.

            
              <link href="https://fonts.googleapis.com/css?family=Source+Serif+Pro" rel="stylesheet">

<div class = 'container-flex'>

<h1>Random Quote Generator</h1>  
  
<div id = 'quote'> </div>

<button id = 'submit'>New Quote</button>

</div>
            
          
!
            
              body {
font-family: 'Source Serif Pro', serif;
width: 100vw;
background: linear-gradient(90deg, #dbdfe0, #eef2f3);
}

.container-flex {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 600px;
  height: 350px;
  margin: 0 auto;
  text-align: center;
  padding: 50px 30px 0 30px;
}

#quote {
  font-size: 20px;
}

#submit {
  border: none;
  background-color: #fff;
  font-family: 'Source Serif Pro', serif;
  font-size: 16px;
  cursor: pointer;
  transition: 0.2s all linear;
  height: auto;
  width: auto;
  border-radius: 2px;
  margin-top: 30px;
}

#submit:hover {
  background-color: #282828;
  color: #fff;
}


#submit:focus {
  outline: none;
}

p {
  display: table-cell;
  vertical-align: middle;
  animation: fadeIn 2s 1;
  padding: 0 10px 20px 10px;
  color: #fff;
  background-color: #282828;
  width: 800px;
  height: 100px;
  text-align: center;
  border-radius: 3px;
}

  @keyframes fadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
}
            
          
!
            
              var quotes;
quotes = [ ' "Success is the sum of small efforts, repeated day in and day out." ',
          ' "Everything is created twice, first in the mind, then in reality." ',
          ' "The secret is here in the present. If you pay attention to the present you can improve upon it. And, if you can improve the present, what comes later will also be better." ', 
          ' "Believe you can and you’re halfway there." ', 
          ' "Mistakes are the portals of discovery." ', 
          ' "Great things come from hard work and perseverance. No excuses." ', 
          ' "The pessimist sees difficulty in every opportunity. The optimist sees opportunity in every difficulty." ', 
          ' "Whether you think you can or think you can’t, you’re right." ', 
          ' "You are never too old to set another goal or to dream a new dream." ', 
          ' "Do not wait; the time will never be ‘just right.’ Start where you stand, and work with whatever tools you may have at your command, and better tools will be found as you go along." ', 
         ];

document.getElementById('submit').addEventListener('click', function(){
  
  var randomNum = Math.floor((Math.random() * quotes.length));
  
  var el = document.getElementById('quote');
  el.innerHTML = '<p>' + quotes[randomNum];
  
})


            
          
!
999px
Loading ..................

Console