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

              
                <h1>Random Ron</h1>

<p>
  <img src="https://www.incimages.com/uploaded_files/image/1920x1080/parks-and-recreation_32716.jpg" alt="Ron Swanson, from the American sitcom 'Parks and Recreation', portrayed by Nick Offerman.">
</p>

<blockquote>
  <p id="quote" aria-live="polite">One moment while I find a quote...</p>
</blockquote>

<p>
  <button id="new-quote" type="button">More Ron</button>
</p>
              
            
!

CSS

              
                body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 30rem;
  padding: 1rem;
  margin: 0 auto;
  font-family: Georgia, serif;
  color: #222;
}

body > * + * {
  margin-top: 1rem;
}

h1 {
  color: #444;
}

h1::before {
  content: '💬 ';
}

blockquote {
  font-size: 1.5rem;
}

blockquote p::before {
  content: open-quote;
}

blockquote p::after {
  content: close-quote;
}

button {
  font-size: 1.25rem;
  font-family: Arial, sans-serif;
}

              
            
!

JS

              
                //
// Variables
//

// Get the placeholder for the quote
const quote = document.querySelector('#quote');

// Get the button for fetching new quotes
const button = document.querySelector('#new-quote');

// Store the API endpoint
const endpoint = 'https://ron-swanson-quotes.herokuapp.com/v2/quotes';


//
// Functions
//

/**
 * Get the JSON data from a Fetch request
 * @param {Response} response The Response object
 * @returns {Promise} The JSON data or the rejected response
 */
function getJSON (response) {
  return response.ok ? response.json() : Promise.reject(response);
}

/**
 * Add a quote to the DOM
 * @param {String[]} quotes An array of quotes
 */
function showQuote (quotes) {
  quote.textContent = quotes[0];
}

/**
 * Add an error message to the DOM
 */
function showError () {
  quote.textContent = 'I tried to find a quote, but something went wrong. Come back later, and be ready. Because I am. I was born ready. I\'m Ron F*cking Swanson.';
}

/**
 * Fetch a quote and add it to the DOM
 */
function fetchQuote () {
  fetch(endpoint)
    .then(getJSON)
    .then(showQuote)
    .catch(showError);
}


//
// Inits & Event Listeners
//

// Show a quote when the page loads
fetchQuote();

// Show a new quote when the button is clicked
button.addEventListener('click', fetchQuote);

              
            
!
999px

Console