Article
3 Jul 2023
5 min read

How to develop creative Glow Button effect?

How to develop creative Glow Button effect?
Share this article

HOW TO MAKE YOUR WEBSITE DESIGN MORE APPEALING?

Read the article to the end to find a link to our Codepen — we've shared the source code for our custom glow button made with React.js, TypeScript/JavaScript, HTML and CSS/Scss.


At Overcode, we believe in paying attention to details, both in coding and product design.
In today's competitive corporate website landscape, unique design elements can help your website stand out from the rest. This is particularly crucial for companies aiming to establish a strong brand and a recognizable corporate style.


→ USER EXPERIENCE

Unusual and rare interface details contribute to enhancing the user experience. When users visit a corporate website, they seek not only information but also a well-designed and easily navigable interface that incorporates unexpected animations, interesting transition effects, or interactive buttons, making the User Experience (UX) more memorable.

To assist our colleagues in creating adorable UI interfaces, we share our code and ideas through a link on Codepen or detailed Reels on our Instagram profile.

→ FULL CODE

Button.tsx

const { useEffect, useMemo, useRef, useState } = React;

type Props = {
  children: ReactNode;
  onClick?: MouseEventHandler<HTMLButtonElement>;
};

const GlowButton: FC<Props> = ({ children, onClick }) => {
  const [offsetWidth, setOffsetWidth] = useState<number>(0);
  const [offsetHeight, setOffsetHeight] = useState<number>(0);

  const [translateX, setTranslateX] = useState<string>("-40%");
  const [translateY, setTranslateY] = useState<string>("-30%");

  const buttonRef = useRef<HTMLButtonElement>(null);

  // This function calculate button's position
  const getPosition = () => {
    if (buttonRef.current) {
      setOffsetWidth(buttonRef.current.offsetWidth);
      setOffsetHeight(buttonRef.current.offsetHeight);
    }
  };

  useEffect(() => {
    getPosition();
  }, []);

  const onMove = (e: MouseEvent) => {
    if (buttonRef.current) {
      const { pageX, pageY } = e;

      const rect = buttonRef.current.getBoundingClientRect();

      setTranslateX(
        `${pageX - rect.left - window.scrollX - offsetWidth / 2}px`
      );
      setTranslateY(
        `${pageY - rect.top - window.scrollY - offsetHeight / 2}px`
      );
    }
  };

  const styleValue = useMemo(
    () => ({
      transform: `translate(${translateX}, ${translateY})`
    }),
    [translateX, translateY]
  );

  return (
    <button
      className="glow-button"
      onClick={onClick}
      onPointerMove={onMove}
      ref={buttonRef}
    >
      {children}
      <div className="glow-button__glow">
        <div className="glow-button__glow-light" style={styleValue} />
      </div>

      <div className="glow-button__border">
        <div className="glow-button__border-light" style={styleValue} />
      </div>
    </button>
  );
};

ReactDOM.render(
  <GlowButton>Overcode</GlowButton>,
  document.getElementById("root")
);

button.scss

:root {
  --purple-1: #ead9ef;
  --purple-2: #0d0915;
}

body {
  height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--purple-2);
}

@mixin button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: 14px 30px;
  height: 50px;
  font-size: 14px;
  border-radius: 25px;
  cursor: pointer;
  outline: none;
  white-space: nowrap;
  user-select: none;
  appearance: none;
}

.glow-button {
  --bg-color: var(--purple-2);
  --text-color: var(--purple-1);

  @include button;

  background: var(--bg-color);
  color: var(--text-color);
  margin: 1px;
  position: relative;
  border: none;
  transition: all 0.15s ease;

  &__border {
    position: absolute;
    border-radius: 1000px;
    top: -2px;
    bottom: -2px;
    right: -2px;
    left: -2px;
    z-index: -1;
    background: #3b039b;
    overflow: hidden;

    &-light {
      background: #590285;
      z-index: 2;
      filter: blur(15px);
    }
  }

  &__glow {
    position: absolute;
    background: #9d00c5;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: -10;
    overflow: hidden;
    opacity: 0.4;
    transition: opacity 0.5s ease;

    filter: blur(15px);
    -webkit-filter: blur(15px);

    -webkit-backface-visibility: hidden;
    -moz-backface-visibility: hidden;
    -webkit-transform: translate3d(0, 0, 0);
    -moz-transform: translate3d(0, 0, 0);

    &-light {
      background: #3b039b;
      z-index: 3;
      opacity: 0;
    }
  }

  .glow-button__border-light,
  .glow-button__glow-light {
    position: absolute;
    width: 100%;
    height: 100%;
    transition: opacity 0.5s ease;
  }

  &:hover {
    .glow-button__glow {
      opacity: 1;
    }

    .glow-button__glow-light {
      opacity: 1;
    }
  }
}
Vitalina H.
Vitalina H.
Chief Marketing Officer
My mission is to help startups build software, experiment with new features, and bring their product vision to life.

Related content

Lorem ipsum dolor sit amet consectetur. Viverra aliquam nunc dui volutpat cursus ac.

Outsourcing software development for startups
14 Sep 2025
12 min read

Outsourcing software development for startups: Benefits, risks, and best practices

Explore the benefits, risks, and best practices of outsourcing software development for startups to scale efficiently while saving time and costs.

How to create PWA with React
3 Sep 2025
14 min read

React Progressive Web App: Guide on How to Create PWA with React

Our guide explains the framework for progressive web app development on React and describes the business benefits of a React PWA with real-world examples.

How to come up with an app idea
19 Jul 2025
12 min read

How to Come Up With an App Idea: Practical Strategies That Work

Learn how to come up with an app idea using practical strategies that help you identify real problems, build market-ready solutions, and attract investors.

SUBSCRIBE TO OUR NEWSLETTER

Subscribe to our newsletter to receive the latest updates on cloud trends, best practices, and case studies, all delivered straight to your inbox.

HAVE A GREAT IDEA? LET’S TALK ABOUT IT