whoami

Lucas Jenß

cat /etc/motd

The Coding Journal ツ — Notes taken on an epic coding journey. Technical solutions, debugging notes, and practical guides from the trenches of software development.

Close-up of white dominoes with black dots standing on green felt surface, shallow depth of field, focused mood

ls -la ~/languages/

total 8
drwxr-xr-x
▶ PHP
▶ Ruby
▶ Scala
▶ C#
▶ JavaScript
▶ Objective-C
▶ Shell Scripting

ls -la ~/toolchain/

total 7
drwxr-xr-x
▶ Typo3
▶ Akka
▶ Capistrano
▶ Git
▶ MAMP
▶ Adobe Illustrator
▶ NSTrackingArea (Cocoa)

uname -a

platforms
drwxr-xr-x
▶ Mac OS X
▶ Unix

A pure CSS SVG spinner with smarter viewBox geometry

A loading spinner sits in an awkward corner of interface design: it must be noticeable without dominating, remain legible on different screens, and never imply that an action has failed. Creating an SVG loading spinner with pure CSS and viewBox tricks solves the visual part cleanly, using one compact asset and a stylesheet rather than a JavaScript timer.

The useful idea is to let the SVG define a predictable coordinate system, then let CSS handle repetition, colour and motion. That separation also keeps the indicator reusable across a PHP admin panel, a TYPO3 template, a Rails view or a small Android companion screen. The animation is only half the job, though; accessible status text and honest loading states still belong in the markup.

Choose an animation method that fits

SVG works well here because paths and strokes remain sharp at any density, and currentColor lets the same spinner inherit button, panel or brand colours. A CSS rotation is also inexpensive compared with repainting a canvas on every frame. The browser composites a transformed graphic, which makes the loader suitable for dashboards and checkout screens where several small components may appear at once.

For a small interface indicator, these choices compare quickly:

Approach Motion source Flexibility Accessibility Typical use
Inline SVG with CSS CSS keyframes Excellent theming and scaling Semantic status text is still required Reusable interface indicators
SVG with SMIL <animateTransform> Good for standalone assets Behaviour varies between browsers Self-contained SVG downloads
Canvas with JavaScript Scripted redraw loop Full drawing control Status handling remains an application concern Complex pixel-based animation
Animated GIF Pre-rendered frames Limited colour and sizing control Limited accessibility options One-off decorative loaders

For this use case, inline SVG with CSS is the strongest balance. It avoids an extra network request, remains easy to theme, and can be switched by an aria-busy attribute without an animation library. Keep canvas for genuinely graphical work, SMIL for a self-contained exported file, and a GIF only when a single fixed asset matters more than theming.

Build the geometry around a stable viewBox

Start with a square coordinate system rather than dimensions borrowed from a design canvas. A viewBox of 0 0 50 50 tells the renderer that the visible drawing occupies fifty user units in each direction, even if CSS later renders the element at 24, 32 or 64 pixels. Because the circle is centred at 25, 25, its geometry stays balanced as the component scales.

<svg class="spinner" viewBox="0 0 50 50" aria-hidden="true">
  <circle class="spinner__track" cx="25" cy="25" r="20"></circle>
  <circle
    class="spinner__arc"
    cx="25"
    cy="25"
    r="20"
    pathLength="100"
  ></circle>
</svg>

The pathLength="100" attribute is the useful viewBox trick in this example. It gives the circle a normalised length of 100 units, so a dash pattern such as 18 82 always represents the same proportion of the ring, regardless of its real length. You can therefore tune the visible arc with percentage-like values without recalculating the circumference or changing the radius.

Keep the stroke centred on the path and leave enough room for its width. A radius of 20 inside a 50-unit box leaves a five-unit margin, suitable for a five-unit stroke with rounded ends. Avoid percentages inside SVG attributes, because exported artwork can behave differently when a design tool changes the viewBox or when the SVG is nested in another document.

Designers who start in Illustrator should also export carefully, because duplicated IDs, expanded strokes and cropped artboards can make an SVG look correct while carrying unsuitable geometry. The notes on Adobe Illustrator SVG fixes cover useful cleanup steps that prevent clipping and scaling surprises once a loader is embedded in a page.

Animate the ring without JavaScript

Now animate the root SVG. A linear rotation avoids the uneven speed of an ease-in-out loop, while transform-box: view-box and a centred origin make the movement predictable in browsers that apply CSS transforms to SVG content.

.loading {
  display: none;
  align-items: center;
}

[aria-busy="true"] .loading {
  display: inline-flex;
}

.spinner {
  inline-size: 2.5rem;
  aspect-ratio: 1;
  color: #005ea8;
  animation: spinner-turn 800ms linear infinite;
  transform-box: view-box;
  transform-origin: center;
}

.spinner__track {
  fill: none;
  stroke: currentColor;
  stroke-opacity: 0.2;
  stroke-width: 5;
}

.spinner__arc {
  fill: none;
  stroke: currentColor;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 18 82;
}

@keyframes spinner-turn {
  to {
    transform: rotate(1turn);
  }
}

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

The application only needs to change the aria-busy attribute when a request starts and finishes. No timer, requestAnimationFrame loop or animation library is involved, and the spinner is removed from the rendering tree when it is not needed. Keep the visual SVG hidden from assistive technology and provide a separate live region with text such as “Loading results”.

CSS can animate stroke-dashoffset for a pulsing arc instead, but rotating the whole ring usually reads more clearly and creates less visual churn than continually changing a dash pattern. If you use the dash technique, test the cap shape and reduced-motion variant. Avoid rapidly alternating opacity, since a flashing effect can be uncomfortable and may obscure short loading states.

Tune the spinner for real screens

Small details determine whether a spinner feels native or ornamental. Treat size, colour and duration as part of the component contract, not as values copied blindly from a popular icon.

Layout and colour checks

  • Use inline-size with aspect-ratio: 1, then choose a size suited to the surrounding control or status area.
  • Check the rendered result on high-density and low-density screens, including the smallest size used in a compact toolbar.
  • Inherit the stroke from currentColor and verify that the track remains distinguishable against light and dark backgrounds.

Timing needs to be long enough to perceive without making a quick response appear slower. A cycle around 800 milliseconds works for many interfaces; slower requests can use the same indicator while additional text supplies context.

Motion and timing checks

  • Test the complete cycle at 700 to 1,000 milliseconds and confirm that it does not compete with nearby content.
  • Honour prefers-reduced-motion with a static arc or restrained alternative, backed by visible or accessible status text.
  • Keep state changes calm; avoid loops that flash, expand rapidly or suggest that the underlying operation has failed.

Keep the indicator honest and accessible

Australian use adds some practical constraints. Picture a Melbourne commuter checking a delivery on an Opal trip, a Brisbane customer confirming a mobile order, or a regional user waiting on an NBN Fixed Wireless or Satellite connection. Customers in Sydney, Melbourne and Brisbane often move between train, street and home connectivity, so the loader should preserve its size and meaning when the network fluctuates.

That resilience matters in the local market: Australian shoppers expect responsive feedback on stores such as Kogan and The Iconic, while Australian software companies such as Canva and Atlassian have made fast, unobtrusive interface states familiar. A spinner is not a substitute for useful copy, but it can stop a delayed interface from looking broken during a checkout or dashboard update.

Accessibility and privacy should shape the implementation too. The Australian Government Digital Service Standard requires federal services to meet WCAG 2.1 AA, providing a strong benchmark for motion, contrast and status communication. If telemetry attached to the loader records an IP address or user agent in a way that identifies a person, the Privacy Act 1988 and Australian Privacy Principles may apply. Keep animation analytics separate unless there is a clear, lawful purpose, and assess the actual data flows rather than assuming that a decorative spinner is automatically exempt.

Put the spinner into production

Production use is mostly about integration. Inline the SVG only where the browser can share the same aria-busy region, or serve it as a cached symbol when it must repeat many times. Keep the CSS in the compiled asset pipeline, avoid a framework-specific component if the same loader is needed in an email template or static TYPO3 page, and include the reduced-motion rule in the shared stylesheet.

Test the real state transitions as well as the final frame: start the request, delay it, fail it and replace the loader with an error message. When the indicator represents work that continues independently of a browser request, it needs a genuine job state; this Python cron-style scheduler offers a useful cron-like pattern for organising recurring command-line tasks and exposing their progress.

Create the component in a real feature today: add the markup, connect aria-busy to the request lifecycle, and verify the spinner, reduced-motion fallback and failure message on a phone before shipping.


cat ~/interests.json

KeyValue
editorTerminal-first workflow
osMac OS X / Unix
vcsGit, distributed version control
deployCapistrano, cron automation
graphicsSVG, Adobe Illustrator troubleshooting
networkingIP validation, SSH, VPN

git log --oneline --reverse

2013-10-30

Solving SVG import issues in Adobe Illustrator CS6 and CC

When importing an SVG into Illustrator, the operation fails with an unknown error [CANT]. A workaround for this Adobe-side bug.

2013

Solving NDK build issues on OS X

Troubleshooting native development kit compilation problems on Mac OS X.

2013

Programmatically adding PHP generated TypoScript to the backend configuration

Integrating dynamically generated TypoScript into Typo3 backend setups using PHP.

2013

ArgumentError: Could not parse PKey: no start line

Debugging an SSH key parsing error encountered during deployment.

2011-08-04

Validating IP-Addresses in PHP

Using PHP filter functions with flags like FILTER_FLAG_IPV4 and FILTER_FLAG_IPV6, and understanding how filter_var handles reserved IP addresses.

2011-07-09

Cocoa: Using NSTrackingArea

A short tutorial on using Cocoa's NSTrackingArea to capture mouseEntered and mouseExited events.


cat ~/contact.txt

github: github.com/x3ro
stackoverflow: x3ro
coderwall: coderwall.com/x3ro
twitter: @x3rames