Creating a button with a "fill" effect using CSS

In this article, we'll be taking a look at the secret to achieving this "filling" effect on a button!
•
Updated on August 14, 2026
•
2 min read
Believemy logo

Let's discover together in this article the secret to creating this "filling" effect on a button!

Image

 

Step 1

Let's start with the HTML code.

HTML
<a href="#">Wow ça swing !</a>

We could hardly do anything more easy!

 

Step 2

Let's style the link.

CSS
a {
  width: 200px;
  height: 60px;
  font-size: 1.3rem;
  font-family: arial, sans-serif;
  font-weight: 700;
  position: relative;
  color: white;
  z-index: 0;
  border: 1px solid #892cdc;
  background: black;
  overflow: hidden;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

In this step, we use flexbox (display: flex) to align the text inside our a tag horizontally and vertically.

Next, we specify that we want to hide elements that exceed our link because we are going to create a large background using the before pseudo-element.

This pseudo-element will cover the background of our button when hovering.

 

Step 3

Let's now style the pseudo-elements before and after.

CSS
a::before,
a::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  background: linear-gradient(45deg, #ff0000, #00f0f0, #00ff00, #0000ff, #ff0000, #00f0f0, #00ff00, #0000ff, #f00f0f);
  width: 100%;
  height: 100%;
  transform: scale(1.02);
  z-index: -1;
  background-size: 500%;
  animation: animate 20s infinite;
}

In this step, we create two elements using the pseudo-elements before and after.

These two elements have a multicolor background that we enlarge by 500% to keep the most beautiful part.

We increase the size of our elements using the transform property by 2%, which allows us to give the impression of already having rainbow borders on our element.

 

Step 4

Let's finish styling the link on hover.

CSS
a:hover::before {
  top: 0px;
  border-radius: 0;
}

When we hover over our button, we gradually display the pseudo-element and change its rounded corners to rectangular corners.

Here is the secret to creating this filling effect.

Category: Developers

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.

Believemy logo
Comments (0)

You need to be logged in to comment on this article: log in or sign up.

Read next

Create an animated 3D button using CSS

In this article, we'll find out how to create a three-dimensional button that will add a touch of softness and perspective to your projects!

December 9, 2024

Create an animated "rainbow" button with CSS

In this article, we'll show you how to create a rainbow button that comes to life when the mouse hovers over it. A modern and sensational effect guaranteed!

December 9, 2024

Creating an "Old School" button with CSS

Let's find out how to create an original button that's right up to date!

December 9, 2024

Creating a sinking button with CSS

The buttons on a site are the main triggers for action: styling them and making them dynamic is very important in your development process! That's the aim of this article.

December 9, 2024

Create an "architectural" design button using CSS

Creating a button where the borders split in two on hover may seem complicated, but nothing could be easier! Let's find out how in this article.

December 9, 2024

Creating a NEON button with CSS

Creating a button is one thing! But creating a button that your visitors want to click is something else entirely. In any case, this neon button will catch the eye of everyone who visits your pages.

December 9, 2024

Creating circled buttons on hover with HTML and CSS

For a menu or to encourage your readers to share your website, share buttons are essential elements to add to your website. Let's find out how to make them more modern with a "neon" effect that will surround the icon selected by your user.

December 9, 2024

Create a very modern hover on a link

Here's an easy way to create a very modern hover on a link! There are lots of possible effects for buttons and links: the better they look, the more likely your users will be to click on them.

December 9, 2024

Become the solopreneur you dream of being.

First project, career change, business launch: access our courses, practice on real-world cases, and move forward with clear guidance.