Believemy logo purple

Make an arrow that expands when hovered over with CSS

Whether it's to make your users want to see your project, read your article or access a page on your website, presenting your link with an arrow will make it easier to catch your visitors' eye! Let's find out in this article how to animate this arrow to enhance your readers' experience.
Updated on December 9, 2024
Believemy logo

Whether you want to entice your users to view your project, read your article, or access a page on your website, presenting your link with an arrow will make it easier to catch your visitors' eyes! Let's discover in this article how to animate this arrow to enhance your readers' experience.

Image

 

Step 1

Let's start, as usual, with the HTML code.

HTML
<a href="https://believemy.com" class="btn">
      <div class="arrow"></div>
      View the website
    </a>

We simply create a link with a class btn.
We then add a div with a class arrow and the text of our link.

 

Step 2

Let's style the link.

CSS
.btn {
      text-decoration: none;
      font-size: 1.4rem;
      color: #ff4754;
      display: flex;
      align-items: center;
    }

We use flexbox (display: flex) to align the arrow and the link text side by side.

 

Step 3

Now let's take care of the arrow's line.

CSS
.btn .arrow {
      margin-right: 1em;
      height: 0.1em;
      width: 1.5em;
      position: relative;
      background: #ff4754;
      transition: all 0.2s;
    }

Here, we simply create the line of our arrow. The end of the arrow will be created using the pseudo-elements ::before and ::after.

 

Step 4

Let's style the end of our arrow.

CSS
.btn .arrow::before,
    .btn .arrow::after {
      content: "";
      position: absolute;
      right: 0;
      top: 0;
      background: #ff4754;
      height: 0.1em;
      width: 0.6em;
    }

We create two elements that will be positioned at the top right of the line we created in the previous step.

 

Step 5

Let's enlarge the arrow on hover and finish our arrow.

CSS
.btn:hover .arrow {
      width: 5em;
    }

Our code is so functional and we have thought it out so well that we just need to set the arrow's line width to 5em so that it automatically enlarges on hover of the link. Congratulations to us!

Category: Development
Believemy logo
Comments (0)

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

Try for Free

Whether you're scaling your startup, building your first website, or transitioning to a developer role, Believemy is your new home. Join us, grow, and let’s build your project together.

Believemy is with anyone