search
HomeWeb Front-endCSS TutorialCreating a Shooting Star Border Animation with Tailwind CSS

Creating a Shooting Star Border Animation with Tailwind CSS

In this blog post, we'll create a captivating "shooting star" border animation using Tailwind CSS. This effect gives a glowing, animated border to an input field that can catch the user's attention—perfect for call-to-action sections like email sign-ups or important notifications.

Demo

Before diving into the code, you can check out the live demo of the effect here: View in Tailwind Playground.

The Concept

The animation is achieved using Tailwind CSS's utility classes and pseudo-elements. We'll use Tailwind's after pseudo-class to create a conic gradient animation that spins around the input field, giving the illusion of a shooting star tracing the border.

HTML and Tailwind CSS Setup

Below is the HTML structure and Tailwind CSS classes needed to create this effect:

<div class="flex h-screen bg-black">
  <div class="z-10 m-auto overflow-hidden p-0.5">
    <div class="after:transparent relative h-14 w-[500px] rounded-md border border-white/50 bg-black after:absolute after:-inset-[1px] after:-z-10 after:h-full after:w-full after:animate-[spin_4s_infinite] after:bg-[conic-gradient(var(--tw-gradient-stops))] after:from-transparent after:from-40% after:via-50% after:to-blue-600 after:to-100%">
      <input type="text" placeholder="Join the waitlist, enter your email.." class="h-full w-full bg-transparent px-4 text-lg text-white placeholder:text-white/40 focus:outline-none">
    </div>
  </div>
</div>

Breaking Down the Code

Container Setup

  <div class="flex h-screen bg-black">




<ul>
<li>We start by creating a flex container that centers the content both vertically and horizontally with h-screen (full height) and bg-black (black background).</li>
</ul>

<h4>
  
  
  Wrapper for Input Field
</h4>



<pre class="brush:php;toolbar:false">  <div class="z-10 m-auto overflow-hidden p-0.5">




<ul>
<li>The input field is wrapped inside a div that has z-10 to ensure it is above the animated border, m-auto to center it within the flex container, and overflow-hidden to contain the animated border within its bounds.</li>
</ul>

<h4>
  
  
  Input Field with Animated Border
</h4>



<pre class="brush:php;toolbar:false">  <div class="after:transparent relative h-14 w-[500px] rounded-md border border-white/50 bg-black ...">




<ul>
<li>The main input field is set to a fixed width of 500px and height of 14 Tailwind units.</li>
<li>The border-white/50 class adds a semi-transparent border, while rounded-md gives it rounded corners.</li>
<li>
bg-black sets the background color to black, blending it with the container.</li>
</ul>

<h4>
  
  
  Creating the Animation
</h4>



<pre class="brush:php;toolbar:false">  after:absolute after:-inset-[1px] after:-z-10 after:h-full after:w-full after:animate-[spin_4s_infinite] after:bg-[conic-gradient(var(--tw-gradient-stops))] after:from-transparent after:from-40% after:via-50% after:to-blue-600 after:to-100%">
  • The after pseudo-element is used to create the conic gradient that will animate around the border.
  • after:-inset-[1px] slightly expands the gradient beyond the input's border, and after:absolute positions it absolutely to cover the entire input area.
  • after:animate-[spin_4s_infinite] adds a custom spin animation that completes one full rotation every 4 seconds.
  • The after:bg-[conic-gradient...] creates the gradient effect. We use the from-transparent and to-blue-600 classes to define the color stops, giving a fading effect that mimics a shooting star.

Input Field Styling

  <input type="text" placeholder="Join the waitlist, enter your email.." class="h-full w-full bg-transparent px-4 text-lg text-white placeholder:text-white/40 focus:outline-none">
  • The input itself is transparent (bg-transparent) and takes up the full height and width of its parent.
  • The text-lg class sizes the text, while text-white and placeholder:text-white/40 ensure that the text and placeholder are visible against the dark background.
  • Finally, focus:outline-none removes the default focus outline to maintain the custom styling.

Conclusion

With just a few lines of Tailwind CSS and the power of pseudo-elements, you can create eye-catching effects like this shooting star border animation. This effect is not only aesthetically pleasing but also easy to implement and customize for your own projects. Feel free to tweak the colors, timing, and other properties to fit your design needs!

Happy coding!

Cover Photo by Juskteez Vu on Unsplash

The above is the detailed content of Creating a Shooting Star Border Animation with Tailwind CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
CSS Animations: Is it hard to create them?CSS Animations: Is it hard to create them?May 09, 2025 am 12:03 AM

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframes CSS: The most used tricks@keyframes CSS: The most used tricksMay 08, 2025 am 12:13 AM

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

CSS Counters: A Comprehensive Guide to Automatic NumberingCSS Counters: A Comprehensive Guide to Automatic NumberingMay 07, 2025 pm 03:45 PM

CSSCountersareusedtomanageautomaticnumberinginwebdesigns.1)Theycanbeusedfortablesofcontents,listitems,andcustomnumbering.2)Advancedusesincludenestednumberingsystems.3)Challengesincludebrowsercompatibilityandperformanceissues.4)Creativeusesinvolvecust

Modern Scroll Shadows Using Scroll-Driven AnimationsModern Scroll Shadows Using Scroll-Driven AnimationsMay 07, 2025 am 10:34 AM

Using scroll shadows, especially for mobile devices, is a subtle bit of UX that Chris has covered before. Geoff covered a newer approach that uses the animation-timeline property. Here’s yet another way.

Revisiting Image MapsRevisiting Image MapsMay 07, 2025 am 09:40 AM

Let’s run through a quick refresher. Image maps date all the way back to HTML 3.2, where, first, server-side maps and then client-side maps defined clickable regions over an image using map and area elements.

State of Devs: A Survey for Every DeveloperState of Devs: A Survey for Every DeveloperMay 07, 2025 am 09:30 AM

The State of Devs survey is now open to participation, and unlike previous surveys it covers everything except code: career, workplace, but also health, hobbies, and more. 

What is CSS Grid?What is CSS Grid?Apr 30, 2025 pm 03:21 PM

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

What is CSS flexbox?What is CSS flexbox?Apr 30, 2025 pm 03:20 PM

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.