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

              
                <head>
  <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap" rel="stylesheet">
</head>

<body>
  <div class="amp-story-page">
    <div class="interactive-component">
      <div class="interactive-container">
        <div class="interactive-prompt-container">
          <textarea class="interactive-prompt" rows="2" oninput='this.style.height="0px";this.style.height = (this.scrollHeight-4) + "px"'>Did you like that movie</textarea>
        </div>
        <div class="i-amphtml-story-interactive-binary-poll-option-container">
          <div class="i-amphtml-story-interactive-option i-amphtml-story-interactive-option-selected">
            <span class="i-amphtml-story-interactive-option-percent-bar"></span>
            <span class="i-amphtml-story-interactive-option-text-container">
              <span class="i-amphtml-story-interactive-option-title"><textarea class="i-amphtml-story-interactive-option-title-text" rows="1" oninput='this.style.height="0px";this.style.height = (this.scrollHeight - 4) + "px";updateScale()'>yes</textarea></span>
              <span class="i-amphtml-story-interactive-option-percentage-text">50%</span>
            </span>
          </div><span class="i-amphtml-story-interactive-option-divider"></span>
          <div class="i-amphtml-story-interactive-option">
            <span class="i-amphtml-story-interactive-option-percent-bar"></span>
            <span class="i-amphtml-story-interactive-option-text-container">
              <span class="i-amphtml-story-interactive-option-title"><textarea class="i-amphtml-story-interactive-option-title-text" rows="1" oninput='this.style.height="0px";this.style.height = (this.scrollHeight - 4) + "px";updateScale()'>no</textarea></span>
              <span class="i-amphtml-story-interactive-option-percentage-text">50%</span>
            </span>
          </div>
        </div>
      </div>

      <div class="toggle-options">
        <span><strong>Configure quiz</strong></span>
        <div class="switch">
          <select onchange="toggleDark(this)">
            <option selected="selected">light</option>
            <option>dark</option>
          </select>
          <label>theme</label>
        </div>
        <div class="switch">
          <select onchange="promptChange(this)">
            <option>small</option>
            <option selected="selected">medium</option>
            <option>large</option>
          </select>
          <label>prompt</label>
        </div>
        <div class="switch">
          <input type="color" value="#005af0" onchange="changeColor(this)">
          <label>accent</label>
        </div>
        <div class="switch">
          <input type="checkbox" onclick="toggleAnswered(this)">
          <label>Answered</label>
        </div>
      </div>
    </div>
</body>
              
            
!

CSS

              
                html,
body {
  height: 100%;
}

body {
  background-color: #202125;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Poppins", sans-serif;
  font-size: 16px;
}

.toggle-options {
  background: white;
  width: 150px;
  padding: 16px 16px;
  border-radius: 32px;
  border-bottom-left-radius: 0px;
  position: absolute;
  top: -5px;
  right: 0px;
  transform: translatey(-100%);
  opacity: 0.1;
  transition: opacity 0.2s ease-in-out;
}

.interactive-component:hover .toggle-options {
  opacity: 1;
}

select {
  width: 80px;
  font-family: "Poppins", sans-serif;
}

.amp-story-page {
  width: 500px;
  height: 800px;
  background-color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image: url("https://images.unsplash.com/photo-1595364397663-fca4f075d796?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1234&q=80");
  box-shadow: 0px 5px 10px 0px #00000060;
}

.interactive-component {
  width: 100%; /* Width can be changed for the component, default is 100% */
  /* Properties overrideable by user (view examples) */
  --interactive-accent-color: #005af0;
  --interactive-prompt-background: var(--interactive-accent-color);
  --interactive-prompt-text-color: white;
  --interactive-prompt-alignment: initial;
  /* Shared properties by interactives (do not modify) */
  height: auto;
  min-width: 14em;
  max-width: 18em;
  --i-amphtml-interactive-option-accent-color: var(--interactive-accent-color);
  --i-amphtml-interactive-option-background-color: white;
  --i-amphtml-interactive-option-text-color: #5f6368;
  --i-amphtml-interactive-theme-border: rgba(0, 0, 0, 0.2);
  --i-amphtml-interactive-theme-shading: rgba(95, 99, 104, 0.2);
  --i-amphtml-interactive-chip-radius: 2em;
  --i-amphtml-interactive-chip-shadow: 0px 0px 0px transparent;
  --i-amphtml-interactive-chip-shadow-inset: inset 0px 0px 0px transparent;
  --i-amphtml-interactive-answer-choice-border: var(--interactive-accent-color);
  --i-amphtml-interactive-answer-choice-background: white;
  --i-amphtml-interactive-prompt-text-size: 1.375em;
  --i-amphtml-interactive-prompt-line-height: 1.3em;
  --i-amphtml-interactive-strong-text-color: black;
  --i-amphtml-interactive-component-shadow: 0px 4px 12px rgba(60, 64, 67, 0.08),
    0px 2px 4px rgba(60, 64, 67, 0.12);
  --i-amphtml-interactive-animation-time: 0.3s !important;
  --i-amphtml-interactive-ease-out-curve: cubic-bezier(0.3, 0, 0, 1) !important;
  position: relative;
  --post-select-scale-variable: 1;
}

.interactive-component[theme="dark"] {
  --i-amphtml-interactive-option-text-color: #9aa0a6;
  --i-amphtml-interactive-option-background-color: #202124;
  --i-amphtml-interactive-theme-border: rgba(255, 255, 255, 0.2);
  --i-amphtml-interactive-theme-shading: rgba(154, 160, 166, 0.2);
  --i-amphtml-interactive-theme-shading-flash: rgba(154, 160, 166, 0.4);
  --i-amphtml-interactive-strong-text-color: white;
  --i-amphtml-interactive-option-accent-color: white !important;
}

.interactive-component[chip-style="shadow"] {
  --i-amphtml-interactive-chip-shadow: 0px 2px 8px rgba(60, 60, 60, 0.2);
  --i-amphtml-interactive-chip-shadow-inset: inset 4px 4px 8px
    rgba(0, 0, 0, 0.2);
  --i-amphtml-interactive-theme-border: rgba(0, 0, 0, 0);
}

.interactive-component[chip-style="shadow"][theme="dark"] {
  --i-amphtml-interactive-chip-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.6);
  --i-amphtml-interactive-chip-shadow-inset: inset 4px 4px 8px
    rgba(0, 0, 0, 0.4);
}

.interactive-component[prompt-size="large"] {
  --i-amphtml-interactive-prompt-text-size: 1.75em;
}

.interactive-component[prompt-size="small"] {
  --i-amphtml-interactive-prompt-text-size: 1.125em;
}

.interactive-prompt-container {
  display: flex;
  justify-items: center;
  padding: 1.25em;
}

.interactive-prompt {
  margin: 0px;
  overflow: hidden;
  font-size: var(--i-amphtml-interactive-prompt-text-size);
  line-height: var(--i-amphtml-interactive-prompt-line-height);
  font-weight: bold;
  text-align: var(--interactive-prompt-alignment);
  color: var(--interactive-prompt-text-color);
  font-family: "Poppins", sans-serif;
  background: transparent;
  border: none;
  outline: none;
  width: 100%;
  resize: none;
  max-height: calc(3 * var(--i-amphtml-interactive-prompt-line-height));
  text-align: center;
}

.interactive-container {
  background: var(--interactive-prompt-background);
  border-radius: 2em;
}

.i-amphtml-story-interactive-binary-poll-option-container {
  background: var(--i-amphtml-interactive-option-background-color) !important;
  display: flex !important;
  justify-content: center !important;
  height: 5.625em !important;
  border-radius: 1em !important;
  overflow: hidden !important;
  box-shadow: var(--i-amphtml-interactive-component-shadow) !important;
  /* overflow bug fix for percent bar animation on ios safari  */
  transform: translateZ(0) !important;
  --post-select-scale: 0.5 !important;
}

.i-amphtml-story-interactive-option {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
  flex-direction: column !important;
  width: 50%;
  position: relative !important;
}

.i-amphtml-story-interactive-prompt {
  text-align: center !important;
}

.i-amphtml-story-interactive-option-text-container {
  width: 100% !important;
  display: flex !important;
  align-items: center !important;
  flex-direction: column !important;
  transform: translateY(calc(1em + 1px)) !important;
}

.i-amphtml-story-interactive-post-selection
  .i-amphtml-story-interactive-option-text-container {
  transition: transform var(--i-amphtml-interactive-animation-time)
      var(--i-amphtml-interactive-ease-out-curve),
    opacity var(--i-amphtml-interactive-animation-time)
      var(--i-amphtml-interactive-ease-out-curve) !important;
  transform: translateY(0) !important;
}

.interactive-component:not(.i-amphtml-story-interactive-post-selection)
  .i-amphtml-story-interactive-option-divider {
  height: 100% !important;
  width: 1px !important;
  opacity: 0.3 !important;
  background-color: var(--i-amphtml-interactive-theme-border) !important;
}

.i-amphtml-story-interactive-option
  .i-amphtml-story-interactive-option-percent-bar {
  height: 100% !important;
  width: 100% !important;
  position: absolute !important;
  opacity: 0 !important;
  transform-origin: left !important;
  transition: transform var(--i-amphtml-interactive-animation-time)
    var(--i-amphtml-interactive-ease-out-curve) !important;
}

[dir="rtl"]
  .i-amphtml-story-interactive-option
  .i-amphtml-story-interactive-option-percent-bar {
  transform-origin: right !important;
}

.i-amphtml-story-interactive-option:last-child
  .i-amphtml-story-interactive-option-percent-bar {
  transform-origin: right !important;
}

[dir="rtl"]
  .i-amphtml-story-interactive-option:last-child
  .i-amphtml-story-interactive-option-percent-bar {
  transform-origin: left !important;
}

.i-amphtml-story-interactive-post-selection
  .i-amphtml-story-interactive-option.i-amphtml-story-interactive-option-selected
  .i-amphtml-story-interactive-option-percent-bar {
  background-color: var(--i-amphtml-interactive-option-accent-color) !important;
  opacity: 0.2 !important;
  animation: i-amphtml-interactive-animation-flash-background forwards
    var(--i-amphtml-interactive-animation-time)
    var(--i-amphtml-interactive-ease-out-curve);
}

.i-amphtml-story-interactive-option-title {
  font-weight: 800 !important;
  font-size: 1.75em !important;
  margin: 0 !important;
  width: 4.42em !important;
  height: 1.3em !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: transform var(--i-amphtml-interactive-animation-time)
    var(--i-amphtml-interactive-ease-out-curve) !important;
}

.i-amphtml-story-interactive-post-selection
  .i-amphtml-story-interactive-option-title {
  transform: scale(var(--post-select-scale)) !important;
}

.i-amphtml-story-interactive-option-title-text {
  font-size: 1em;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  display: -webkit-box !important;
  -webkit-line-clamp: 2 !important;
  -webkit-box-orient: vertical !important;
  transition: transform var(--i-amphtml-interactive-animation-time)
    var(--i-amphtml-interactive-ease-out-curve) !important;
  line-height: 1.3em !important;
  border: none;
  text-align: center;
  resize: none;
  font-family: "Poppins";
  font-weight: 700;
  background: transparent;
  color: var(--i-amphtml-interactive-strong-text-color);
}

.i-amphtml-story-interactive-post-selection
  .i-amphtml-story-interactive-option-title-text {
  transform: scale(var(--post-select-scale-variable)) !important;
}

.i-amphtml-story-interactive-option-percentage-text {
  font-weight: 700 !important;
  font-size: 1.375em !important;
  transform: scale(0) !important;
  display: inline-block !important;
  transition: transform var(--i-amphtml-interactive-animation-time)
    var(--i-amphtml-interactive-ease-out-curve) !important;
  color: var(--i-amphtml-interactive-strong-text-color);
}

.i-amphtml-story-interactive-post-selection
  .i-amphtml-story-interactive-option-percentage-text {
  transform: scale(1) !important;
}

.interactive-component:not(.i-amphtml-story-interactive-post-selection)
  .i-amphtml-story-interactive-option:before {
  background-color: var(--i-amphtml-interactive-theme-shading-flash) !important;
  content: "" !important;
  position: absolute !important;
  width: 100% !important;
  height: 100% !important;
  left: 0 !important;
  opacity: 0 !important;
  animation: i-amphtml-interactive-animation-landing-animation-flash-background
    var(--i-amphtml-interactive-animation-time) !important;
  animation-delay: var(
    --i-amphtml-interactive-landing-animation-delay-offset-el1
  ) !important;
}

.i-amphtml-story-interactive-active:not(.i-amphtml-story-interactive-post-selection)
  .i-amphtml-story-interactive-option:nth-of-type(2):before {
  animation-delay: var(
    --i-amphtml-interactive-landing-animation-delay-offset-el2
  ) !important;
}

.i-amphtml-story-interactive-active:not(.i-amphtml-story-interactive-post-selection)
  .i-amphtml-story-interactive-option
  .i-amphtml-story-interactive-option-title-text {
  animation: i-amphtml-story-interactive-option-title-text-landing-animation
    var(--i-amphtml-interactive-animation-time) !important;
  animation-delay: var(
    --i-amphtml-interactive-landing-animation-delay-offset-el1
  ) !important;
}

.i-amphtml-story-interactive-active:not(.i-amphtml-story-interactive-post-selection)
  .i-amphtml-story-interactive-option:nth-of-type(2)
  .i-amphtml-story-interactive-option-title-text {
  animation-delay: var(
    --i-amphtml-interactive-landing-animation-delay-offset-el2
  ) !important;
}

@keyframes i-amphtml-story-interactive-option-title-text-landing-animation {
  33% {
    transform: scale(0.95);
  }
}

              
            
!

JS

              
                var quiz = document.getElementsByClassName("interactive-component")[0];

var prompt = document.getElementsByClassName("interactive-prompt")[0];

function toggleDark(select) {
  quiz.setAttribute("theme", select.value);
}

function toggleShadow(select) {
  quiz.setAttribute("chip-style", select.value);
}

function toggleAnswered(checkbox) {
  quiz.classList.toggle(
    "i-amphtml-story-interactive-post-selection",
    checkbox.checked
  );
}

function promptChange(select) {
  quiz.setAttribute("prompt-size", select.value);
  prompt.style.height = "0px";
  prompt.style.height = prompt.scrollHeight - 4 + "px";
}

function changeColor(picker) {
  var color = picker.value;
  quiz.style = "--interactive-accent-color: " + color;
}

function updateScale() {
  var largestFontSize = 28;
  const allTitles = Array.from(
    document.getElementsByClassName(
      "i-amphtml-story-interactive-option-title-text"
    )
  );
  allTitles.forEach((e) => {
    const lines = Math.round(
      e.offsetHeight /
        parseFloat(window.getComputedStyle(e)["line-height"].replace("px", ""))
    );
    console.log(e.textContent, e.textContent.length, lines, largestFontSize);
    if (e.value.length <= 3 && largestFontSize >= 28) {
      largestFontSize = 28;
    } else if (lines == 1 && largestFontSize >= 16) {
      largestFontSize = 16;
    } else if (lines == 2) {
      largestFontSize = 14;
    }
  });
  quiz.style.setProperty("--post-select-scale-variable", largestFontSize / 14);
}

updateScale();

              
            
!
999px

Console