3D Animated Text with CSS: SVG Tutorial and Demo

3D Animated Text with CSS: SVG Tutorial and Demo - Image

Hi, I am going to introduce an amazing animation concept for your web page. I think you have to know a keyword SVG, yes SVG stands for Scalable Vector Graphics. SVG is used to define vector-based graphics for the Web application using HTML and CSS. One big thing is SVG graphics do not lose quality either zoomed or resized your page.


How This 3D Animated Text Effect Works

SVG provides the drawing surface

The effect uses SVG because text inside an SVG can be styled with a fill, outline, dash pattern, and coordinate system. The viewBox creates an internal canvas, so the same artwork can scale from a wide desktop banner to a narrow mobile container without redrawing every letter.

The <text> element draws the characters. Its x and y values position the baseline, while text-anchor="middle" lets the text stay centered around the middle of the SVG. SVG text does not wrap like an HTML paragraph, so keep the phrase short or provide a separate responsive heading.

Several copies create visual depth

One outlined word looks flat. The example repeats the same text several times, places every copy in the same coordinate system, and gives each copy a different stroke color and animation delay. The overlapping outlines create the impression of layers moving through the letters.

CSS SVG animated text workflow infographic
CSS SVG Text Animation

A reusable symbol keeps the markup manageable. Define the word once inside <symbol>, then reference it through <use>. Newer examples can use the unprefixed href attribute; test older browser requirements before using legacy SVG syntax.

Build a Better SVG Structure

Use an accessible name

Decorative layers should not be announced as several separate headings. Give the SVG a title and description, or place a normal HTML heading near it. Mark repeated visual copies with aria-hidden="true" when the accessible name is supplied elsewhere.

<section class="hero" aria-labelledby="hero-heading">
  <h1 id="hero-heading" class="visually-hidden">Legend Blogs</h1>
  <svg class="hero-text" viewBox="0 0 600 300" role="img" aria-labelledby="svg-title">
    <title id="svg-title">Legend Blogs animated text</title>
    <symbol id="s-text">
      <text x="50%" y="50%" dy="0.35em" text-anchor="middle">Legend Blogs</text>
    </symbol>
    <use class="text text-one" href="#s-text" aria-hidden="true"></use>
    <use class="text text-two" href="#s-text" aria-hidden="true"></use>
    <use class="text text-three" href="#s-text" aria-hidden="true"></use>
  </svg>
</section>

Prefer clear classes for layers

:nth-child() is useful for patterned selections, but named classes are easier for a beginner to change. Use one class for shared stroke rules and modifier classes for color and timing. This makes it obvious which layer is being edited.

Animate the Stroke with CSS

Dash array and dash offset

stroke-dasharray divides an outline into painted and unpainted segments. stroke-dashoffset moves those segments along the outline. When the offset changes in a keyframe animation, the colored portion appears to travel around the letters.

.text {
  fill: none;
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
  stroke-dasharray: 70 330;
  animation: text-stroke 6s linear infinite;
}
.text-one { stroke: #3cba54; animation-delay: -1.2s; }
.text-two { stroke: #f4c20d; animation-delay: -2.4s; }
.text-three { stroke: #4885ed; animation-delay: -3.6s; }
@keyframes text-stroke {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: -400; }
}

The animation name must match the keyframes name. If the name is misspelled, the SVG can still display correctly but remain still. Start with one layer while debugging, then add the other layers after the basic stroke moves as expected.

Choose colors and timing carefully

High-contrast colors are easier to read than several pale strokes on a white background. Negative delays make the copies begin at different points in the animation. If every layer uses the same delay, the layers may look like one thick border. If the delays are too far apart, a color can look detached from the word.

Make the Text Responsive

Let the viewBox scale the artwork

Set the SVG width with CSS instead of forcing a large fixed width. A rule such as width: min(100%, 900px) allows the illustration to fill available space while preventing horizontal overflow. Use height: auto so the aspect ratio remains stable.

.hero-text {
  display: block;
  width: min(100%, 900px);
  height: auto;
  margin-inline: auto;
}
@media (max-width: 520px) {
  .hero-text { stroke-width: 2; }
}

Test real content, not only the demo word

Different words have different widths and counters. Test letters with curves, narrow strokes, and descenders. If a longer heading does not fit, shorten the visual text and keep the complete meaning in a nearby HTML heading.

Accessibility and Reduced Motion

Offer a static alternative

Motion should decorate the message, not carry essential information. Use a readable text alternative and preserve enough contrast when animation is stopped. A reduced-motion rule can hide extra layers, remove the dash pattern, and leave one steady outline.

@media (prefers-reduced-motion: reduce) {
  .text { animation: none; }
  .text-two, .text-three { display: none; }
  .text-one { stroke: white; stroke-dasharray: none; }
}

Check performance

A few simple SVG layers are usually easier to maintain than a large collection of animated elements. Avoid stacking heavy filters over a full-screen heading. Test on a lower-powered phone, check the page while scrolling, and stop decorative effects when the design does not need continuous motion.

Debugging Checklist

  • If the word is invisible, check the stroke color, fill, background, and SVG dimensions.
  • If the word is misaligned, confirm every copy references the same symbol and viewBox.
  • If the animation is static, check the animation name, duration, and keyframe spelling.
  • If the effect clips, inspect parent overflow and leave room around rotated or stroked shapes.
  • If mobile text is crowded, reduce the size or use a shorter visual phrase.

FAQ

Can CSS create 3D text without JavaScript?

Yes. Layered SVG text, strokes, and CSS keyframes can create a depth-style effect without JavaScript.

Why are multiple SVG text layers used?

Each copy can have a different color and timing. Their overlap creates the appearance of moving depth around one word.

How do I change the colors?

Change the stroke value on each layer class and test the contrast with animation disabled.

How do I support reduced motion?

Use the prefers-reduced-motion: reduce media query to stop the animation and keep one static layer visible.

Conclusion

SVG supplies scalable text while CSS supplies the layered colors and movement. Begin with a short phrase, reuse one symbol, stagger the layers, and test the result at narrow widths.

A polished effect also needs a readable fallback, visible contrast, and reduced-motion support. Those details make the animation useful on real pages rather than only in a desktop demo.

In this example, I'll introduce a CSS trick:- :nth-child

.text:nth-child(5n + 1) {
  stroke: #3cba54;
  -webkit-animation-delay: -1.3s;
  animation-delay: -1.2s;
}

First look at here, see how it works :nth-child

(5 x 0) + 1 = 1 = 3rd Element
(5 x 1) + 2 = 7 = 7th Element
(5 x 2) + 3 = 13 = 13th Element

Using this CSS trick you can set stroke color and animation delay on your element. In the color section, you can choose your favorite color and animation delay accordingly browser compatibility.

In the HTML section, you need to implement SVG tag with some child nodes. For this example I have used a simple tag as multiple use cases for example:

<svg viewBox="0 0 600 300">
  
  <symbol id="s-text">
    <text text-anchor="middle" x="50%" y="50%" dy="0.35em">Legend Blogs</text>
  </symbol>
  
  <use class="text" xlink:href="#s-text"></use>
  <use class="text" xlink:href="#s-text"></use>
  <use class="text" xlink:href="#s-text"></use>
  <use class="text" xlink:href="#s-text"></use>
  <use class="text" xlink:href="#s-text"></use>
</svg>

Let's start from an HTML page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>3D Animated Text Example</title>
<link rel="stylesheet" href="lb_css.css" type="text/css" />
</head>
<body>
<svg viewBox="0 0 600 300">
  <!-- Symbol-->
  <symbol id="s-text">
    <text text-anchor="middle" x="50%" y="50%" dy="0.35em">Legend Blogs</text>
  </symbol>
  <!-- Duplicate symbols-->
  <use class="text" xlink:href="#s-text"></use>
  <use class="text" xlink:href="#s-text"></use>
  <use class="text" xlink:href="#s-text"></use>
  <use class="text" xlink:href="#s-text"></use>
  <use class="text" xlink:href="#s-text"></use>
</svg>
    
</body>
 
</html>

CSS page like this:

@charset "utf-8";
/* CSS Document */
@import url(https://fonts.googleapis.com/css?family=Open+Sans:800);
body {
  background: #fff;
  font: 5em/1 Open Sans, Impact;
  margin: 0;
}
.text {
  fill: none;
  -webkit-animation: stroke 6s infinite linear;
  animation: stroke 6s infinite linear;
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-dasharray: 70 330;
  stroke-dashoffset: 0;
}
.text:nth-child(5n + 1) {
  stroke: #3cba54;
  -webkit-animation-delay: -1.3s;
  animation-delay: -1.2s;
}
.text:nth-child(5n + 2) {
  stroke: #f4c20d;
  -webkit-animation-delay: -2.1s;
  animation-delay: -2.4s;
}
.text:nth-child(5n + 3) {
  stroke: #db3236;
  -webkit-animation-delay: -3.2s;
  animation-delay: -3.6s;
}
.text:nth-child(5n + 4) {
  stroke: #56d9ef;
  -webkit-animation-delay: -4.4s;
  animation-delay: -4.8s;
}
.text:nth-child(5n + 5) {
  stroke: #4885ed;
  -webkit-animation-delay: -5s;
  animation-delay: -6s;
}
@-webkit-keyframes stroke {
  100% {
    stroke-dashoffset: -400;
  }
}
@keyframes stroke {
  100% {
    stroke-dashoffset: -400;
  }
}

How to create 3D Animated Text with CSS

Related posts

(2) Comments

  • User Pic

    thanks

  • User Pic

    Great post!! I have try to used my web site .. thank you very much

Write a comment