skip to content
VA Logo

Line animation

How to make a simple and effective effect with css animation

HTML layout:

<div class="box">
	<div class="box__line"></div>
	<div class="box__text">Scroll to explore</div>
</div>

CSS styles (using scss):

* {
	box-sizing: border-box;
}
html {
	width: 100%;
}
body {
	padding: 0;
	height: 100vh;
	display: flex;
	align-items: center;
	justify-content: center;
	margin: auto;
}
.box {
	position: relative;
	height: 100px;
	display: flex;
	cursor: pointer;
	&__line {
		position: absolute;
		top: 0;
		left: 50%;
		margin-left: -1px;
		background-color: black;
		width: 2px;
		height: 80px;
		animation: lineHeight 5s ease-in-out infinite;
	}
	&__text {
		display: flex;
		margin-top: auto;
		font-size: 12px;
		line-height: 20px;
		letter-spacing: 0.1em;
		text-transform: uppercase;
	}
}

@keyframes lineHeight {
	0% {
		transform: scaleY(1);
		transform-origin: bottom;
	}
	50% {
		transform: scaleY(0);
		transform-origin: bottom;
	}
	51% {
		transform: scaleY(0);
		transform-origin: top;
	}
	100% {
		transform: scaleY(1);
		transform-origin: top;
	}
}

All together in one example

See the Pen Line Animation by vladimir-vo (@vladimirvo) on CodePen.