Creating Zebra Striped Text Effects with Pure CSS
Visual Breakdown
Three distinct text layers combine to produce the zebra stripe projection effect:
- Top layer: Black text shadow
- Middle layer: White text shadow
- Base layer: Zebra striped text content
Implementation Strategy
Layering Approach
Standard text-shadow properties create solid color shadows, but cannot generate striped patterns. The solution uses a different approach: black and white layers are shadows, while the zebra stripes form the actual text content.
Zebra Stripe Technique
Linear gradients create the striped pattern without image files:
- Use
background-imagewithlinear-gradientto genearte alternating black and white stripes - Apply
background-clip: textto render the gradient within text boundaries - Set text color to transparent to reveal the background pattern
Color Transparency
Make the text transparent too display the background gradient:
color: transparent;
-webkit-text-fill-color: transparent;
-webkit-text-fill-color is a non-standard property that overrides color when both are present. This ensures transparency even if other CSS rules might override the standard color property.
Complete Implementation
<div class="striped-text">Zebra</div>
<style>
.striped-text {
font-size: 100px;
font-weight: bold;
color: transparent;
-webkit-text-fill-color: transparent;
text-shadow: 6px -6px #000, 4px -4px #fff;
background-image: linear-gradient(
135deg,
#fff 0%, #fff 25%,
#000 25%, #000 50%,
#fff 50%, #fff 75%,
#000 75%, #000 100%
);
background-size: 6px 6px;
background-repeat: repeat;
-webkit-background-clip: text;
background-clip: text;
}
</style>
Code Explanation
- Font properties: Large, bold text makes the effect more visible
- Shadows: Two offset shadows create depth (black at 6px, white at 4px)
- Gradient: Alternating white and black sections at 25% intervals create stripes
- Background size: Controls stripe thickness (6px squares)
- Background clip: Restricts gradient rendering to text boundaries
- Color transparency: Allows background gradient to show through text