Screenshot a Tweet/Post
Use the HTML/CSS to Image API to generate images of tweets and posts on X.
There are two ways to capture a screenshot of a tweet: using the URL method (recommended) or the HTML embed method.
Method 1: URL Screenshot (Recommended)
The simplest approach is to use the url parameter to directly screenshot the tweet on x.com.
Example
Pass the tweet URL directly to the API with the selector parameter set to article to crop to just the tweet.
curl -X POST https://hcti.io/v1/image -u 'UserID:APIKey' \
-H "Content-Type: application/json" \
-d '{
"url": "https://x.com/usahockey/status/2006109366827597923",
"selector": "article",
"ms_delay": 3000,
"device_scale": 2
}'
Result
Parameters
| Parameter | Value | Description |
|---|---|---|
| url | Tweet URL | The full URL to the tweet on x.com (e.g., https://x.com/username/status/123456789) |
| selector | article | Crops the image to just the tweet content |
| ms_delay | 3000 | Gives the page time to fully load (3 seconds recommended) |
| device_scale | 2 | Optional. Higher resolution image |
Twitter vs X URLs
Both twitter.com and x.com URLs work. The API will follow redirects automatically.
Method 2: HTML Embed
You can also use the X/Twitter embed widget to render a tweet. This gives you a card-style appearance.
HTML
<blockquote class="twitter-tweet" data-dnt="true">
<a href="https://twitter.com/usahockey/status/2006109366827597923"></a>
</blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
Result
Parameters for HTML Embed
| Parameter | Value | Description |
|---|---|---|
| selector | .twitter-tweet | Crops to the rendered tweet widget |
| ms_delay | 3000 | Gives the embed time to load via JavaScript |
Choosing the Right Method
| Method | Best For |
|---|---|
| URL Screenshot | Full tweet appearance as seen on x.com, including engagement metrics |
| HTML Embed | Card-style appearance with X branding, “Follow” button, and replies link |
Getting the Tweet URL
To get the URL of any tweet:
- Click on the tweet to open it
- Copy the URL from your browser’s address bar
- The URL format is:
https://x.com/username/status/tweet_id
Need help?
Talk to a human. Please email us support@htmlcsstoimage.com with any questions and we’ll gladly help you get started.