Pen Settings



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


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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


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.


                <div class="joke">
  <blockquote data-container="joke"></blockquote>
<button class="cta" data-container="cta" name="cta"></button>
<p class="answer" data-container="answer"></p>
<a href="" class="permalink" data-container="permalink">Permalink</a>
<div data-container="reset-joke" class="reset-joke">
  <p>Do you want another one?</p>
  <button class="reset" data-container="reset" name="reset"></button>


                $color-primary: #B06AB3;
$color-secondary: #4568DC;
$color-default: #ffffff;
$color-dark: #333333;

*, *:before, *:after {
  box-sizing: border-box;

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: 'DM Sans', sans-serif;
  font-size: 125%;
  letter-spacing: 1px;
  line-height: 1.5;
  background: #4568DC;
  background: linear-gradient(to right, #B06AB3, #4568DC);
  color: $color-dark;

.joke, .reset-joke {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: stretch;
  padding: 3rem;
  border: 1px solid $color-default;
  width: 80%;
  box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
  background-color: $color-default;
  position: relative;
  z-index: 10;
  min-height: 50vh;

.joke > *:not(:last-child) {
  margin-bottom: 3rem;

blockquote {
  font-size: 200%;
  font-weight: bold;
  text-align: center;

p.answer {
  opacity: 0;
  transform: scale(0);
  transition: all .3s ease;
} {
  opacity: 1;
  transform: scale(1);

button {
  font-size: 100%;
  background-color: $color-primary;
  color: #ffffff;
  border: 2px solid $color-default;
  border-radius: 100px;
  padding: 15px 30px;
  font-size: 80%;
  text-transform: uppercase;
  font-weight: bold;
  letter-spacing: 2px;
  transition: all .2s ease;

button:hover {
  cursor: pointer;
  background-color: darken($color-primary, 10%);

button:focus {
  outline: none;

a {
  display: inline-block;
  font-size: 11px;
  text-decoration: none;
  color: $color-dark;
  position: relative;

a:after {
  content: '';
  width: 100%;
  height: 1px;
  position: absolute;
  bottom: -3px;
  left: 0;
  background-color: $color-dark;
  opacity: 0;
  transform: translate(-1rem, 0);
  transition: all .3s ease;

a:hover:after {
  opacity: 1;
  transform: translate(0);

.reset-joke {
  margin-top: 1rem;
  flex-direction: row;
  opacity: 0;
  pointer-events: none;
  transform: translate(0, -50%);
  transition: all .3s ease;
  z-index: 1;
  min-height: auto;
  padding: 1rem 3rem;
} {
  opacity: 1;
  pointer-events: auto;
  transform: translate(0);

.reset-joke button {
  margin-left: auto;
  font-size: 70%;
  padding: 0.5rem 1rem;
  font-weight: normal;


                const CTA = ['Geez, dad...', 'I don\' t know...', 'Please, stop', 'Quit it', 'Just stop it already', '*sigh*', 'Dad, don\'t']
const RESET = ['Okay, gimme one more', 'This is the last', 'Please, no', 'Stop', 'Nope nope nope']

const CONTAINERS = {
  joke: document.querySelector('[data-container="joke"]'),
  cta: document.querySelector('[data-container="cta"]'),
  answer: document.querySelector('[data-container="answer"]'),
  permalink: document.querySelector('[data-container="permalink"]'),
  resetJoke: document.querySelector('[data-container="reset-joke"]'),
  reset: document.querySelector('[data-container="reset"]')

let answer = ''

document.body.addEventListener('click', click)
CONTAINERS.resetJoke.addEventListener('transitionend', transitionend)

getData().then(data => init(data))

function getData() {
  const query = (`
    query { 
      joke {
  return fetch(`${ query }`)
    .then(response => response.json())
    .then(data =>

function init(data) {
  const joke = data.joke.split('?')
  answer = ''
  // only allow jokes as questions
  if (!joke[1] || joke[1].length < 3) {
    getData().then(data => init(data))
  // fill containers
  CONTAINERS.joke.innerHTML = joke[0] + '?'
  CONTAINERS.permalink.href = data.permalink
  CONTAINERS.cta.innerHTML = CTA.random()
  CONTAINERS.answer.innerHTML = joke[1]
  CONTAINERS.reset.innerHTML = RESET.random()

function click(e) {
  switch( {
    case 'cta':
    case 'reset':

function transitionend(e) {
  let condition = (!CONTAINERS.answer.classList.contains('show'))
  condition &= ( === 'reset-joke')
  condition &= (e.propertyName === 'transform')
  if (!condition) return
  getData().then(data => init(data))

Array.prototype.random = function() {
  return this[Math.floor(Math.random() * this.length)]