Gradient Border CSS Rounded Cards With Padding Box Trick
Three course cards for a pottery studio, each framed by a two pixel gradient border: orange to pink at a 12px radius, teal to indigo at 24px and yellow to green at 36px. The cards prove the point of the technique: the gradient follows any corner radius, which border-image cannot do. On phones the cards stack into one column with the same borders.
Code
// Rounded gradient borders with one element each: solid fill clipped to padding-box over a gradient clipped to border-box.
const cards = [
{ title: "Glaze chemistry", meta: "6 weeks, Mondays", body: "Mix and test your own stoneware glazes, from celadon to tenmoku.", grad: "linear-gradient(135deg,#f97316,#ec4899)", radius: "12px" },
{ title: "Throwing large forms", meta: "4 weeks, Wednesdays", body: "Centre ten kilos of clay and pull walls for planters and jars.", grad: "linear-gradient(135deg,#14b8a6,#6366f1)", radius: "24px" },
{ title: "Raku firing day", meta: "1 day, Saturday", body: "Pull glowing pots from the kiln and smoke them in sawdust.", grad: "linear-gradient(135deg,#eab308,#16a34a)", radius: "36px" },
];
export default function GradientBorderCssRoundedCardsWithPaddingBoxTrick() {
return (
<section className="bg-stone-100 px-5 py-16">
<div className="mx-auto max-w-5xl">
<h2 className="text-center text-2xl font-semibold tracking-tight text-stone-900">Courses starting in March</h2>
<p className="mt-2 text-center text-sm text-stone-600">Same border trick on three radii: 12, 24 and 36 pixels.</p>
<ul className="mt-10 grid gap-5 sm:grid-cols-3">
{cards.map((c) => (
<li
key={c.title}
className="border-2 border-transparent p-6"
style={{ borderRadius: c.radius, background: `linear-gradient(#fff,#fff) padding-box, ${c.grad} border-box` }}
>
<p className="text-xs font-semibold uppercase tracking-wider text-stone-500">{c.meta}</p>
<h3 className="mt-2 text-lg font-semibold text-stone-900">{c.title}</h3>
<p className="mt-2 text-sm leading-relaxed text-stone-600">{c.body}</p>
<a href="#" className="mt-5 inline-flex min-h-[40px] items-center text-sm font-semibold text-stone-900 underline decoration-stone-300 underline-offset-4 hover:decoration-stone-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-stone-900">
Reserve a place
</a>
</li>
))}
</ul>
</div>
</section>
);
}
Install with one command: npx shadcn@latest add https://we.inc/r/gradient-border-css-rounded-cards-with-padding-box-trick.json
When to use it
- Cards on a plain background need a colourful edge without an extra wrapper element.
- Your design uses large rounded corners and border-image squared them off.
- Each card in a set should carry its own colour, set by one variable per card.
- You want a gradient outline that costs nothing after the first paint.
How to customize it
- Set `--gb1-grad` on each card to any gradient, including radial or conic ones.
- Change `--gb1-width` from 2px to 1px for a fine hairline or 4px for a bold frame.
- Match `--gb1-fill` to the card colour you want inside; it has to be solid, so for a see-through middle use the mask method instead.
- In Tailwind, write the background as an arbitrary value: `[background:linear-gradient(#fff,#fff)_padding-box,linear-gradient(135deg,#f97316,#ec4899)_border-box]` with `border-2 border-transparent`.
Accessibility
- The border is decoration only; card titles are real h3 headings under the section's h2.
- Text sits on a solid white fill, so contrast is unaffected by the gradient colours.
Questions
Why use background-clip instead of border-image?
border-image paints the border in straight slices and ignores border-radius, so rounded cards end up with square gradient corners. Two clipped backgrounds respect the radius because both are ordinary backgrounds of a rounded box.
Can the inside be transparent?
Not with this method, because the solid inner layer is what hides the middle of the gradient. If the card sits on a photo or pattern, put the gradient on a masked pseudo-element instead, which cuts the centre out.
Does it work with a semi-transparent fill?
Only partly. A see-through fill lets the gradient behind show through the whole card. If you want a tinted card, use a solid colour that matches the tint on your background.
How do I change the border thickness?
Change the width of the transparent border. The gradient fills whatever border area there is, so a 1px, 2px or 6px border all work without touching the gradients.
Related: CSS Gradient Border: 12 Techniques with Rounded Corners and Glow, HTML CSS Gradient Border Button On Dark, HTML CSS Button Solid Outline Ghost With Hover Active Disabled States.
More borders and glows or all free UI components. Build your site free to have a full site built around it.
More in Borders
- CSS Gradient Border: 12 Techniques with Rounded Corners and Glow
- Glass Tube Border Feature Card in WebGL with a Warm Bead of Light That Runs the Edge and Warms the Sunlit Table
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App