frontend.fyi
Overview

Using CSS masks to fadeout content

Some super interesting text or component, but faded out.

Variants:

.fadeout-horizontal {
mask-image: linear-gradient(
to right,
transparent,
black var(--fade-size, 5rem),
black calc(100% - var(--fade-size, 5rem)),
transparent
);
}
.fadeout-vertical {
mask-image: linear-gradient(
to bottom,
transparent,
black var(--fade-size, 5rem),
black calc(100% - var(--fade-size, 5rem)),
transparent
);
}
.fadeout-left {
mask-image: linear-gradient(
to right,
transparent,
black var(--fade-size, 5rem)
);
}
.fadeout-right {
mask-image: linear-gradient(
to left,
transparent,
black var(--fade-size, 5rem)
);
}
.fadeout-top {
mask-image: linear-gradient(
to bottom,
transparent,
black var(--fade-size, 5rem)
);
}
.fadeout-bottom {
mask-image: linear-gradient(
to top,
transparent,
black var(--fade-size, 5rem)
);
}
.fadeout-circular {
mask-image: radial-gradient(
circle,
black calc(100% - var(--fade-size, 5rem)),
transparent
);
}

Combining a linear gradient with a mask image in CSS, results in nice fadeout masks that you can add on top of any element you want.

These masks have a configurable CSS variable --fade-size that you can adjust to make the fadeout effect hide more or less of the content, without changing the class itself.