Skip to main content
A Hashtag button is a special type of Post button to encourage participation in a conversation grouped by keyword. Read more about hashtags on X.

How to add a Hashtag Button to your website

  1. Create a new anchor element with a twitter-hashtag-button class to allow the X for Websites JavaScript to discover the element and enhance the link into a Hashtag button. Set a href attribute value of https://x.com/intent/tweet to create a link to the X web intent composer.
<a class="twitter-hashtag-button"
  href="https://x.com/intent/tweet">
Post</a>
  1. Add your hashtag of interest as a button_hashtag query parameter value and a component of the anchor element’s inner text.
<a class="twitter-hashtag-button"
  href="https://x.com/intent/tweet?button_hashtag=XStories">
Post #XStories</a>
  1. Asynchronously load the X for Websites JavaScript using our loading snippet. The JavaScript snippet will check for an existing version 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.

Define secondary hashtags

Include additional hashtags in pre-populated Post text using the hashtags web intent query parameter. A hashtag defined in the button_hashtag parameter and displayed in the button will appear before hashtags defined in the hashtags parameter.

JavaScript factory function

X’s widget JavaScript library supports dynamic insertion of a hashtag button using the twttr.widgets.createHashtagButton function. Pass a hashtag, target container element, and the same options supported by the Post button JavaScript factory function.
twttr.widgets.createHashtagButton(
  "XStories",
  document.getElementById("container"),
  {
    size:"large"
  }
);