PHP PollUser Manual Visit PHP Poll →
Embed & share

Embed a poll with JavaScript

Add a poll to any HTML page with two lines of JavaScript. The PHPPoll embed resizes itself, supports light and dark themes and custom accent colors.

The JavaScript embed is the easiest and most flexible way to show a poll on another page. It works in plain HTML, WordPress, Joomla, Wix, Shopify and any other system that lets you paste HTML.

A PHPPoll poll embedded in the sidebar of an existing website
A poll embedded in the sidebar of an existing website.

The code

Copy the code from Embed & share → JavaScript embed:

<div data-phppoll="POLL_ID"></div>
<script src="https://www.example.com/poll/embed.js" async></script>
  1. Paste the <div> exactly where the poll should appear.
  2. Paste the <script> line once on the page, usually just before </body>. It activates all poll placeholders on the page.

Several polls on one page

Add one <div data-phppoll="..."> for each poll. The script tag is needed only once.

Options

AttributeValuesEffect
data-phppollpoll IDWhich poll to show (required).
data-themelight, dark, autoOverrides the theme of the poll.
data-accentcolor like #e11d48Overrides the accent color.
<div data-phppoll="abc123" data-theme="dark" data-accent="#e11d48"></div>

Single-tag alternative

If you can add only one tag, use the script with the poll ID. The poll appears right after the script:

<script src="https://www.example.com/poll/embed.js" data-poll="POLL_ID"></script>

How it works

The script creates a responsive iframe that loads the poll from your PHPPoll folder. The poll reports its height to the page, so the frame grows when the results appear – no scrollbars. Because the poll lives in its own frame, your website's CSS cannot break it and it cannot break your site.

The embed uses the Script URL to find embed.js. When the address in the code is wrong, fix it in Settings. See Settings.

No scripts allowed on your page? Use the iframe code.

Last updated