@opengraphplus/tailwind
v0.1.0
Published
TailwindCSS plugin for OpenGraph+
Maintainers
Readme
OpenGraph+ Tailwind Plugin
TailwindCSS v4 plugin that adds variants for styling elements specifically for OpenGraph image generation via OpenGraph+.
Installation
npm install @opengraphplus/tailwindUsage
In your CSS file where you import TailwindCSS:
@import "tailwindcss";
@plugin "@opengraphplus/tailwind";Then use the ogplus: variant on any utility class:
<!-- Hide elements in OpenGraph images -->
<nav class="ogplus:hidden">...</nav>
<!-- Show elements only in OpenGraph images -->
<div class="hidden ogplus:block">Special OG content</div>
<!-- Different styling for OG -->
<h1 class="text-2xl ogplus:text-4xl">Title</h1>Provider-Specific Variants
Target specific social platforms with provider variants:
<!-- Different padding per provider -->
<div class="ogplus:p-8 ogplus-linkedin:p-12 ogplus-twitter:p-6">
Content
</div>
<!-- Provider-specific backgrounds -->
<div class="ogplus:bg-slate-900 ogplus-twitter:bg-blue-500 ogplus-linkedin:bg-blue-700">
Content
</div>Available provider variants:
ogplus-linkedin:- LinkedInogplus-twitter:- Twitter/Xogplus-facebook:- Facebookogplus-discord:- Discordogplus-whatsapp:- WhatsAppogplus-apple:- Apple (iMessage, etc.)ogplus-bluesky:- Bluesky
How It Works
This plugin adds custom variants that target the data-ogplus attribute on the <html> element. When OpenGraph+ renders your page for image generation, it adds this attribute:
<!-- Base render -->
<html data-ogplus>
<!-- Provider-specific render -->
<html data-ogplus="twitter">The generated CSS uses :where() selectors to match these attributes:
/* ogplus:hidden generates */
:where([data-ogplus]) .ogplus\:hidden { display: none; }
/* ogplus-twitter:bg-blue-500 generates */
:where([data-ogplus="twitter"]) .ogplus-twitter\:bg-blue-500 { background-color: #3b82f6; }Plain CSS Usage
You can also use the data attributes directly in your CSS without Tailwind:
/* Target all OpenGraph renders */
[data-ogplus] .nav,
[data-ogplus] .footer { display: none; }
[data-ogplus] .hero { padding: 60px; background: #0f172a; }
/* Target specific providers */
[data-ogplus="linkedin"] .hero { padding: 80px; }
[data-ogplus="twitter"] .hero { background: #1da1f2; }