How to Make Gradient Button in HTML?
Last Updated :
14 Oct, 2024
Gradients are smooth transitions between multiple colors, offering a visually appealing and modern way to design elements. In HTML, gradients are typically applied using CSS.
We will discuss the different approaches to making gradient buttons in HTML:
Using Linear Gradients
A linear gradient creates a transition between colors along a straight line. The most basic way to create a gradient button is by using the background property with linear-gradient().
Gradient Direction:
- to right: Horizontal gradient from left to right.
- to left: Horizontal gradient from right to left.
- to top: Vertical gradient from bottom to top.
- to bottom: Vertical gradient from top to bottom.
- to top left: Diagonal gradient from bottom right to top left.
- to top right: Diagonal gradient from bottom left to top right.
- to bottom left: Diagonal gradient from top right to bottom left.
- to bottom right: Diagonal gradient from top left to bottom right.
Example: Below is an example of making a gradient button in html using a linear gradient.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<title>Gradient Heading and Button</title>
<style>
/* Flexbox to center content */
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
/* Full viewport height */
margin: 0;
}
/* Gradient heading */
h1 {
font-size: 3em;
background: linear-gradient(to right, #ff7e5f, #feb47b);
-webkit-background-clip: text;
color: transparent;
/* Make the text transparent */
}
.gradient-button {
background: linear-gradient(to right, #ff7e5f, #feb47b);
color: white;
border: none;
padding: 10px 20px;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
transition: background 0.3s ease;
}
.gradient-button:hover {
background: linear-gradient(to right, #feb47b, #ff7e5f);
}
</style>
</head>
<body>
<h1>Gradient Heading</h1>
<!-- Centered Gradient Button -->
<button class="gradient-button">Click Me</button>
</body>
</html>
Output:
Using Linear GradientA radial gradient gives a circular or elliptical color transition, starting from the center (or a specified point) of the button. In this case, radial-gradient() is used to create a circular gradient effect. The colors transition from the center outward, giving the button a dynamic look. The button also has a hover effect that slightly enlarges it.
Example: Below is an example to make a gradient button using radial gradient button.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<title>Radial Gradient Button</title>
<style>
.radial-gradient-button {
background: radial-gradient(circle, #ff7e5f, #feb47b);
color: white;
border: none;
padding: 10px 20px;
font-size: 16px;
border-radius: 50px;
cursor: pointer;
transition: transform 0.2s ease;
}
.radial-gradient-button:hover {
transform: scale(1.05);
}
</style>
</head>
<body>
<h1>Radial Gradient Button</h1>
<button class="radial-gradient-button">Click Me</button>
</body>
</html>
Output:
Radial Gradient ButtonUsing Gradient with Pseudo-elements
Another approach is to use pseudo-elements (::before or ::after) to create a gradient effect. This allows you to create more complex designs or add animations. In this case, we use the ::before pseudo-element to create the gradient. The ::before element is initially hidden using transform: scaleX(0), and on hover, it expands to cover the entire button, creating a smooth gradient transition effect.
Example: Below is an example to make gradient button in html with pseudo-elements:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<title>Gradient Button with Pseudo-element</title>
<style>
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
h1 {
font-size: 2.5em;
margin-bottom: 30px;
background: linear-gradient(to right, #ff7e5f, #feb47b);
-webkit-background-clip: text;
color: transparent;
}
.pseudo-gradient-button {
position: relative;
display: inline-block;
padding: 10px 20px;
font-size: 16px;
color: white;
border: none;
background: transparent;
cursor: pointer;
overflow: hidden;
z-index: 1;
}
.pseudo-gradient-button::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(to right, #ff7e5f, #feb47b);
z-index: -1;
transition: transform 0.5s ease;
transform: scaleX(0);
transform-origin: left;
}
.pseudo-gradient-button:hover::before {
transform: scaleX(1);
}
</style>
</head>
<body>
<h1>Gradient button with Pseudo-element</h1>
<button class="pseudo-gradient-button">Hover Me</button>
</body>
</html>
Output:
Using Pseudo-elements
Similar Reads
HTML Tutorial HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It tells the web browser how to display text, links, images, and other forms of multimedia on a webpage. HTML sets up the basic structure of a website, and then CSS and JavaScript
11 min read
HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML
14 min read
Top 10 Projects For Beginners To Practice HTML and CSS Skills Learning to code is an exciting journey, especially when stepping into the world of programming with HTML and CSSâthe foundation of every website you see today. For most beginners, these two building blocks are the perfect starting point to explore the creative side of web development, designing vis
8 min read
HTML Introduction HTML stands for Hyper Text Markup Language, which is the core language used to structure content on the web. It organizes text, images, links, and media using tags and elements that browsers can interpret. As of 2025, over 95% of websites rely on HTML alongside CSS and JavaScript, making it a fundam
6 min read
HTML Tags - A to Z List HTML Tags are fundamental elements used to structure and format content on web pages. They provide instructions to web browsers on how to render text, images, links, and other media.HTML tags are enclosed in angle brackets < > and usually come in pairs: an opening tag and a closing tag. The cl
15+ min read
30+ Web Development Projects with Source Code [2025] Web development is one of the most in-demand career paths in the IT industry, experiencing consistent growth of around 20â25% annually. Whether you're a student starting out or an experienced professional looking to switch or advance your career, it's essential to go beyond theory and demonstrate yo
4 min read
Frontend Developer Interview Questions and Answers Frontend development is an important part of web applications, and it is used to build dynamic and user-friendly web applications with an interactive user interface (UI). Many companies are hiring skilled Frontend developers with expertise in HTML, CSS, JavaScript, and modern frameworks and librarie
15+ min read
HTML DOCTYPE Declaration HTML DOCTYPE (Document Type Declaration) is an instruction that appears at the beginning of an HTML document, before the <html> tag.Its primary role is to tell the web browser which version of HTML the page is written in, ensuring that the browser renders the content correctly. It is not an HT
4 min read
HTML Forms HTML forms, defined using the <form> Tags are essential for collecting user input on web pages. They incorporate a variety of interactive controls such as text fields, numeric inputs, email fields, password fields, checkboxes, radio buttons, and submit buttons. Over 85% of websites rely on for
5 min read
HTML Tables HTML (HyperText Markup Language) is the standard markup language used to create and structure web pages. It defines the layout of a webpage using elements and tags, allowing for the display of text, images, links, and multimedia content. As the foundation of nearly all websites, HTML is used in over
10 min read