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="i-amphtml-story-interactive-component">
      <div class="i-amphtml-story-interactive-container">
        <div class="i-amphtml-story-interactive-prompt-container">
          <textarea class="i-amphtml-story-interactive-prompt" rows="2" oninput='this.style.height="0px";this.style.height = (this.scrollHeight-4) + "px"'>What animal do you like the most?</textarea>
        </div>
        <div class="i-amphtml-story-interactive-option-container"><span class="i-amphtml-story-interactive-option" style="--option-percentage:32%">
            <textarea class="i-amphtml-story-interactive-option-text" rows="1" oninput='updateScale(this)'>Cats are the best</textarea>
            <span class="i-amphtml-story-interactive-option-percentage">
              <span class="i-amphtml-story-interactive-option-percentage-text">32</span>
              <span class="i-amphtml-story-interactive-option-percentage-sign">%</span>
            </span>
          </span><span class="i-amphtml-story-interactive-option" style="--option-percentage:45%">
            <textarea class="i-amphtml-story-interactive-option-text" rows="1" oninput='updateScale(this)'>Dogs are so cute</textarea>
            <span class="i-amphtml-story-interactive-option-percentage">
              <span class="i-amphtml-story-interactive-option-percentage-text">45</span>
              <span class="i-amphtml-story-interactive-option-percentage-sign">%</span>
            </span>
          </span><span class="i-amphtml-story-interactive-option" style="--option-percentage:10%">
            <textarea class="i-amphtml-story-interactive-option-text" rows="1" oninput='updateScale(this)'>Fish are so convenient</textarea>
            <span class="i-amphtml-story-interactive-option-percentage">
              <span class="i-amphtml-story-interactive-option-percentage-text">10</span>
              <span class="i-amphtml-story-interactive-option-percentage-sign">%</span>
            </span>
          </span><span class="i-amphtml-story-interactive-option" style="--option-percentage:23%">
            <textarea class="i-amphtml-story-interactive-option-text" rows="1" oninput='updateScale(this)'>Elephants are awesome</textarea>
            <span class="i-amphtml-story-interactive-option-percentage">
              <span class="i-amphtml-story-interactive-option-percentage-text">23</span>
              <span class="i-amphtml-story-interactive-option-percentage-sign">%</span>
            </span>
          </span></div>
      </div>
      <div class="toggle-options">
        <span><strong>Configure poll</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="toggleShadow(this)">
            <option selected="selected">flat</option>
            <option>shadow</option>
          </select>
          <label>style</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;
}

.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;
}

.i-amphtml-story-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-1516139008210-96e45dccd83b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1700&q=80");
  box-shadow: 0px 5px 10px 0px #00000060;
  background-size: cover;
  background-position: center;
}

.i-amphtml-story-interactive-component {
  width: 400px; /* Width can be changed for the component, default is auto */
  /* 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: 14ems;
  max-width: 25em;
  --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);
  position: relative;
}

.i-amphtml-story-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-story-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);
}

.i-amphtml-story-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);
}

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

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

amp-story-interactive-binary-poll[theme="dark"],
amp-story-interactive-poll[theme="dark"] {
  --i-amphtml-interactive-option-accent-color: white;
}

.i-amphtml-story-interactive-container {
  font-family: "Poppins", sans-serif !important;
}

.i-amphtml-story-interactive-container {
  background: var(--interactive-prompt-background) !important;
  border-radius: 2em !important;
}

.i-amphtml-story-interactive-prompt-container {
  display: flex !important;
  justify-items: center !important;
  padding: 1.25em !important;
  color: var(--interactive-prompt-text-color) !important;
}

.i-amphtml-story-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));
}

.i-amphtml-story-interactive-option-container {
  background-color: var(--i-amphtml-interactive-option-background-color);
  border-radius: 1em;
  color: var(--i-amphtml-interactive-strong-text-color);
  font-weight: bold;
  padding: 0.5em;
}

.i-amphtml-story-interactive-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 3.5em;
  overflow: hidden;
  padding: 0px 0.75em;
  position: relative;
  box-shadow: var(--i-amphtml-interactive-chip-shadow),
    inset 0px 0px 0px 1px var(--i-amphtml-interactive-theme-border);
  -webkit-box-shadow: var(--i-amphtml-interactive-chip-shadow),
    inset 0px 0px 0px 1px var(--i-amphtml-interactive-theme-border);
  -moz-box-shadow: var(--i-amphtml-interactive-chip-shadow),
    inset 0px 0px 0px 1px var(--i-amphtml-interactive-theme-border);
  border-radius: 8px;
}

.i-amphtml-story-interactive-option:not(:first-child) {
  margin-top: 0.5em;
}

.i-amphtml-story-interactive-option.i-amphtml-story-interactive-option-selected {
  background-color: var(--i-amphtml-interactive-theme-shading);
  box-shadow: var(--i-amphtml-interactive-chip-shadow-inset),
    inset 0px 0px 0px 1px var(--i-amphtml-interactive-theme-border);
  -webkit-box-shadow: var(--i-amphtml-interactive-chip-shadow-inset),
    inset 0px 0px 0px 1px var(--i-amphtml-interactive-theme-border);
  -moz-box-shadow: var(--i-amphtml-interactive-chip-shadow-inset),
    inset 0px 0px 0px 1px var(--i-amphtml-interactive-theme-border);
  animation: i-amphtml-interactive-animation-flash-background-color forwards
    var(--i-amphtml-interactive-animation-time)
    var(--i-amphtml-interactive-ease-out-curve);
}

.i-amphtml-story-interactive-option::after {
  content: "";
  background-color: var(--i-amphtml-interactive-theme-shading);
  position: absolute;
  height: 100%;
  width: 100%;
  left: 0;
  top: 0;
  transform: translateX(-100%);
  transition: transform 0.3s ease-out;
}

.i-amphtml-story-interactive-poll-container[dir="rtl"]
  .i-amphtml-story-interactive-option::after {
  transform: translateX(100%);
}

.i-amphtml-story-interactive-post-selection
  .i-amphtml-story-interactive-option::after {
  transform: translateX(calc(var(--option-percentage) - 100%));
}

.i-amphtml-story-interactive-poll-container.i-amphtml-story-interactive-post-selection[dir="rtl"]
  .i-amphtml-story-interactive-option::after {
  transform: translateX(calc(100% - var(--option-percentage)));
}

.i-amphtml-story-interactive-option-text {
  font-family: "Poppins", sans-serif;
  border: none;
  width: 100%;
  padding: 0px;
  color: inherit;
  resize: none;
  background: transparent;
  font-size: 1.375em;
  line-height: 1.3em;
  max-height: 2.6em;
  margin: 0;
  z-index: 1;
  transition: transform 0.3s ease-out;
  transform-origin: left;
  font-weight: bold;
}

.i-amphtml-story-interactive-poll-container[dir="rtl"]
  .i-amphtml-story-interactive-option-text {
  transform-origin: right;
}

.i-amphtml-story-interactive-post-selection
  .i-amphtml-story-interactive-option-text {
  transform: scale(0.72);
}

.i-amphtml-story-interactive-poll-two-lines
  .i-amphtml-story-interactive-option-text {
  font-size: 1.125em;
}

.i-amphtml-story-interactive-option-percentage {
  font-weight: 700;
  font-size: 1.75em;
  margin: 0;
  opacity: 0;
  transition: transform 0.3s ease-out;
  transform: translateX(2em);
  /* Percentage sign always goes to the right of the number, regardless of language. TODO(mszylkowski): rtl for arabic */
  direction: ltr;
  display: inherit;
  place-items: baseline;
}

.i-amphtml-story-interactive-poll-container[dir="rtl"]
  .i-amphtml-story-interactive-option-percentage {
  transform: translateX(-2em);
}

.i-amphtml-story-interactive-component.i-amphtml-story-interactive-post-selection[dir="rtl"]
  .i-amphtml-story-interactive-option-percentage,
.i-amphtml-story-interactive-component.i-amphtml-story-interactive-post-selection:not([dir="rtl"])
  .i-amphtml-story-interactive-option-percentage {
  opacity: 1;
  transform: translateX(0px);
}

.i-amphtml-story-interactive-option-percentage-sign {
  font-size: 0.6em;
  display: inline-block;
}

              
            
!

JS

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

var prompt = document.getElementsByClassName(
  "i-amphtml-story-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(element) {
  var hasTwoLines = false;
  quiz.classList.toggle(
    "i-amphtml-story-interactive-poll-two-lines",
    hasTwoLines
  );
  const allTitles = Array.from(
    document.getElementsByClassName("i-amphtml-story-interactive-option-text")
  );
  allTitles.forEach((e) => {
    const lines = Math.round(
      e.scrollHeight /
        parseFloat(window.getComputedStyle(e)["line-height"].replace("px", ""))
    );
    if (lines >= 2) {
      hasTwoLines = true;
    }
  });
  quiz.classList.toggle(
    "i-amphtml-story-interactive-poll-two-lines",
    hasTwoLines
  );
  allTitles.forEach((title) => {
    title.style.height = "0px";
    title.style.height = title.scrollHeight + "px";
  });
}

updateScale();

              
            
!
999px

Console