Tweet
The <Tweet>
component embeds posts to Twitter (also known as X) in Astro projects.
Usage
The <Tweet>
component generates a static Twitter card for a single Tweet using Twitter’s oEmbed API.
The above code produces the following result:
Astro has all-new catalogs to launch your next project 🚀
— Astro (@astrodotbuild) April 6, 2022
❤️ Themes to kickstart your journey
📦 Integrations to add your fave tools
> astro add @tailwindcss, partytown, sitemap, components... the universe keeps expanding 🪐https://t.co/dMQGtU1Lkk pic.twitter.com/DamGoVoAri
Loading Twitter’s JavaScript
By design, <Tweet>
is a minimal component and loads zero JavaScript, only rendering some static HTML content.
However, this HTML is compatible with Twitter’s widget system.
Loading Twitter‘s large bundle of widget JavaScript will convert each <Tweet>
into an interactive embed.
You can do this by including the following <script>
tag in your Astro layout file:
See an example of <Tweet>
with Twitter‘s JavaScript
Use Twitter’s dark theme
When loading Twitter’s JavaScript, the <Tweet>
card will render with their light theme by default.
You can use their dark theme by setting the theme
prop:
See an example of <Tweet>
with Twitter‘s JavaScript and dark theme
Styling the Tweet component
By default the <Tweet>
card has minimal styling, which should adapt to your site’s font settings etc.
You can customise it by targeting the .twitter-tweet
class, for example:
The above styles would render <Tweet>
like this:
Introducing: Astro DB
— Astro (@astrodotbuild) March 12, 2024
Add a hosted database to any Astro project in seconds. Includes a TypeScript ORM, schema manager, and automatic migrations out-of-the-box.
Try it today! Every database comes with a generous free tier for you to get started.https://t.co/sF2LyrSEsw
Custom properties API
The <Tweet>
component also supports a minimal API for controlling its styles by setting some CSS custom properties.
Standalone installation
If you only need the <Tweet>
component, you can install the package directly instead of the main astro-embed
package:
The <Tweet>
component can then be imported as: