Urgent.News

What's breaking now, across thousands of outlets.

Tech

Prototype hover, press and focus animation in SVG before you build the app

A mockup cannot tell you whether a button answers a press in 150 milliseconds or 600. You find out by using it. Building the real interaction means wiring state, routing and data first, so the cheap move is to prototype the motion on the screen itself, before the app exists. An SVG screen is a good place to do it. It is markup, CSS works on its elements, and the whole prototype opens in a browser…

Building an app requires more than just a simple mockup to determine how a button responds to user interaction. To truly understand the user experience, you need to prototype the motion on screen before the app is fully developed. One efficient way to do this is by using an SVG screen, which is a markup file that can be styled with CSS and opened in a browser tab for easy testing.

An SVG element allows you to create a button with a specific fill color and transform properties, such as the center of the shape. You can define the button's hover state using the :hover pseudo-class, changing the fill color to a lighter shade when the mouse cursor is over it. The :active state can be used to alter the button's appearance when it is being pressed, such as scaling it slightly.

The :focus-visible state can be set to provide visual feedback when the button is focused using the keyboard, making it more accessible.

To ensure that the button is reachable by the keyboard, you should assign a tabindex of 0 and a role to the element. This allows the :focus-visible state to work correctly. If you need to create a toggle effect, you can use an attribute like aria-checked to change the appearance of an SVG element. By toggling this attribute with a few lines of JavaScript on click or by pressing the Space or Enter keys, you can create an interactive toggle.

The prototype can be animated using CSS keyframes, like the rise animation that makes an element fade in and move up over 400ms. To accommodate users who prefer reduced motion, you can use a CSS media query to disable all animations when the user has indicated they prefer reduced motion. In this case, the transition and animation properties are set to none, and the visual appearance remains static.

In the testing process, you can use headless Chrome to simulate user interactions with real mouse and keyboard events. By reading back the computed styles, you can observe how the button changes state during hover, active, and focus events. A click event can set the aria-checked attribute, move an SVG knob, and change the fill color of the track.

Pressing the Space or Enter keys on a focused toggle should perform the same actions. Tabbing twice should bring focus to the button, and :focus-visible should apply the correct border stroke.

While the prototype was tested in headless Chrome, you should note that the behavior may differ on other browsers such as Safari or Firefox, as well as on touch devices. The prototype demonstrates that CSS is well-suited for handling states and short entrances, but for more complex animations that involve multiple steps or synchronized movements, a dedicated animation tool is recommended.

The SVG Lab is set to release its own animation product, the SVG Animate MCP, which will handle the screens and animations without the need for extensive coding. The live demo can be found on the SVG Lab blog, showcasing how to prototype UI animation before building the actual app.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

5 Places Custom React Hooks Make Your Code Better

You add a search box to a page. A timer delays the search until the user stops typing. Then another page needs the same behavior. You copy the timer, the effect, and the cleanup.

  • useDebouncedValue hook delays component updates until input settles
  • custom hook maintains latest input and debounced values in state
  • updates only occur after set delay, avoiding expensive work on each keystroke

Polymarket Trading Bots: How to Build the Decision Engine

Getting market data is easy. Deciding what to do with it is the difficult part. A Polymarket trading bot can connect to the API. It can stream market data. It can read an order book.

  • Polymarket trading bot uses API for market data
  • Decision engine normalizes market state for analysis
  • Engine compares model probability with market-implied probability

Why Your WebP Is Larger Than the Original PNG

Converting an image to WebP does not guarantee a smaller file. If your exported WebP outweighs the original PNG, check the image content and encoder settings before assuming the converter is broken.

  • Images with limited color palette compress well as PNG.
  • Lossy WebP increases file size due to color representation changes.
  • Adjust compression effort for better compression without lowering quality.

Modeling the Boundary Between Dispatch Data and QuickBooks Invoicing

At 3:30 p.m. on a Thursday, an invoice question can reveal a data ownership problem. QuickBooks may show the draft invoice, while the dispatch record contains the field reality: extra sourcing time, a…

  • Dispatch record contains definitive information like additional sourcing time and scope changes
  • QuickBooks governs accounts receivable, payroll rules, and invoice numbering
  • Structured Dispatch Reconciliation and sign-off process prevents data inconsistencies

More from Thursday 1 October →