Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

How to Create SVG Animations with SVG, CSS, and JavaScript

Create SVG animations with declarative SVG elements, CSS keyframes and transitions, or JavaScript for interactive behavior. Includes working examples and accessibility guidance.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create an SVG animation by putting animation elements in the SVG markup, applying CSS keyframes or transitions, or controlling the SVG DOM with JavaScript. Use SVG elements for declarative attribute changes and path motion, CSS for visual effects expressible as CSS properties, and JavaScript when an animation must respond to interaction or application state. The examples below show each approach and how to account for reduced-motion preferences.

Choose an animation method

Method Best suited to Typical control
SVG animation elements Changing SVG attributes, transforms, or movement along a path Animation settings declared in SVG markup
CSS animations or transitions Changing CSS properties such as opacity, fill, or transforms Stylesheets, keyframes, and property changes
JavaScript and the SVG DOM Animation driven by events, data, or application state Script that accesses SVG elements and attributes

The choice also depends on where the SVG will be displayed. Inline SVG and SVG referenced in an image context may not support a particular animation mechanism in the same way, so verify the exact feature and delivery context in your target browsers.

Animate SVG attributes with markup

SVG animation elements let you declare changes inside the SVG. The main options include <animate> for changing an attribute or property, <set> for a discrete change, <animateTransform> for transforms, and <animateMotion> for movement along a path.

Working example: move a circle

<svg viewBox="0 0 300 100" xmlns="http://www.w3.org/2000/svg">
  <circle cx="0" cy="50" r="15" fill="blue">
    <animate attributeName="cx" from="0" to="300" dur="3s" repeatCount="indefinite" />
  </circle>
</svg>

Here, attributeName identifies the value being animated, from and to set its endpoints, dur sets the duration, and repeatCount makes the motion repeat. Change the animated attribute and its values to suit the shape and viewBox. For transforms, use <animateTransform> rather than treating a transform as one simple number. For path travel, <animateMotion> accepts a path and can rotate an object to follow the path tangent.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Check the embedding context

MDN describes <animate> as widely available across browsers since January 2020, but that is not a guarantee that every SVG animation feature behaves identically in all browsers or embedding modes. Test the exact feature in the browsers and context where the SVG will appear.

Animate SVG with CSS

Use CSS keyframes when the animated value is a CSS property. CSS transitions are useful when a property should change smoothly after a state change. The following inline SVG scales and fades a circle using a repeating keyframe animation.

Rank #2
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" aria-labelledby="title">
  <title id="title">Pulsing circle</title>
  <circle class="pulse" cx="50" cy="50" r="20" />
</svg>
.pulse {
  transform-box: fill-box;
  transform-origin: center;
  animation: pulse 1.2s ease-in-out infinite alternate;
}

@keyframes pulse {
  to { transform: scale(1.25); opacity: 0.65; }
}

The example is a starting pattern, not a guarantee that every CSS property works identically in every browser or SVG context. Check support for the specific property and where the SVG is embedded; CSS is not automatically faster or better than SVG animation elements.

Use JavaScript for interaction or dynamic behavior

The SVG DOM exposes SVG elements, attributes, and properties to scripts, and graphical objects can have event handlers. This makes JavaScript appropriate when animation depends on a user action, changing data, or application state. A simple event-driven example can update an SVG attribute directly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 60">
  <circle id="marker" cx="20" cy="30" r="12" fill="teal" />
</svg>
<button id="move" type="button">Move circle</button>
<script>
  const marker = document.querySelector("#marker");
  document.querySelector("#move").addEventListener("click", () => {
    marker.setAttribute("cx", "100");
  });
</script>

This changes the circle’s position when the button is clicked; it is not itself a timed animation. For timed or stateful motion, script can coordinate updates or trigger CSS classes, but the reviewed standards do not establish a need for any particular JavaScript library.

Support reduced motion and user control

Blinking, flashing, and some other motion can be problematic for people with vestibular disorders, epilepsy, migraine, or other sensitivities. For nonessential CSS motion, honor the operating-system preference with a reduced-motion rule:

@media (prefers-reduced-motion: reduce) {
  .pulse {
    animation: none;
  }
}

For SVG-markup animations or script-driven motion, also provide a suitable control or alternate state where appropriate. Do not assume a CSS media query by itself will pause every animation mechanism or control an SVG in every embedding context.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check and troubleshoot your animation

  • The animation does not appear: Check that the SVG is valid, the animated element is nested or targeted correctly, and the attribute name and values match the intended SVG element. Confirm that the browser supports the exact feature in the way the SVG is embedded.
  • A transform behaves unexpectedly: Use <animateTransform> for SVG markup-driven transform animation. For CSS transforms, define the transform box and origin deliberately, as in the CSS example.
  • CSS changes work inline but not from an image reference: Test the SVG in the intended delivery context. Inline SVG and SVG loaded as an image are not interchangeable for every animation mechanism.
  • The motion is inaccessible or distracting: Reduce or remove nonessential motion for users requesting reduced motion, and add a pause or disable control for animation that needs explicit user control.

Reliability and performance

There is no single method that is best for every animation. Prefer the simplest mechanism that expresses the change: SVG elements for declarative attributes or path motion, CSS for CSS-property effects, and JavaScript for interaction or dynamic state. Test on the target browser set and in the actual embedding mode; the available sources do not support a blanket speed ranking among these approaches.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

If your next step is capturing a webpage rather than authoring its animation, ScreenshotNeo is a website screenshot API and MCP server. A single GET request can return a PNG, JPEG, WebP, or PDF. For a runnable cURL example and API parameters, see the ScreenshotNeo documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server includes take_screenshot, get_page_info, and capture_pdf for AI agents and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for 1,000 free screenshots a month, with no card required.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.