Live preview
Preview settings
Changes appear as you type. Use Tab to test keyboard focus.
⌘ / Ctrl + S saves locally
Animated Button through JS
HTML, CSS or Tailwind, and a little JavaScript. One button or a group of up to six.
By @Aayush895
Button submission checks
Checks will appear after the preview updates.
Buttons only: no full pages, forms, cards or navigation. Put scripts in the JavaScript tab. Tailwind uses utilities from HTML and JavaScript; use complete class names. Custom CSS supports plain CSS, without @apply, imports or plugins.
Accessibility quick check
Waiting for the rendered preview…
Try Tab, Enter and Space in the preview. Check the focus ring, hover and disabled states, then enable Reduce motion. These checks are guidance, not an accessibility certification.
Explore freely here. Remix to publish your version with credit to the creator.
About Animated Button through JS
Animated Button through JS is an animated CSS button by @Aayush895. Preview the interaction, customize its HTML, styles and JavaScript, or download the files with creator credit.
- Effects and categories
- Hover effects, Loading, Social, Animated
- Using this example
- Copy the HTML or download index.html, style.css and app.js. Test keyboard focus, motion and contrast in your own project.
Usage, Tailwind and licensing questions
Read the source files
HTML
<!-- Github Profile -> Aayush895, Animated Button through JS -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
http-equiv="X-UA-Compatible"
content="IE=edge"
/>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>Animated Button through JS</title>
<link
rel="stylesheet"
href="style.css"
/>
</head>
<body>
<div id="container">
<button
type="submit"
class="submit"
>
Submit
</button>
</div>
</body>
<script>
let submit_btn = document.querySelector(".submit");
submit_btn.addEventListener("click", () => {
submit_btn.innerHTML = "";
submit_btn.classList.add("submitting");
setTimeout(() => {
submit_btn.classList.remove("submitting");
submit_btn.innerHTML = "DONE!";
}, 3000);
});
</script>
</html>
CSS
* {
padding: 0;
margin: 0;
background-color: orange;
}
#container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: none;
}
.submit {
padding: 1rem 4rem;
cursor: pointer;
background-color: gray;
text-transform: uppercase;
letter-spacing: 1rem;
font-size: larger;
text-align: center;
color: white;
border-radius: 5px;
border: none;
box-shadow: 5px 10px 5px -6px rgba(0,0,0,0.75);
transition: linear .3s;
}
.submitting {
height: 50px;
width: 100%;
padding: 1rem 10rem;
cursor: pointer;
background-color: gray;
transition: linear .3s;
}
.submit:hover {
transform: translateY(1px);
box-shadow: 5px 10px 5px -8px rgba(0,0,0,0.75);
}
.submit.submitting::before {
content: "";
background-color: white;
width: 20px;
height: 20px;
position: absolute;
left: 1rem;
border-radius: 50%;
animation: loading 1s infinite ease-in;
}
@keyframes loading {
0% {
opacity: 1;
}
50% {
opacity: .4;
left: 9rem;
}
100% {
opacity: 0;
left: 18rem;
}
}