The Wayback Machine - https://web.archive.org/web/20240923001841/https://www.geeksforgeeks.org/gradient-borders/
Open In App

Gradient borders in CSS

Last Updated : 17 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Creating visually appealing borders can significantly enhance the user experience on your website. One such technique is the use of gradient borders. Although CSS does not directly support gradient borders, there are two effective methods to achieve this:

Try It:

Gradient Border 1
Gradient Border 2
Gradient Border 3
See the Border

Currently Active Property:

Gradient Border: linear-gradient(to right, green, lightgreen) 

Property Values

ValueDescription
linear-gradientSets a linear gradient for the border.
radial-gradientSets a radial gradient for the border.
border-imageApplies an image or gradient to an element’s border.
background-clipClips the background to extend into the border area, allowing gradient borders.

How to do gradient borders in CSS

Method 1: Border-Image with Gradient

This method involves using the border-image property in combination with a gradient. The border is defined with a transparent color and a specific size using the border property. The border-image property is then used to apply the gradient. To ensure the border is displayed correctly, the border-image-slice is set to 1.

Syntax:

.border {
width: 400px;
border: 3px solid transparent;
border-image: linear-gradient(to right, green, lightgreen);
border-image-slice: 1;
padding: 25px;
}

Example:

html
<!DOCTYPE html> 
<html> 

<head> 
    <title>Gradient Borders</title> 
    
    <style> 
        .border { 
            width: 400px; 
            border: 3px solid transparent; 
            border-image: linear-gradient(to right, green, lightgreen); 
            border-image-slice: 1; 
            padding: 25px; 
        } 
    </style> 
</head> 

<body> 
    <h1 style="color: green"> 
        GeeksForGeeks 
    </h1> 
    
    <b>Gradient Borders</b> 
    
    <div class="border"> 
        GeeksforGeeks is a computer science portal with a huge 
        variety of well written and explained computer science 
        and programming articles, quizzes and interview questions. 
    </div> 
</body> 

</html>                     

Output:

border-image

Method 2: Gradient Background with Content Overlay

This method involves creating a gradient background on an element and overlaying the content with equal padding to the required border width. This gives the illusion of a gradient border. The background color of the page is used for the content overlay.

Syntax:

.border {
width: 400px;
position: relative;
background: linear-gradient(to right, green, lightgreen);
padding: 3px;
}
.inner {
background: white;
padding: 25px;
}

Example:

html
<!DOCTYPE html> 
<html> 

<head> 
    <title>Gradient Borders</title> 

    <style> 
        .border { 
            width: 400px; 
            position: relative; 
            background: linear-gradient(to right, green, lightgreen); 
            padding: 3px; 
        } 
        .inner { 
            background: white; 
            padding: 25px; 
        } 
    </style> 
</head> 

<body> 
    <h1 style="color: green"> 
        GeeksForGeeks 
    </h1> 
    
    <b>Gradient Borders</b> 
    
    <div class="border"> 
        <div class="inner"> 
            GeeksforGeeks is a computer science portal with 
            a huge variety of well written and explained 
            computer science and programming articles, 
            quizzes and interview questions. 
        </div> 
    </div> 
</body> 

</html>                     

Output:

background-gradient

Supported Browsers

The browser supported by border-width property are listed below:

Note: Always check for the latest browser versions to ensure full compatibility with the most recent CSS features.

CSS Gradient Border Property – FAQs

Can you put a gradient on a border?

Yes, you can apply a gradient on a border using border-image or by using background-clip techniques.

How to make a gradient circle border in CSS?

Create a gradient circle border using border-radius: 50% and apply a gradient with border-image or background-clip.

What are the three types of gradients?

Create a gradient circle border using border-radius: 50% and apply a gradient with border-image or background-clip.

Can you use border-radius with a gradient border-image?

Yes, you can combine border-radius with a border-image that has a gradient for rounded gradient borders.




Similar Reads

Pure CSS Table with Horizontal Borders
A table is an arrangement of data in rows and columns, or possibly in a more complex structure. Tables are widely used in communication, research, and data analysis. In Pure CSS, we will add a "pure-table" class to add styles to the table. This class adds padding and borders to table elements and emphasizes the header. A table with Horizontal Borde
2 min read
Tailwind CSS Borders Complete Reference
Tailwind CSS is a highly customizable, low-level CSS framework that gives you all of the buildings blocks that you need. Tailwind CSS Border utility settings the radius, width, color, opacity, etc., of element's borders. all the properties covered as in this class form. Tailwind CSS Class Description Example Border RadiusIt is used to set the borde
2 min read
Primer CSS Responsive Borders
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by Object-Oriented CSS principles, functional CSS, an
3 min read
Primer CSS Borders
Primer CSS is a free and open-source CSS framework. It is built upon the systems that create the foundation of the basic style elements such as spacing, typography, and color. Created with GitHub’s design system, it is highly reusable and flexible. Primer CSS Borders is a utility class that applies borders to a div container of HTML by simply apply
3 min read
Pure CSS applying Padding and Borders to Grid Units
Pure CSS is a free and open-source CSS framework. It is a set of instruments for developing responsive websites and online applications. This was created by Yahoo and is used to create websites that are quicker, more aesthetically beautiful, and more user-friendly. It effectively replaces Bootstrap. The responsive design was considered when creatin
3 min read
How to add Borders and Shadows to Elements in CSS ?
Apply box shadows to elements to create a 3D effect, whereas adding borders to containers or boxes can enhance the structural clarity of a layout. In this article, we will learn how to add borders and shadows to the elements in CSS. We will explore two different approaches to adding borders and shadows. Table of Content Using the border and box-sha
2 min read
How to Add Borders to Pagination in CSS ?
Add borders to Pagination is when you have many pages of content and must move between them. Making these page buttons look better can make navigating easier and more enjoyable for users. One way to do this is by adding borders to the page buttons using CSS. These are the following approaches: Table of ContentUsing Border PropertyUsing Border-Style
3 min read
CSS Borders
A CSS border is a line that surrounds an HTML element, providing a visual separation between the element and its surroundings. Borders can be styled in various ways, including adjusting their width, color, and style. The basic properties used to define borders in CSS are border-width, border-style, and border-color. Here, We covered CSS borders, in
5 min read
How to remove borders of a canvas-type text using Fabric.js ?
In this article, we are going to see how to remove the borders of a canvas-like text using FabricJS. The canvas means text written is movable and can be stretched according to requirement. Further, the text itself cannot be edited like a textbox.Approach: To make it possible we are going to use a JavaScript library called FabricJS. After importing
2 min read
How to set the collapsing borders model for a table ?
CSS describes the way HTML elements should be displayed. There are various CSS properties that can add magic to the basic HTML document. This article is focused on setting the collapsing borders model for the table element of HTML. HTML tables allow us to arrange our data using rows and columns. The &lt;table&gt; tag defines an HTML table. Each tab
3 min read
Borders in bootstrap with examples
Borders: Borders are generally used to display an outline around a box or table cell or any other HTML element. In Bootstrap, there are different classes available to add or remove borders. The classes that are used to add borders are referred as Additive classes and those that are used to remove borders are referred as subtractive classes. Additiv
4 min read
How to remove controlling borders of a canvas circle using Fabric.js ?
In this article, we are going to see how to remove the controlling borders of a canvas circle using FabricJS. The canvas means the circle is movable and can be stretched according to requirement. Further, the circle can be customized when it comes to initial stroke color, fill color, stroke width, or radius. Approach: To make it possible, we are go
2 min read
How to change Input box borders after filling the box using JavaScript ?
In this article, we will change the input border after filling in the text on the input text field. The onchange event attribute works when the value of the element changes and selects the new value from the list. Approach: Whenever the input value is changed with some value by the user, the onchange event attribute is triggered. After the event is
2 min read
React MUI Borders
Material UI is an open-source design framework that showcases different components made in react. It is developed and maintained by Google since 2014. What is Borders API offered by Material UI? The Borders API, provided by MUI, allows us to control the border and border-radius of DOM elements that have border utilities. passed to Borders API props
3 min read
Tachyons Theming Borders
CSS border properties allow us to set the style, color, and width of the border. Tachyon is a toolkit that is used to create a responsive website. Used Classes: Border: The "ba" class is used to create a simple border.Border Top: The "bt" class is used to create a border from the top.Border Right: The "br" class is used to create a border from the
4 min read
Bootstrap 5 Borders Sizes
Bootstrap 5 Border utility is used to set the style of the border element. The border styles can be of border-color, border-width, border-radius, etc. The Border Sizes are used to set the border-radius rounded corners larger or smaller. The range of border sizes varies from 0 to 3, where 0 represents smaller-size rounded corners and 3 represents la
2 min read
Bootstrap 5 Table borders
Bootstrap 5 Table borders classes are used to set or unset the border of the table. With bootstrap 5 table borders are easy to customize with border or no border. Bordered tables: This is used to set the border on each side of the table.Tables without borders: This is used to make the table borderless all over the table like there will be no row an
2 min read
Bootstrap 5 Borders Subtractive
Bootstrap5 Borders Subtractive is used to remove borders from the box by defining which side the border is to be removed or we can remove the border from all sides at once. Bootstrap 5 Borders Subtractive Classes: border-0: This class is used to remove borders from all around the elementborder-top-0: This class is used to remove the border from the
3 min read
Bootstrap 5 Borders Additive
Bootstrap5 Borders Additive classes are mainly used to display an outline around a box and it provides style, color, and radius of an element border on the side we want. For eg: if we want the border only on the top of the box we can have it by using the border-top additive class. Bootstrap 5 Borders Additive classes: border: This class is used to
2 min read
Bootstrap 5 Tables without borders
Bootstrap5 Tables without borders is used to create a table in borderless form. It is mostly used when we do not want to show the separation in the table content. Tables without Borders Class: table-borderless: This class is used to create borderless tables Syntax: &lt;table class="table table-borderless"&gt; ... &lt;/table&gt; Example 1: In this e
2 min read
HTML Table Borders
HTML Table Borders define the visible lines around cells and the overall table. They help in creating clear distinctions between various sections of the table, making it easier to understand and show information clearly. This attribute allows you to control the border's style, color, and width, for the visual presentation of your table. Syntaxtable
5 min read
Chakra UI Borders
Chakra UI is a popular React component library that simplifies the process of building user interfaces with a set of customizable and accessible components. Among those feature it also provide support for styling and layout including the management of borders. It provides various properties to customize borders. In this article, we will learn about
2 min read
Bootstrap 5 Borders
Bootstrap 5 Borders offer predefined border styles to elements. Classes like .border, .border-0, .border-top, .border-bottom, .border-left, and .border-right provide easy customization for borders, including color, width, and radius, enhancing UI design. iframe { width: 100%; height: 450px;} @media (max-width: 1145px) {.article--viewer .a-wrapper .
2 min read
How to draw a circle with gradient border using CSS ?
CSS is used to create various shapes and styles with different colors or gradient. In this article, we will learn how to draw a circle with a gradient border. Approach: We are going to create two div one is outer div with class outer_circle and another is inner div with class inner_circle. Outer div contains the big circle with gradient colour and
2 min read
How CSS transition work with linear gradient background button?
In CSS, you can smoothly make transitions between two or more colors. CSS has two types of gradients: Linear gradient: It goes down/up/left/right/diagonally and makes smooth transitions of colors. To make a linear transition you first have to choose two color stops. Color stops are the color among which you want to make the transitions. You can als
1 min read
Create a Gradient Text Effect using HTML and CSS
This article will show the approach to add a gradient effect on text using the background-clip CSS property. The final output of text using this effect is shown below. The CSS properties that would be used are flexbox, background-clip, and -webkit-background-clip and the background. HTML Section: This section contains the HTML markup that will cont
3 min read
Tailwind CSS Gradient Color Stops
This class accepts more than one value in tailwind CSS. All the properties are covered as in class form. It is the alternative to the CSS Gradients property. Gradient Color Stops classes: from-transparent: This class is used to set the start color transparency.from-current: This class is used to adopt the parent color for the element that will use
2 min read
How to apply background image with linear gradient using Tailwind CSS ?
In this article, we will see how to apply background images with a linear gradient using Tailwind CSS. Tailwind CSS is a highly customizable, utility-first CSS framework from which we can use utility classes to build any design. To apply background images with linear gradients we use the background image utility of Tailwind CSS. It is the alternati
2 min read
How to create linear gradient background using CSS ?
In CSS, we can use the background-color property to set the background color of an element to a specific color. Sometimes we want to add more styling to the element when setting the background color by using the linear-gradient property. CSS linear-gradient property lets you display smooth transitions between two or more colors. Syntax: background-
4 min read
How to create a gradient shadow using CSS ?
In this article, we will see how to create a gradient shadow using CSS, along with knowing the various CSS properties applied to get the gradient shadow effects. The gradient shadow means adding the gradient with shadow effect to the element. The gradient can be linear, radial, or cylindrical. Generally, the gradient shadow can be implemented on th
3 min read
Article Tags :