Developers

Embed

Put polls and forms on your own site in an iframe, sized to fit and with returning voters recognized.

Overview

Every published poll or form can sit on another website in an <iframe>. The frame loads the poll’s own page with embed in the link, and a small script, embed.js, fits the frame to the poll. Embedding is free on every plan, with unlimited responses.

  • Frame: https://strawpoll.com/r/{slug}?embed=1
  • Script: https://strawpoll.com/embed.js, about 2 KB, once per page
  • From the API: the link in urls.formUrl of a form, or urls.voteUrl of a poll

Only published polls can be embedded. A poll’s Share tab, under Embed, writes the code below for you with a live preview. For step-by-step help with WordPress, Wix, Webflow and other builders, see Embed a poll on your website.

Embed code

Inline

The poll sits in your page like a block of content, and grows and shrinks as people answer:

html
<iframe
	src="https://strawpoll.com/r/w8Jq3KdN?embed=1"
	title="Where should we go for lunch?"
	width="100%"
	height="640"
	style="border:0;max-width:100%;border-radius:8px"
	loading="lazy"
	allow="clipboard-write"
></iframe>
<script src="https://strawpoll.com/embed.js" async></script>
  • height is only where the frame starts. embed.js sets it to the poll’s height once the poll has loaded.
  • data-strawpoll-fixed on the <iframe> keeps the height you give it. Longer polls then scroll inside the frame.
  • title names the frame for screen readers. Use the poll’s question.
  • allow="clipboard-write" lets the poll’s own copy buttons work inside the frame.

Full page

The poll fills the window, for a page of its own like yoursite.com/vote:

html
<iframe
	src="https://strawpoll.com/r/w8Jq3KdN?embed=full"
	title="Where should we go for lunch?"
	style="position:fixed;inset:0;width:100%;height:100%;border:0"
	allow="clipboard-write"
	data-strawpoll-fixed
></iframe>
<script src="https://strawpoll.com/embed.js" async></script>

embed=full lays the poll out for the whole window, and comments show only in this mode. data-strawpoll-fixed keeps the frame at the size its style gives it.

A popup is an inline frame inside a dialog of your own. With the native <dialog> element:

html
<button type="button" onclick="document.getElementById('poll').showModal()">Vote now</button>
<dialog
	id="poll"
	style="width:min(640px,100%);max-height:90vh;padding:0;border:0;border-radius:8px"
>
	<iframe
		src="https://strawpoll.com/r/w8Jq3KdN?embed=1"
		title="Where should we go for lunch?"
		height="600"
		style="display:block;width:100%;border:0"
		loading="lazy"
		allow="clipboard-write"
	></iframe>
</dialog>
<script>
	const poll = document.getElementById('poll');
	poll.addEventListener('click', (event) => event.target === poll && poll.close());
</script>
<script src="https://strawpoll.com/embed.js" async></script>

embed.js sizes the frame to the poll, and the dialog scrolls once that is taller than the window. Esc or a click outside the poll closes it.

URL parameters

Add these to the frame’s src:

ParameterValue
embed1 for an inline or popup frame, full for a full page frame.
codeThe visitor’s unique code, see below.
Question keysAn answer filled in ahead, like email=alex%40example.com, see below.
Hidden fieldsValues saved with each response without asking, like utm_source=blog.

Prefill answers

What your site already knows about a visitor can go in the frame’s link, so they don’t type it again: their voting code, their name and email from your login, or a choice they made elsewhere on your site. Prefilled questions still show, and visitors can change the answer before they submit. Build the link with URLSearchParams, which encodes the values for you.

Unique codes

Unique codes are the surest way to give each member of your site exactly one vote, without asking them to sign up at StrawPoll. Each code allows one response, and with the code in the link, members skip the code screen and vote right away.

  1. Set the poll’s duplicate check to unique codes: "responseDuplicateCheck": "code" in its properties, or Unique code in the poll’s settings.
  2. Generate one code per member with POST/forms/{slug}/codes, giving count and length, or under Share → Unique codes in the poll.
  3. Store each code with a member in your own database.
  4. Put the signed-in member’s code in the frame:
js
const src = new URL('https://strawpoll.com/r/w8Jq3KdN');
src.searchParams.set('embed', '1');
src.searchParams.set('code', member.votingCode);
// <iframe src="${src}" …></iframe>

Codes aren’t case-sensitive. A wrong or used code shows the code screen with an error, so the member can type another one. GET/forms/{slug}/codes tells you for each code whether it was used (responded), so you can show who still has to vote.

Only render a member’s code on pages that member sees: anyone who reads it can vote with it.

Names and emails

Name and email questions, and each field of a contact info question, take their answer as text. Their parameter is the field’s key, made from its title when the poll is first published: “Your email” becomes your_email. You find the key in the editor under Prefill label in the question’s settings, and can rename it there.

For a form you create with the API, choose the key yourself in each field’s reference, like "reference": "email". Then fill in the signed-in member:

js
src.searchParams.set('name', member.name);
src.searchParams.set('email', member.email);

code and embed are taken, so a field can’t use them as its key.

Other questions

Question typeValue
Multiple choice, Picture choiceThe option’s label. Separate several with commas.
Short text, Long text, Word cloudThe text.
NumberThe number, like 42.
DateThe day as YYYY-MM-DD, like 2026-12-24.

Options that don’t exist and empty values are ignored. Rankings, ratings, matrices and meeting polls can’t be prefilled. See Prefill answers from the link for all the rules.

Hidden fields

To save a value with each response without asking for it, like the page a visitor came from or your own customer id, add a Hidden fields block to the poll in the editor and list the parameters to keep, like utm_source, customer_id. Visitors don’t see them. Their values show as columns in the responses and the CSV export.

What embed.js does

The script loads after your page and listens for messages from StrawPoll frames. It works for frames added later too, so single-page apps can load it once.

  1. It fits frames to their polls. Each poll reports its height as it changes, and the script sets that height on its <iframe>, unless the frame has data-strawpoll-fixed.
  2. It recognizes returning voters. Many browsers block StrawPoll’s cookie inside frames on other sites. The script keeps a random id in your site’s own localStorage, under strawpoll:voter, and hands it to every poll on the page. The id says nothing about the visitor and only serves the poll’s duplicate check.

Load embed.js from the same host as the frame: it only accepts messages from its own origin. For a poll on a custom domain, that is the custom domain.

Without the script, the poll still works. The frame keeps the height in its code, and in browsers that block the cookie, like Safari and Firefox, every visit looks like a new voter to the browser check. Use the IP address, unique codes or emails as the duplicate check then.

Messages

Instead of embed.js, your own code can talk to the frame with postMessage. Each message is an object with a type:

MessageDirectionWhen
{ type: 'strawpoll:resize', height }Frame to pageWhenever the poll’s height changes, in CSS pixels.
{ type: 'strawpoll:voter-request' }Frame to pageRight after the frame loads, up to five times, until it gets an answer.
{ type: 'strawpoll:voter', token }Page to frameYour answer: a UUID that stays the same for this visitor.

The frame keeps the first token it gets, and only from the window that frames it. Frames send their messages to any origin, so they carry nothing private, but check event.origin on your side:

js
const ORIGIN = 'https://strawpoll.com';

addEventListener('message', (event) => {
	if (event.origin !== ORIGIN) return;
	const frame = [...document.querySelectorAll('iframe')].find(
		(iframe) => iframe.contentWindow === event.source
	);
	if (!frame) return;
	if (event.data?.type === 'strawpoll:resize') {
		frame.style.height = `${Math.ceil(event.data.height)}px`;
	}
	if (event.data?.type === 'strawpoll:voter-request') {
		frame.contentWindow.postMessage({ type: 'strawpoll:voter', token: visitorId() }, ORIGIN);
	}
});

visitorId() stands for your own id for the visitor, such as one kept in localStorage.

Create and embed from your code

A poll made with the API embeds like any other. Create it on your server, where the API key stays private, and put its link in the frame:

js
const response = await fetch('https://new.strawpoll.com/api/v4/polls', {
	method: 'POST',
	headers: { 'X-API-Key': process.env.STRAWPOLL_API_KEY, 'Content-Type': 'application/json' },
	body: JSON.stringify({
		title: 'Where should we go for lunch?',
		options: ['Pizza', 'Sushi', 'Tacos']
	})
});
const poll = await response.json();

const src = new URL(poll.urls.voteUrl);
src.searchParams.set('embed', '1');
// <iframe src="${src}" …></iframe>

For a form from POST/forms, take urls.formUrl and send "status": "published", or it starts as a draft that can’t be embedded. Store the slug to read the results later with GET/forms/{slug}/responses. See the StrawPoll API for every endpoint.

Frameworks

In React, Vue, Svelte and other frameworks, render the <iframe> in a component and load embed.js once, in the page’s <head>. A React component:

jsx
export function StrawPoll({ slug, title }) {
	return (
		<iframe
			src={`https://strawpoll.com/r/${slug}?embed=1`}
			title={title}
			width="100%"
			height={640}
			style={{ border: 0, maxWidth: '100%', borderRadius: 8 }}
			loading="lazy"
			allow="clipboard-write"
		/>
	);
}

Several polls on one page work: the script serves them all.

Content Security Policy

If your site sends a Content Security Policy, allow StrawPoll in it:

text
frame-src https://strawpoll.com;
script-src https://strawpoll.com;

script-src is only needed for embed.js. For a poll on a custom domain, allow that domain instead. Without these, the browser leaves the frame empty and says why in its console.

In the frame

  • No ads and no analytics. Embedded polls never show ads, on any plan, and StrawPoll’s analytics don’t run in them.
  • A small badge on Free and Basic. Embedded polls show a “Made with StrawPoll” link at the bottom. Pro and up remove it. See pricing.
  • The poll’s own theme. Colors, font, logo and custom CSS come from the poll, so change them there.
  • Results stay in the frame. When voters see results after voting, they open in the frame, sized like the poll.
  • Edits show up right away. Publish a change and every embed shows it. The code never changes.