Published on

How To Make A Link Underline Animation With Tailwind CSS From Scratch

Tags
Link Underline Animation

What is Tailwind CSS?

Tailwind CSS is a utility-first CSS framework that focuses on creating personalized user interfaces quickly. It can gives you all the building blocks you are able to create personalized designs without having to fight to override irritating opinionated styles. Also, Tailwind CSS is a highly configurable, low-level CSS framework.

Link underline growing animation with tailwindcss

  • It can make the building process of Link Underline Animation ui component faster and more easily.
  • Enables building complex responsive layouts and components freely.
  • Minimum lines of CSS code in Link Underline Animation component file.

Free download of the Link Underline Animation's source code

<div class="min-h-screen bg-gray-100 py-6 flex flex-col justify-center sm:py-12">
	<div class="relative py-3 sm:max-w-xl sm:mx-auto">
		<a href="#" class="font-display max-w-sm text-2xl font-bold leading-tight">
			<span class="link link-underline link-underline-black text-black"> Hover to See the Effect </span>
		</a>
		<br>
		<br>
		<a href="#" class="font-display max-w-sm text-2xl font-bold leading-tight">
			<span class="link link-underline link-underline-black text-black"> Multi line text will <br>work fine too.</span>
		</a>
	</div>
</div>


<style>
	.link-underline {
		border-bottom-width: 0;
		background-image: linear-gradient(transparent, transparent), linear-gradient(#fff, #fff);
		background-size: 0 3px;
		background-position: 0 100%;
		background-repeat: no-repeat;
		transition: background-size .5s ease-in-out;
	}

	.link-underline-black {
		background-image: linear-gradient(transparent, transparent), linear-gradient(#F2C, #F2C)
	}

	.link-underline:hover {
		background-size: 100% 3px;
		background-position: 0 100%
	}
</style>

Install tailwind css of verion 2.2.4

Use the script html tag to import the script of Tailwind CSS of the version 2.2.4

<script src="https://cdn.tailwindcss.com"></script>
  • min-h-screen
  • bg-gray-100
  • py-6
  • flex
  • flex-col
  • sm:py-12
  • relative
  • py-3
  • sm:max-w-xl
  • sm:mx-auto
  • max-w-sm
  • text-2xl
  • text-black
  1. Set the minimum width/height of an element using the min-h-screen utilities.

  2. Control the background color of an element to gray-100 using the bg-gray-100 utilities.

  3. Control the vertical padding of an element to 1.5rem using the py-6 utilities.

  4. Use flex to create a block-level flex container.

  5. Use flex to create a block-level flex container.

  6. Control the vertical padding of an element to 3rem at only small screen sizes using the sm:py-12 utilities.

  7. Use relative to position an element according to the normal flow of the document.

  8. Control the vertical padding of an element to 0.75rem using the py-3 utilities.

  9. Set the maximum width/height of an element using the sm:max-w-xl utilities at only small screen sizes.

  10. Control the horizontal margin of an element to auto at only small screen sizes using the sm:mx-auto utilities.

  11. Set the maximum width/height of an element using the max-w-sm utilities.

  12. Control the text color of an element to 2xl using the text-2xl utilities.

  13. Control the text color of an element to black using the text-black utilities.

Conclusion

The above is a step-by-step tutorial on how to use Tailwind CSS to create a Link Underline Animation components, learn and follow along to implement your own components.