The Wayback Machine - https://web.archive.org/web/20240624205033/https://www.geeksforgeeks.org/how-to-make-border-popup-animation-for-buttons-using-css/
Open In App

How to make border popup animation for buttons using CSS ?

Last Updated : 30 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn how to make border pop animation for buttons for your website. To create the border popup animation, we use CSS Pseudo Elements.

A CSS Pseudo elements is a keyword added to a selector that lets you style to a specific part of the selected element. In order to create an animation of such kind, we need to create our website to look decent so that clients can stay on the website.

Example: In this example, we will the border pop-ups when we click on the button.

HTML




<!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">
    <link rel="stylesheet"
          href="styles.css">
</head>
 
<body>
    <button class="btn btn-border-pop">
        Border Pop
    </button>
</body>
 
</html>


CSS code: We make the pseudo-element bigger and then we will give it a border and then we will multiply * it with (-2) so that it makes a border from inside so that it gives a nice outside-in transition.

The following is the code for “styles.css” used in the above HTML code. We use var for the background color and border size. We can use transitions on top, left, right, and bottom. We can calculate -2 border size so that we make it away from the box.

styles.css

CSS




*,
*::before,
*::after {
    box-sizing: border-box;
}
 
body {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    margin: 0;
}
 
button {
    margin: 1rem;
}
 
.btn {
    background-color: var(--background-color);
    color: #222;
    padding: .5em 1em;
    border: none;
    outline: none;
    position: relative;
    cursor: pointer;
 
    --background-color: #E3E3E3;
    --border-size: 2px;
    --accent-color: #0AF;
}
 
.btn.btn-border-pop::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    border: var(--border-size) solid var(--background-color);
    transition: top, left, right, bottom, 100ms ease-in-out;
}
 
.btn.btn-border-pop:hover::before,
.btn.btn-border-pop:focus::before {
    top: calc(var(--border-size) * -2);
    left: calc(var(--border-size) * -2);
    right: calc(var(--border-size) * -2);
    bottom: calc(var(--border-size) * -2);
}


Output:

          



Similar Reads

How to Create Border Animation using CSS ?
The CSS border animation using hover is used to create border animation when we hover over a text. The concepts that we are going to use are before , after and hover selectors. It is highly recommend to go through all these selectors before moving any further in this article. Approach: The approach of this animation is to divide the animation into
5 min read
Bootstrap 5 Buttons Block buttons
Bootstrap 5 Block buttons are used to display the full-width responsive buttons. To make the block buttons, we will use .d-grid, and .d-flex classes. We can also use screen sizes classes to change the button sizes on different screen sizes. Block buttons used Classes: .d-flex: This class is used to display an element as a block-level flex container
2 min read
How to make smooth bounce animation using CSS ?
The smooth bounce animation can be done with the help of HTML and CSS. It will generate fun and desired outputs. For this project, a simple div with class ball is needed in HTML page: &lt;div class=&quot;ball&quot;&gt;&lt;/div&gt; We will switch to CSS for animation programming. Now, Flexbox is used to have the ball at the middle of the page and ma
3 min read
How to make a morph spinner animation using CSS ?
Morphing is the rotating animation of certain objects changing their shape. The changing of shape is called morphing. In this article, we will make a morph spinner that will act as a loading animation by using CSS. This method can also be used to make eye-catching card backgrounds, banners, buttons, and demo purposes of certain functions on the web
3 min read
How to Make Vertical Card Sliding Animation using only HTML & CSS ?
The vertical card slider serves as an engaging way to showcase content, such as profiles, products, or services, in a modern web design. In this tutorial, we'll see the creation of a visually appealing vertical card slider with smooth animation effects using HTML and CSS. Approach :Firstly use the HTML to structure the cards and their content.Now a
3 min read
Which one should we use 'border: none' or 'border: 0 '?
In this article, we will learn the validity of CSS border properties. We can specify the no border property using CSS border: none, border-width : 0, border : 0 properties. Syntax: border: none | 0 Differences: border: noneborder : 0For this property, the browser does not render.For this property, the browser renders border-color and border-width p
1 min read
How to create Popup Box using HTML, CSS and JavaScript ?
In this article, we will see how to create a pop-up box with the help of HTML, CSS, and JavaScript. Here we will create a Popup box that is functional through the Popup button, when is clicked the Popbox appears on the screen with the title and close button. PrerequisitesHTMLCSSJavaScriptApproachCreate the Popup structure using HTML tags, Some tags
3 min read
Design a Cookies Message Popup Template using HTML and CSS
In this article, we will design a Cookies Message Popup template using HTML and CSS. Cookies play a pivotal role in enhancing user experiences on websites by storing information about user preferences and interactions. The "Cookies Message Popup Template" is a simple and customizable solution for websites to inform users about using cookies. Table
3 min read
How to create a Popup Form using HTML CSS and JavaScript ?
To create a popup form using JavaScript, you can design a hidden overlay that becomes visible when triggered. We will use HTML for form elements, CSS for styling, and JavaScript to toggle the visibility of the overlay. This allows for a user-friendly and interactive way to display forms on your webpage without cluttering the main content. Preview A
3 min read
How to Create Popup Box using HTML and CSS?
Popup boxes are a valuable tool for improving user experience on websites. A Popup (or dialog box) is a modal window used to inform, warn, or receive input from the user. Pop-up windows should not be used as they prevent the user from accessing other aspects of the program until the pop-up window is closed. In this create popup box in HTML and CSS
4 min read
three90RightbarBannerImg