How to add a Post button to your website
- Create a new anchor element with a
twitter-share-buttonclass to allow the X for Websites JavaScript to discover the element and enhance the link into a Post button. Set ahrefattribute value ofhttps://x.com/intent/tweetto create a link to the X web intent composer.
- Pre-populate Post text and suggest related accounts by customizing Post web intent query parameters.
- Customize Post button parameters using
data-*attributes.
- Asynchronously load the X for Websites JavaScript using our loading snippet. The JavaScript snippet will check for an existing version already on the page, initialize a function queue to be executed once the widgets JavaScript has loaded, and load the widgets JavaScript asynchronously from X’s CDN.
Post text components
text
Atext parameter appears pre-selected in a Post composer. The Post author may easily remove the text with a single delete action.
The text parameter may be auto-populated from the webpage’s <title> element if not explicitly set.
url
Theurl parameter contains an absolute HTTP or HTTPS URL to be shared on X. The shared URL will be automatically shortened in a published Post. A Card may appear for a shared URL.
The url parameter may be auto-populated from a canonical link element (<link rel="canonical">) or the location.href of the page when not explicitly set.
hashtags
Add a comma-separated list ofhashtags to a Post using the hashtags parameter. Omit a preceding “#” from each hashtag; the Post composer will automatically add the proper space-separated hashtag by language.
via
Attribute the source of a Post to a X username using thevia parameter. The attribution will appear in a Post as ” via @username” translated into the language of the Post author.
A via parameter may be auto-populated from a link or anchor element linked to a X profile page with a me relationship token.
Button customization
Size
Add adata-size attribute value of large to display a larger Post button.