Photo by Kari Shea on Unsplash

Animating HTML Links with CSS Transition

Christina Truong
7 min readNov 9, 2021

--

Prefer to watch a video? This article is a companion piece to my Decoded by Christina series on YouTube.

The CSS transition property does what it sounds like; it creates transitions! But more specifically, it controls the animation speed when changing a CSS style from one state to another. For example, changing the text color when hovering over alink. The hover is the state change.

Changing the state of an element usually requires some kind of user interaction like scrolling down the page or clicking on an object. Making changes based on user interactions usually requires JavaScript. But there is a way to create CSS-only interactions using pseudo-classes.

CSS pseudo-classes

A CSS pseudo-class is a special keyword, added to a selector, to define a specific state of an element. A common example is using :hover to change the style of a link when a user hovers over it with their mouse.

A common style convention for the link/hover interaction is to change the underline and/or the color styles. By default…

--

--

Christina Truong

Tech Educator. christina.fyi Twitter @christinatruong Instagram @christina.is.online