How to Create an Effect to Change Button Color using HTML and CSS ? Last Updated : 15 Feb, 2021 Comments Improve Suggest changes Like Article Like Report The color-changing effect of a button is very common but what we are going to do a slightly advanced version of this effect. The background will change like a clip effect rotating at some particular angle. Approach: The approach is to provide two or three background and then rotating them on different angles. HTML Code: In this section, we will use HTML code to design the body structure. html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content= "width=device-width, initial-scale=1.0" /> <title>Button effect</title> </head> <body> <a href="#">GeeksforGeeks</a> </body> </html> CSS Code: In this section, we will follow some steps to design the button effect. Step 1: First, we set the position of button and then use text-decoration property to remove underline from link. Also, set the width, height, color and background color of a button. Step 2: Here we apply the second background with rotation using the before selector. We have used z-index to display this background at the top of other one. Step 3: Now, apply final background with a different degree of rotation using nested selection of both hover and before selector. Tip: You can change the degree of rotation to change the effect a bit according to your need. Below is the implementation of the above three steps. CSS <style> body { padding: 0; margin: 0; } a { position: absolute; top: 40%; left: 40%; transform: translate(-50%, -50%); width: 180px; height: 60px; color: white; text-decoration: none; text-align: center; padding-top: 30px; font-size: 20px; overflow: hidden; background: green; } a::before { content: ""; position: absolute; width: 0; height: 0; left: 0; bottom: 0; border-style: solid; border-color: #f00; border-width: 80px 100px; z-index: -1; transform: rotate(360deg); transition: 1s; transform-origin: left; } a:hover::before { border-color: #00f; transform: rotate(60deg); } </style> Complete Code: In this section, we will combine the above to section to make a color-changing effect on button using HTML and CSS. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Button effect</title> <style> body { padding: 0; margin: 0; } a { position: absolute; top: 40%; left: 40%; transform: translate(-50%, -50%); width: 180px; height: 60px; color: white; text-decoration: none; text-align: center; padding-top: 30px; font-size: 20px; overflow: hidden; background: green; } a::before { content: ""; position: absolute; width: 0; height: 0; left: 0; bottom: 0; border-style: solid; border-color: #f00; border-width: 80px 100px; z-index: -1; transform: rotate(360deg); transition: 1s; transform-origin: left; } a:hover::before { border-color: #00f; transform: rotate(60deg); } </style> </head> <body> <a href="#">GeeksforGeeks</a> </body> </html> Output: Comment More infoAdvertise with us Next Article How to Create an Effect to Change Button Color using HTML and CSS ? S sirohimukul1999 Follow Improve Article Tags : Web Technologies Web Templates Similar Reads How to Create Text Color Animation using HTML and CSS ? The text color can be changed according to the programmerâs choice using CSS @keyframes rule. In this article, we will see how to create text color animation using HTML and CSS. Preview:Approach:Create an HTML file with a centered <div> containing an <h2> element.Use CSS to reset default 1 min read How to create button hover animation effect using CSS ? Minimal rotating backdrop button hovers and click animation is a basic CSS animation effect where when the button hovers, the button's background color changes, and when the button is clicked, it scales down slightly. This animation is implemented using CSS pseudo-elements and transitions. The ::sel 3 min read How to Create Text Reveal Effect for Buttons using HTML and CSS ? Buttons are the most important user interface component for any website. It is very important to design the buttons in a creatively unique way. The text-reveal effect for a button is used when it is used to reveal some offer or exciting content for enhancing the user experience. Approach: The approa 2 min read How to create a shinny button using HTML and CSS ? Buttons are undoubtedly one of the most important components of any website or app. A button should be designed in such a way that it stands out of the other component so that it is becoming clear to the user where to click and what is the button used for. There are infinite ways in which a button c 3 min read How to Create a Transparent Button using HTML and CSS? Transparent buttons are a popular design choice in modern web development, as they create a sleek and minimalist look. By using CSS, you can easily create buttons with fully transparent or semi-transparent backgrounds. This article uses the background-color: transparent; property to design the trans 2 min read Like