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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>

    <div class="wrapper">
      <header>Random Quote Machine</header>
      <div id="quote-box">
        <div id="content" class="content">
        <div id="quote-area" class="quote-area">
          <i class="fas fa-quote-left"></i>
          <p class="text" id="text">Yesterday I was clever, so I wanted to change the world. Today I am wise, so I am changing myself.</p>
          <i class="fas fa-quote-right"></i>
        </div>
        <div id="author" class="author">
          <span></span>
          <span id="name" class="name">- Rumi</span>
        </div>
        </div>
      <div class="buttons" id="quote-buttons">
        <div class="features">
          <ul>
           <li> <a id="speech-btn" class="speech fa-gradient"><i class="fas fa-volume-up"></i></a></li>
            <li><a class="copy fa-gradient copy-text"><i class="fas fa-copy "></i></a></li>
            <li><a class="twitter fa-gradient" id="tweet-quote" title="Tweet this quote!" target="_top" href="twitter.com/intent/tweet"><i class="fab fa-twitter"></i></a></li>
          </ul>
          <button id="new-quote" class="new-buttons" >New Quote</button>
        </div>
      </div>
        </div>
    </div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"></script>

    
              
            
!

CSS

              
                /* Import Google Font - Akshar */
@import url('https://fonts.googleapis.com/css2?family=Akshar:wght@300&display=swap');
:root{
  --color-body:linear-gradient(45deg, pink, skyblue);
}
*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Akshar', sans-serif;
  font-weight:500;
}
body{
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--color-body);
}
/*whole quote box*/
.wrapper{
  width: 605px;
  background: #fff;
  border-radius: 0.938rem;/*15px*/
  padding: 30px 30px 25px;
/*   box-shadow: 0 12px 35px rgba(0,0,0,0.1); */
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15), 0 6px 6px rgba(0, 0, 0, 0.23);
}
/*wrapper header */
.wrapper header{
  font-size: 2.188rem;/*35px */
  font-weight: 700;
  text-align: center;
}
/*wrapper content above border line*/
.wrapper .content{
  margin: 2.188rem 0;/*35px 0 */
}
.content .quote-area{
  display: flex;
  justify-content: center;
}
.quote-area i{
  font-size: 0.938rem;/*15px*/
}
.quote-area i:first-child{
  margin: 0.188rem 0.625rem 0 0; /*3px 10px 0 0 */
}
.quote-area i:last-child{
  display: flex;
  margin:0 0 0.188rem 0.625rem;
  /*3px 10px 0 0 */
  align-items: flex-end;
}
/*.text*/
.text{
  font-size: 1.563rem;/*25px*/
  text-align: center;
} 
/*#author*/
#author{
  display: flex;
  font-size: 1.25rem;/*20px*/
  margin-top: 20px;
  font-style: italic;
  justify-content: flex-end;
}
/*#author span:first-child*/
#author span:second-child{
  margin: --0.438rem 0.313rem 0 0; /* -7px 5px 0 0 */
  font-family: monospace;
}
/* #quote-buttons*/
#quote-buttons{
  border-top: 1px solid #ccc;
}

/*buttons below the border line*/

/*font-icons*/
.buttons .features{
  display: flex;
  margin-top: 1.25rem;/*20px*/
  align-items: center;
  justify-content: space-between;
}
.features ul{
  display: flex;
}
.features ul li{
  margin: 0 0.313rem;/*0 5px*/
  height: 2.938rem;/*47px*/
  width: 2.938rem;/*47px*/
  display: flex;
  cursor: pointer;
  list-style: none;
  align-items: center;
  justify-content: center;
  border: 3px solid #D4C5D6;
  border-radius:50%;
/*   transition: all 0.3s ease; */
/*   font-size:18px; */
}

.features ul li:first-child{
  margin-left: 0;
}

.fa-gradient{
  background:-webkit-linear-gradient(45deg, pink, skyblue);
	-webkit-background-clip: text;
	-webkit-text-fill-color: transparent;
}
.fa-gradient :hover{
  font-size:1.438rem;/*23px;*/
    text-shadow: 2px 2px 8px #ccc;
}

 ul li:is(:hover, .active){
  background: -webkit-linear-gradient(45deg, pink, skyblue);
	-webkit-background-clip: text;
	-webkit-text-fill-color: transparent;
}
ul .speech.active{
  pointer-events: none;
}

/*copy button css*/
/*.copy-text:before{
 content: "Copied";
 position:absolute;
  top: -45px;
  right:0px;
 background:#000000;
 padding:8px 10px;
 border-radius:20px;
  font-size:15px;
  color:blue;
  display:block;
}

.copy-text:after {
 content:"";
 position:absolute;
  top:-20px;
  right:25px;
 width:10px; I
 height:10px;
 background:#5c81dc;
  transform:rotate(45deg);
  display:;
}
.copy-text.active: before,
.copy-text.active:after {
 display:block;
} */

/*new quote button*/
.buttons button{
  border: none;
  color: #fff;
  outline: none;
  font-size: 1.1rem;
  font-weight:600;
  cursor: pointer;
  padding: 13px 22px;
   border-radius:1.875rem;/*30px*/ 
  background: var(--color-body);
   transition:all 0.3s;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15), 0 6px 6px rgba(0, 0, 0, 0.23); 
}
.buttons button:hover{
  transform:translateY(0.3rem);
  box-shadow: 0 2px 15px rgba(0, 0, 0, 0.15), 0 6px 6px rgba(0, 0, 0, 0.23);
}

 .buttons button.loading{
  opacity: 0.7;
  pointer-events: none; 
} 
 




              
            
!

JS

              
                const api="https://api.quotable.io/random";

const quoteText = document.getElementById("text");
const quoteAuthor = document.getElementById("name")
const button = document.getElementById("new-quote");
const tweetQuote =document.getElementById("tweet-quote");
const speechBtn=document.getElementById("speech-btn");
const copyBtn = document.querySelector(".copy");
const synth = speechSynthesis;


//function for new quote
function getQuote(){
  button.classList.add("loading");
    button.innerHTML = "Loading Quote...";
 fetch(api).then((res) => res.json())
    .then((data) => {
      quoteText.innerHTML = `"${data.content}"`;
      quoteAuthor.innerHTML = `- ${data.author}`;
      console.log(data);
 button.classList.remove("loading");
    button.innerHTML = "New Quote";
    }).catch(function(){
    console.log("The request generated an error.")
  });
}


//function for tweeting quote
//   function tweetQuoteText(){
//   $('#tweet-quote').attr(
//     'href',
//     'http://twitter.com/intent/tweet?text=' +
//       encodeURIComponent('"' + `${quoteText.innerHTML}` + '" ' + `${quoteAuthor.innerHTML}`),
//   );
//  }


function tweetQuoteText(){
 let tweet = encodeURI(`http://twitter.com/intent/tweet?text=${quoteText.innerHTML}-${quoteAuthor.innerHTML}`);
 window.open(tweet,'_blank');
}


//function for speech button
speechBtn.addEventListener("click", ()=>{
    if(!button.classList.contains("loading")){
        let utterance = new SpeechSynthesisUtterance(`${quoteText.innerHTML} by ${quoteAuthor.innerHTML}`);
       synth.speak(utterance);
         setInterval(()=>{
           return !synth.speaking ? speechBtn.classList.remove("active") : speechBtn.classList.add("active");
        }, 10);
    }
});


//function to copy text to clipboard
copyBtn.addEventListener("click", ()=>{
    navigator.clipboard.writeText(quoteText.innerHTML);
});

button.addEventListener("click", getQuote);
tweetQuote.addEventListener("click",tweetQuoteText);
              
            
!
999px

Console