Socialx.com
Can you embed X (Twitter) in an iframe?
Yes, but only with the official embed code, not with an iframe of the post page. X documents the Embed post code with widgets.js.
Checked Test again
Live check
What the main page sends
Post pagePartial
x.com/Interior/status/463440424141459456- X-Frame-Options
- SAMEORIGIN (ignored)
- CSP frame-ancestors
- 'self' https://x.com https://x.com:443 https://twitter.com https://twitter.com:443
- Response
- 200 OK · 140 ms · HTTPS
Embed codeNot checked
x.com/{username}/status/{post-id}Not checked: needs your own link. X (Twitter) has no public sample we can load.
Test your linkSteps
How to embed X (Twitter)
- Open the post on x.com.
- Open the post menu. Then clickEmbed Post
- On publish.x.com, set the look of the embedded post.
- For a reply, select Hide Conversation to hide the parent post.
- Click Copy Code. Then paste the code into the HTML of your page.
Embed code
Paste this into your page
HTML
<blockquote class="twitter-tweet">
<a href="https://x.com/{username}/status/{post-id}">{post text}</a>
</blockquote>
<script async src="https://platform.x.com/widgets.js" charset="utf-8"></script>The widgets.js script changes the blockquote into the full post. Without the script, only the plain text shows.
URL patterns
Swap the link you have for the embed URL
- You havehttps://x.com/{username}/status/{post-id}Use in the iframehttps://publish.x.com/oembed?url=https://x.com/{username}/status/{post-id}
The oEmbed URL gives the embed code for a post URL. Use it in a CMS or an app.
Good to know
- Posts from protected accounts have no embed code.
- Set data-conversation="none" to hide the parent post of a reply.
- Set data-theme="dark" for light text on a dark background.
- Set data-cards="hidden" to hide photos, videos and link cards.
- Set data-width to a value from 250 to 550 pixels.
- Set data-dnt="true" to stop X from using the post and your page for personalized ads and suggestions.
Sources
- X Developer Platform · Embedded Postsdocs.x.com/x-for-websites/embedded-posts/overview
- X Developer Platform · Embedded Post parameter referencedocs.x.com/x-for-websites/embedded-posts/guides/embedded-tweet-parameter-reference
- X Help Center · How to embed a post on your website or bloghelp.x.com/en/using-x/how-to-embed-a-post
- MDN · X-Frame-Optionsdeveloper.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Frame-Options
- iframecheck live check · main page
Profile updated