Professional Documents
Culture Documents
Overview
The Tweet Button is a small widget which allows users to easily share your website with their followers. This
page is for developers and users who wish to build their own Tweet Buttons. If you are looking for a quick way
to build a Tweet Button for your website you can visit our Tweet Button Goodies Page.
The easiest way to add the Tweet Button to your website is to use Javascript. This method requires adding a
line of Javascript and an HTML anchor to your webpage. Using this method you can customise the Tweet
Button using data attributes and query string parameters.
Notice how the anchor element has a class of twitter-share-button. This is required for the Tweet
Button javascript to know which anchor elements to convert to buttons.
If you prefer you can add a Tweet Button using an iFrame. When using this method you have to use query
string parameters to customise the Tweet Button’s behavior.
If you want to be able to customise the way the Tweet Button looks you will want to use this basic format. When
using this method you have to use query string parameters to customise the Tweet Button’s behavior.
Properties
There are several properties for the Tweet Button which allow you to customise it’s behavior. If the query string,
data source or link source are not provided the Tweet Button will use the default values available from the web
page and referrer information.
To learn more about each property and to see ways you can use them check the examples further down this
page.
The properties in this table can be used by the javascript, iframe and custom types of Tweet Button. Each
property is a query string parameter for the http://twitter.com/share URL.
The properties in this table can only be used by the javascript Tweet Button. When used they provide additional
places the Tweet Button can look for information on what to pre fill the Tweet with. The Tweet Button looks for
property values in the preference order given in the table. For example when looking for the URL to use, the
Tweet Button will:
Data Source Preference Order URL to Tweet Screen name of Default Tweet text Related accounts Count box
the user to position
attribute the Tweet
to
Share query string 1 url via text related count
data- attribute of 2 data-url data-via data-text data-related data-count
a tag
rel= attribute of a 3 rel="canonical" rel="me"
link tag
Default 4 Webpage URL Content of the horizontal
<title> tag
For the iFrame Tweet Button the position of the count box is controlled by setting the value of the count
property in the sharing URL.
For the javascript Tweet Button you can use the data-count property instead of adding count to the URL.
The values for the property remain the same.
When no value is given for the count box the Tweet Button will default to horizontal.
Examples
The examples that follow show different ways you can use the Tweet Button. The code to produce the example
is also given so you can copy and paste.
These examples are real Tweet Buttons. If you press the button you will see a real Tweet Box.
The default Tweet Button works without any configuration or parameters. In this example the Tweet Button will
use the URL of the current webpage and the content of the <title> element.
Query string configuration can be used in the javascript, iframe and custom types of the Tweet Button. For each
property you should URL encode the value you are sending.
In this example we’ll be setting the following values. Notice how the url and text properties are URL
encoded:
url: http%3A%2F%2Fdev.twitter.com
via: twitterapi
text: Checking%20out%20this%20page%20about%20Tweet%20Buttons
related: twitter,anywhere:The Javascript API
Whilst query string parameters are a convenient way to share your webpage they can make your anchor tag
very long. A long URL is difficult to maintain, especially when you have to URL encode the parameters.
To make things easier the javascript Tweet Button allows you to supply data attributes to your URL. These
data attributes take the same values and cause the same Tweet Button behaviour as the query string
parameters. The difference is they are attributes of the anchor tag, not the URL.