Dark CSS

CSS Glowing Gradient Button Border Animation Effect

Facebook
Twitter
WhatsApp

project demo

HTml code

				
					<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Button Gradient Border Animation - Dark CSS</title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <button class="btn">
    <div class="text">
      Dark CSS
    </div>
  </button>
</body>

</html>
				
			

css code

				
					/* Reset default browser padding, margin and set consistent box model */
* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

/* Center content on the page with flexbox */
body {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #06064d;
    height: 100vh;
}

/* Create a custom CSS property that smoothly animates angles */
@property --angle {
    syntax: "<angle>";
    /* Type of value */
    initial-value: 0deg;
    /* Start angle for animation */
    inherits: false;
}

/* Main button container */
.btn {
    position: relative;
    width: 200px;
    padding: 3px;
    border: 0;
    outline: none;
    cursor: pointer;
    border-radius: 12px;
    background: #120909;
    overflow: hidden;
    /* Hide gradient overflow */
}

/* Animated conic border created using ::before pseudo-element */
.btn::before {
    content: "";
    position: absolute;
    background: conic-gradient(from var(--angle), cyan, hotpink, #341f97, cyan);
    opacity: 0;
    /* Hidden at first */
    transition: opacity .3s ease;
    inset: 0;
    /* Stretch to full button area */
    animation: rotate 2s linear infinite;
    /* Rotating gradient */
}

/* Inner text area of button */
.text {
    position: relative;
    background: #000;
    z-index: 1;
    text-align: center;
    font-weight: 600;
    letter-spacing: 1.5px;
    font-size: 1rem;
    font-family: system-ui;
    color: #e8e8e8;
    padding: 1rem;
    border-radius: 10px;
    text-transform: uppercase;
}

/* Show glowing conic border on hover */
.btn:hover::before {
    opacity: 1;
}

/* Animation of the custom angle property */
@keyframes rotate {
    to {
        --angle: 360deg;
    }
}