Pixel-Perfect UI Restoration: Why Asset Slicing Is Harder Than Writing Components
Pixel-perfect design restoration is often assumed to be a component-writing problem, but the real bottleneck is asset slicing. This article explains why AI-generated pages look almost right yet lose visual quality, how to draw a clear boundary between DOM and raster assets, and how a four-layer slicing method, asset delivery standards, and a practical acceptance checklist turn subjective "something feels off" feedback into an engineering process. It also covers how to use AI coding tools effectively without letting them decide layer ownership.
Pixel-Perfect UI Restoration: Why Asset Slicing Is Harder Than Writing Components
1. The Most Underrated Step
Turning a product design mockup into a working React page is rarely a complex technical task. React, Next.js, and Tailwind CSS cover the vast majority of cases. Over the past year or two, AI coding tools have become capable of “generating code from an image,” inferring layout from screenshots, scaffolding components, and filling in styles and basic interactions. Many people assumed this kind of work would quickly become cheap.
After doing it once, the conclusion flips. Recreating the structure is now fairly easy. What consumes most of the time is asset slicing, often called “cutting assets.” When the mockup is not a tidy admin form page but a visually heavy product page with dense modules, complex backgrounds, and rich lighting layers—dark themes, fantasy themes, tarot themes—the generated result often has a typical “almost right” quality: the cards are there, the buttons are there, the module order is correct, but the overall feel is lost.
2. Symptom Profile: Why It Looks Right but Feels Wrong
Placing the generated page side by side with the original reveals four recurring symptoms.
- Modules drift apart: Each section works on its own, but there is no unified lighting and color environment between sections, so the page visually breaks into isolated islands.
- Backgrounds fragment: A background that should be continuous gets sliced into multiple tiled or repeatedly stacked pieces, producing seams, repeated textures, and misalignment.
- Layering and shadows go out of control: Masks, vignettes, and glows are stacked repeatedly, making some areas too dark with crushed detail, or introducing bright edges that should not exist.
- Proportions and text hierarchy drift: Card aspect ratios deviate from the mockup, and the font-size ladder across titles, subtitles, and body text gets flattened, erasing the intended information hierarchy.
These symptoms share one root cause: models tend to “describe everything with the DOM,” while a large amount of information in a mockup is inherently bitmap information—gradients, noise, volumetric light, depth of field, complex illustration. Approximating these with CSS is expensive and unreliable.
3. Core Principle: The Responsibility Boundary Between DOM and Bitmaps
The first rule of high-fidelity restoration is to define the responsibility boundary before writing components. A simple test:
- Use real DOM for content that carries semantics, accessibility, interactivity, or localization: titles, body text, buttons, forms, lists, status labels.
- Use raster assets for visual information that cannot be reliably expressed with a limited set of CSS properties: complex illustrations, characters and architecture, volumetric light, grain texture, depth-of-field blur.
- For anything in between, prefer CSS first and switch to bitmaps after two failed attempts: solid or gradient backgrounds, simple rounded corners and shadows, single-layer masks.
Illustrative decision logic:
// Pseudocode: asset slicing decision helperfunction decideLayer(node) {const needA11y = node.role || node.interactive || node.text;if (needA11y) return 'DOM';const cssExpressible =node.type === 'gradient' ||node.type === 'solid' ||(node.type === 'shadow' && node.layers <= 2);if (cssExpressible) return 'CSS';return 'RASTER'; // hand off to a raster asset}
Once the boundary is clear, prompt constraints like “reproduce it 1:1” or “do not improvise” lose most of their marginal value—because the disagreement is not about wording, it is about layer ownership.
4. Layering Methodology: The Four-Layer Slicing Method
Abstract any mockup into four layers first, then implement them one by one.
Bottom layer: environmental background
One complete, continuous background image that carries spatial relationships and the overall color tone. Never slice it horizontally per module and stitch the pieces back together—that is the direct source of fragmented backgrounds. If multi-viewport adaptation is required, use the same image withobject-fit: coverand a focal offset instead of stitching multiple images.Middle layer: main visuals
Subject illustrations such as characters, architecture, and objects, exported as separate images with a transparent channel so they can support parallax, movement, and responsive cropping.Upper layer: lighting and atmosphere
Glow, volumetric light, vignette, and noise are overlay semantics. Implement them as independent transparent layers with explicit blend modes and opacity to avoid crushed blacks from stacking.Top layer: UI elements
Card containers, text, buttons, icons. Build the card itself with DOM plus rounded corners, borders, and shadows; keep illustrations inside cards as bitmaps.
The container structure can be very plain:
<section className="relative isolate">{/* Bottom layer: continuous background */}<img src="/bg/scene.webp" className="absolute inset-0 h-full w-full object-cover" />{/* Upper layer: lighting overlay */}<div className="pointer-events-none absolute inset-0 bg-[radial-gradient(...)] mix-blend-screen" />{/* Top layer: real DOM content */}<div className="relative z-10 grid gap-6 md:grid-cols-3"><Card title="Entry" icon="/icon/a.svg" /></div></section>
isolate scopes the blend mode, and pointer-events-none keeps overlay layers from swallowing interactions. Both are extremely easy to overlook in practice.
5. Executable Conventions for Proportion, Masks, and Lighting
- Proportion: Establish a minimum size unit from key anchors in the mockup (card width, spacing, title baseline) and express it with a unified spacing scale instead of eyeballing adjustments everywhere.
- Masks: Prefer a single linear or radial gradient. When multiple layers are necessary, write each layer’s opacity into the design notes to prevent stacking from going out of control.
- Vignette and glow: Produce the vignette in one pass with an inset shadow or radial gradient; produce glow with
box-shadowor a blurred copy, and avoid stacking several kinds of blur at once. - Color consistency: Pull a set of primary, secondary, and semantic colors from the mockup, converge them into design tokens, and eliminate hardcoded approximations scattered across the code.
:root {--space-1: 4px; --space-2: 8px; --space-3: 16px; --space-4: 24px;--radius-card: 16px;--shadow-card: 0 8px 24px rgba(0, 0, 0, .35);--overlay-mask: radial-gradient(circle at 50% 40%, transparent 40%, rgba(0,0,0,.55) 100%);}
6. Asset Delivery Standards: The Hidden Cost of Slicing
Slicing is slow not because it is technically hard, but because assets are often not standardized. Agree on delivery standards before starting:
- Format: Use lossy compressed bitmaps for continuous backgrounds and keep the high-quality source; use an alpha-capable format for subjects that need transparency; use vectors for simple icons.
- Scale: Provide at least 1x/2x, and 3x when necessary; vector assets need no scale variants.
- Naming: Follow a “layer-module-state” convention, for example
bg-hero,fg-tarot-card-hover. - Size: Set a file-size cap per image and compress before committing anything over the limit; serve large images with responsive sizes and lazy loading.
- Consistency: Keep the same canvas size and safe margins for all slices in a module to avoid stitching misalignment.
If assets need hosting, the common approach is to put static assets in object storage, deliver them through a content delivery network, host build artifacts on a container platform, and use logging and monitoring with alerting to trace pipeline issues. Only generic capability categories are needed here; no specific vendor implementation is required.
7. Acceptance Checklist: Turning “Something Feels Off” into Checkboxes
- Is the background a single continuous image with no seams or repeated textures?
- Is the subject an independent layer that can move freely without tearing the background?
- Are lighting layers
pointer-events-noneand excluded from layout? - Is all text real DOM that can be selected, read aloud, and wrapped?
- Do card aspect ratios and spacing land on the design scale?
- Do dark areas retain detail, with contours still visible at the darkest point?
- Are above-the-fold critical assets given explicit sizes and a lazy-loading strategy?
- Does narrow-screen adaptation use cropping rather than distorted scaling?
8. Using AI Coding Tools Correctly
The tools are not useless; they need to be placed in the right position. A reliable division of labor is to let the tool produce component skeletons, style drafts, and interaction scaffolding, while humans decide layer ownership, asset slicing, and lighting overlays. After each generation round, run the acceptance checklist immediately and converge deviations into concrete items before iterating. Constraining “background must be a single image, text must be DOM, lighting must be an independent layer” is far more effective than constraining “do not improvise.”
9. Conclusion
The complexity of design restoration is not evenly distributed across the coding phase; it concentrates in asset slicing, an underrated prerequisite. Draw the boundary between DOM and bitmaps first, organize assets with the four-layer slicing method, and combine delivery standards with an acceptance checklist—then page quality problems shift from guesswork to engineering. Tools can accelerate writing React, but what determines fidelity is still how you slice the image.
