Free CSS Gradient Border Generator
Create beautiful gradient borders using the border-image property. Adjust colours, width, radius and angle, then copy the CSS.
How It Works
- Choose gradient colors: Pick two or more colors for the border gradient using the color pickers.
- Set border width and radius: Adjust the border thickness and corner radius to match your design.
- Copy the CSS: The generated CSS using border-image or the pseudo-element technique is ready to paste into your stylesheet.
Why Use CSS Gradient Border Generator?
CSS gradient borders are a visually striking design detail used in modern UI frameworks, card components, button hover states, and highlighted sections. But standard CSS border only accepts solid colors, creating gradient borders requires a workaround using border-image or pseudo-element masking with clever background-clip tricks. This generator handles both techniques and outputs clean, copy-ready CSS so you can focus on design, not syntax.
Features
- Two implementation methods: Choose between border-image (simple) and the pseudo-element background-clip technique (supports border-radius).
- Border radius support: The pseudo-element method supports rounded corners that border-image cannot achieve.
- Multi-stop gradients: Add any number of color stops for complex rainbow or branded gradient effects.
- Live preview: See exactly how the border will look before copying the code.
- Angle control: Rotate the gradient direction with a visual angle picker.
Frequently Asked Questions
Why can't I use border-image with border-radius?
border-image replaces the border rendering entirely and ignores border-radius, the corners remain square. To combine gradient borders with rounded corners, use the pseudo-element technique: apply the gradient as a background on ::before and use background-clip: padding-box on the element itself.
Can I animate gradient borders?
Yes. Gradient borders created with the background + pseudo-element method can be animated by transitioning background-position on the gradient. Apply background-size: 300% 300% and animate background-position for a flowing effect.
Will this work on buttons and inputs?
Yes, the generated CSS works on any HTML element. For buttons, prefer the pseudo-element approach to maintain border-radius. For inputs, apply the border-image technique or wrap the input in a gradient container div.
What CSS gradient borders actually solve
The CSS border property accepts a single solid color, not a gradient. This is a 1996-era limitation that survived into modern CSS. For most of web history, designers who wanted a gradient outline around a card or button had to choose between using a background image (raster, doesn't scale), wrapping the element in a colored container (works but breaks layout in subtle ways), or accepting solid borders. CSS gradient borders are workarounds that simulate the look of border: 3px solid linear-gradient(...) through other CSS properties, since that exact syntax does not exist.
Two techniques dominate. border-image (CSS Backgrounds and Borders Module Level 3, 2012) replaces the border rendering with a gradient or image. It works, but border-image ignores border-radius entirely: corners stay square. The pseudo-element + background-clip technique uses a wrapper element with a gradient background and an inner overlay that masks out everything except the border area. This supports rounded corners but requires two layers of CSS and careful handling of padding versus content boxes. A third modern approach uses mask-composite (2020+ browsers) for a cleaner single-element solution.
Gradient borders matter for current design trends. Card-based layouts (Stripe, Linear, Vercel, Cursor) use subtle two-color gradient borders to add depth without heaviness. Premium feature highlights often draw a colorful gradient border to denote "Pro" status. Cyberpunk and synthwave aesthetics use neon gradient borders to evoke retro-future vibes. AI-product launches in 2023-2024 standardized on multi-color animated gradient borders as a visual signature (OpenAI, Anthropic, Perplexity). What used to require image editors now ships as 5 to 10 lines of CSS.
How this tool works under the hood
The preview is a single div with the two techniques applied via inline CSS, switchable by your method choice. For border-image, the tool sets border: Npx solid transparent with border-image: linear-gradient(...) 1; the 1 slice value tells the browser to use the gradient at full size for each border edge. For the pseudo-element technique, the tool applies a gradient background to the outer element and uses ::before (or background-clip: padding-box) to mask out the inner content area, leaving only the border ring visible.
Color stops are stored as JavaScript array of {color, position} pairs. When you pick colors or move the angle slider, the tool reconstructs the linear-gradient() string by joining stops with commas and prepending the angle: linear-gradient(45deg, #ff0080 0%, #7928ca 100%). That string is interpolated into both the preview CSS and the code box. The angle slider uses a 0 to 360 degree range with visual SVG arrow rotation for orientation feedback.
Nothing leaves your browser. The gradient string generation, the color storage, the preview rendering, and the clipboard copy all happen in JavaScript on your device. No network request is made; no analytics tracks which colors you pick. The tool has no backend at all beyond the static HTML and JavaScript served once on first load. Refresh the page and your selected colors and angle are gone unless you copied the CSS first.
Brief history of CSS borders and gradients
- CSS 1 borders, 1996. The first CSS specification (CSS 1, December 1996) defines
border-style,border-width, andborder-color, supporting only solid colors and the eight border styles (none, dotted, dashed, solid, double, groove, ridge, inset, outset). No gradient support, an architectural choice that persists for 16 years. - CSS linear-gradient ships, 2008 to 2011. WebKit introduces
-webkit-gradient()in 2008, followed by the standardizedlinear-gradient()in CSS Image Values and Replaced Content Module Level 3 (2011). Gradients become first-class CSS citizens for backgrounds, but not borders. Designers immediately want gradient borders; the spec doesn't accommodate. - border-image arrives, 2012. CSS Backgrounds and Borders Module Level 3 (CR June 2012) defines
border-imagewith full browser support by 2014. Lets borders use any image, including CSS gradients. The catch:border-imageoverridesborder-radius, so rounded gradient borders remain impossible with this technique alone. - Pseudo-element workaround pattern emerges, 2013 to 2015. CSS-Tricks and similar resources publish workarounds using
::beforepseudo-elements with gradient backgrounds andbackground-clip: padding-boxtricks. The "rounded gradient border" becomes solvable but requires understanding box-model intricacies. By 2015, the pattern is widespread in design system documentation. - conic-gradient lands, 2018 to 2021. CSS conic-gradient() (Chrome 69, September 2018; Firefox 83, November 2020; Safari 12.1, March 2019) enables circular sweep gradients, ideal for "loading ring" effects with gradient borders. Combined with animation, conic-gradient borders create the rotating glow patterns popular in AI product launches in 2023.
- mask-composite unlocks cleaner solutions, 2020 to 2024. CSS Masking Module Level 1 (2014) and
mask-compositesupport in modern browsers (2020+) allows single-element gradient borders without pseudo-elements: layer a gradient background and mask out everything except the outer ring via composite operations. By 2024 this is the cleanest production approach, though pseudo-element workarounds remain compatible with older browsers.
Real-world workflows
- Card-component subtle accents. Modern dashboard cards (think Stripe, Linear, Vercel) use 1- to 2-pixel gradient borders in two-tone or three-tone color schemes to add visual interest without heaviness. The gradient is usually subtle: 10% to 20% opacity, low contrast, mostly grayscale with a hint of brand color. This is enough to differentiate cards from a flat background and signal interactivity.
- Premium feature highlights. SaaS pricing tables use vivid gradient borders (often gold-to-purple or rainbow) on the "Pro" or "Recommended" plan to visually elevate it. The pattern works because it draws the eye through color and motion (if animated) without requiring badge labels. Linear, Notion, Figma, and most modern SaaS pricing pages use this exact pattern.
- Neon and glow effects. Cyberpunk, synthwave, and gaming UI aesthetics combine gradient borders with box-shadow for a neon-tube look. The border provides the color transition, the shadow provides the bloom. Common pattern:
border-image: linear-gradient(45deg, #ff0080, #00d4ff) 1plusbox-shadow: 0 0 20px rgba(255,0,128,0.5)on the same element. - AI product visual identity. The 2023-2024 wave of AI tools (OpenAI ChatGPT, Anthropic Claude, Perplexity, Cursor) converged on animated multi-color gradient borders as a visual signature for "AI is thinking" or input fields awaiting AI processing. Usually rotating conic gradients or shifting linear gradients on a 4 to 6 second loop. Becomes shorthand for "intelligent / generative" in modern UX.
- Hover and focus state polish. Buttons and inputs that switch from solid border in resting state to gradient border on hover or focus feel premium and intentional. The transition between colors can animate with CSS transitions on
background-positionif the gradient extends beyond the visible area (background-size: 200% 100%with a slide animation). - Brand color expression. Brand systems with multi-color logos (Instagram, Slack, Discord) often use gradient borders to extend their identity into UI components. A card with the brand gradient as its border establishes visual continuity with the logo. For SaaS marketing pages, this is one of the cheapest ways to make a generic component look "branded."
Common pitfalls and what they mean
- border-image ignores border-radius. The most common confusion: using
border-image: linear-gradient(...)alongsideborder-radiusproduces square corners.border-imagetakes over border rendering completely and the radius property has no effect on the painted result. To get rounded gradient borders, use the pseudo-element technique or modernmask-compositeapproach, not border-image. - Pseudo-element technique requires padding-box. The standard workaround uses
backgroundon the outer element and an inner overlay via::before. Critical detail: the inner overlay needsbackground-clip: padding-boxso it stops at the padding edge, leaving the border area visible. Skipping this clip property results in the gradient being completely covered by the overlay, no border visible. - Animating gradient borders is GPU-expensive. Animated gradient borders (the "AI shimmer" pattern) work by transitioning
background-positionon a large gradient. While modern GPUs handle this well, applying it to many elements simultaneously (e.g., every card on a page) drops frame rates noticeably on low-end devices. Use animated gradient borders sparingly: one or two "hero" elements per page, not site-wide. - Dark-mode color clash. A gradient border designed for a light background often looks wrong on dark backgrounds. Pure white gradients become invisible; vibrant colors look oversaturated. For dual-theme designs, define separate gradient color stops for light and dark modes via CSS custom properties or media queries. Reduce saturation and adjust hue to maintain visual harmony with the surrounding theme.
- Low-contrast borders fail accessibility. Subtle gradient borders that look elegant may fail WCAG 2.1 SC 1.4.11 Non-text Contrast (3:1 minimum) for UI components that convey state. If the gradient border is the only visual indicator of a button's bounds or a card's selectability, ensure adequate contrast with the background. For purely decorative borders on already-visible elements, contrast is less critical but still worth checking.
- Internet Explorer and old Edge support nothing useful. IE 11 (retired June 2022) and pre-Chromium Edge (2015 to 2019) lack reliable
border-imagefor gradients,mask-composite, and several pseudo-element techniques. For these legacy browsers, fall back gracefully to a solid border using the gradient's middle color. Modern browsers cover 99%+ of users in 2026, but legacy fallbacks remain important for enterprise software.
Privacy: everything runs in your browser
CSS generator tools come in two flavors: simple HTML pages running client-side JavaScript (private, fast) and cloud editors that save your projects (collaborative but with privacy trade-offs). This tool is the first kind. Your selected colors, your angle, your generated CSS: all stay in your browser session. Refresh the page and the state is gone unless you copied the CSS first. No server stores your gradient choices, no analytics tracks which color combinations you tried, and no account is needed.
The privacy property matters mostly for proprietary design work. A studio prototyping gradient combinations for a confidential brand redesign, a developer working on an unannounced product's UI accents, or a designer iterating on a campaign palette: any context where the color choice or iteration history could leak information about the work. With this tool, there is nothing captured because nothing is sent. Open the browser's Network tab and you will see zero outbound requests during use; only the initial page load fetches the HTML and JavaScript.
When another tool is the right pick
- SVG for complex border shapes. For non-rectangular gradient borders (rounded with notches, scalloped edges, custom irregular shapes), SVG with
linearGradientorradialGradientapplied to astrokeattribute provides full control. CSS gradient borders work for rectangles and rounded rectangles; SVG handles everything else. Use the two together: SVG for decorative shape outlines, CSS for standard UI components. - Photoshop for static gradient images. If the gradient border is on a static hero image or banner that won't change, designing it in Photoshop, Figma, or Sketch and exporting as a PNG or WebP can be simpler than maintaining CSS. The image scales as part of the page asset pipeline. CSS gradient borders are for dynamic elements (cards, buttons, components) that need to render at any size.
- Component libraries for design system consistency. Tailwind UI, shadcn/ui, Radix, and other component libraries ship pre-styled card and button components with optional gradient border variants. For projects already using these libraries, applying the library's variant is faster than hand-rolling CSS. Hand-rolled gradient borders are useful for one-off designs or projects not yet committed to a component library.
- Canvas or WebGL for animated multi-layer effects. For highly animated, multi-layer gradient effects (particle systems, fluid simulations, generative art), Canvas 2D or WebGL provides per-pixel control that CSS cannot match. The trade-off is implementation complexity and accessibility (canvas content is invisible to screen readers). For decorative gradient borders on standard UI components, CSS is the right choice; for visual effects, consider canvas-based approaches.
Other frequently asked questions
Can I use more than two colors in a gradient border?
Yes. CSS linear-gradient() accepts unlimited color stops: linear-gradient(45deg, #ff0080 0%, #ffa500 50%, #00d4ff 100%) creates a three-color gradient transitioning through orange in the middle. Add as many stops as you want, each with an optional position. For complex multi-color gradients (rainbow effect), distribute stops evenly: 0%, 16.7%, 33.3%, 50%, 66.7%, 83.3%, 100%.
How do I create a rainbow or conic gradient border?
For conic (sweep) gradients, use conic-gradient(from 0deg, red, yellow, lime, cyan, blue, magenta, red) as the background of the outer element with the pseudo-element padding-box masking technique. For a rotating effect (popular in AI product loading states), animate --angle via CSS Houdini or use @property --angle with a 360-degree rotation animation. The result is a smooth color sweep around the border.
Can I use CSS custom properties for theme-aware gradient borders?
Yes, and it is the recommended approach for design systems. Define gradient colors as CSS custom properties (--gradient-start, --gradient-end) and use them in your gradient declaration: linear-gradient(var(--angle), var(--gradient-start), var(--gradient-end)). Override the variables in dark-mode media queries or theme classes. One CSS file handles both light and dark themes via variable redefinition.
Does this work in old browsers like Internet Explorer?
Internet Explorer 11 (officially retired by Microsoft in June 2022) had partial border-image support but unreliable gradient rendering, and no mask-composite. Modern browsers (Chrome 88+, Firefox 78+, Safari 14+) fully support both techniques. If you must support IE, provide a solid-color fallback using the gradient's middle color: declare border: 3px solid #888; before the gradient rule, and IE will use that while modern browsers apply the gradient.
Is there a single-property way to do gradient borders?
Not yet in standardized CSS. Modern proposals (CSS Backgrounds and Borders Module Level 4 draft) include the border-color property accepting gradients directly, but browser implementations are not yet stable. The closest current approximation is the mask-composite technique which uses a single element but still requires three CSS declarations. Hopefully by 2027 or 2028, border: 3px solid linear-gradient(...) will just work.
Why does my gradient border look different in Safari?
Safari historically lags Chrome and Firefox in CSS feature parity, especially for mask-composite values and some background-clip edge cases. Test in Safari explicitly. If the pseudo-element technique fails in Safari, switch to border-image (which works universally but loses border-radius), or use Safari-specific prefixes: -webkit-mask-composite may be required for older Safari versions. iOS Safari often needs the prefix even in 2024 versions.