Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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.


Auto Save

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.


                <button id="button" type='button'>Get Joke</button>
<p id="setup"></p>
<p id="punchline"></p>
<p id="error"></p>


                :root {
  --yellow: #f6e767;
  --white: #f6f7f8;
  --black: #2c2e31;

* {
  box-sizing: border-box;
body {
  display: flex;
  flex-flow: column nowrap;
  align-items: center;
  padding: 2rem;
  place-content: center;
  min-height: 100vh;
  background-color: var(--black);
  color: var(--white);
  text-align: center;
  font-size: 1.25rem;
  font-family: Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans",
    "Gill Sans MT", "Myriad Pro", Myriad, "DejaVu Sans Condensed",
    "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, "Helvetica Neue",
    Helvetica, Arial, sans-serif;

p {
  margin: 2rem 0 0;

#button {
  background: var(--yellow);
  color: var(--black);
  padding: 1rem 2rem;
  font-weight: 300;
  text-transform: uppercase;
  border: none;
  border-radius: 4px;
  transition: 0.1s ease transform;
  cursor: pointer;

#button:active {
  transform: translatey(3px);

#punchline {
  font-weight: 600;
  font-size: 1.5rem;

#error {
  color: #ff4d51;



                document.addEventListener("click", function (event) {
  // Checking if the button was clicked
  if (!"#button")) return;

  Here we send a request to the Joke API
  Then process the response into JSON
  Then pass the data to our renderJoke function.
    .then((response) => response.json())
    .then((data) => renderJoke(data))
    .catch(() => renderError());

function renderJoke(data) {
  // Get text elements
  const setup = document.getElementById("setup");
  const punchline = document.getElementById("punchline");
  const error = document.getElementById("error");

  // Hide error and render jokes
  error.innerHTML = "";
  setup.innerHTML = data.setup;
  punchline.innerHTML = data.punchline;

function renderError() {
  const error = document.getElementById("error");
  error.innerHTML = "Whoops, something went wrong. Please try again later!";