Building a Consistent Spacing Scale for Reusable UI Cards

This article demonstrates how to create a consistent spacing scale for reusable UI card components by defining spacing roles, implementing them in CSS, and validating the system against multi-line content variations, replacing ad-hoc pixel values with a maintainable spacing architecture.

Cilantro Loves Linux
Cilantro Loves Linux
Cilantro Loves Linux
Building a Consistent Spacing Scale for Reusable UI Cards

Requirements

The goal is to unify spacing for title, status, duration, and log-entry links across code-inspection and unit-test stage cards so that identical content relationships use identical distances.

Initial Implementation

The first version set padding and margins independently for each card type. Title-to-status gaps were 7px and 19px respectively; status-to-action distances also differed.

Initial interface
Initial interface

Figure 1: Two stage cards with independently set content spacing.

Problem Analysis

Major Issues

Although the cards share the same structure, the distances between title and status and between status and log entry differ. This creates inconsistent visual density and forces maintainers to calibrate each card separately.

The key is to unify the same type of content relationship , not to make every distance in the card identical.

Design Principles

Predefine a small set of spacing tiers to eliminate arbitrary tweaks. Tiers must be perceptibly different: small scales are tighter, large scales more open. For example, 12 to 16 is a ~33% jump, while 500 to 520 is only 4%. The same pixel delta has different perceptual impact at different scales, so simply mandating multiples of a base unit can still leave many near-duplicate options.

Optimization Implementation

Spacing Roles

Assign distinct tiers to three roles: title-to-status (12px), content-to-action (24px), and card-to-card gap (16px). Card padding is set to 24px. The exact numbers matter less than the rule that the same relationship reuses the same token, preserving intra-group and inter-group distinction.

CSS Implementation

.stage-grid { gap: 16px; }
.stage-card { padding: 24px; }
.stage-card h3 { margin: 0 0 12px; }
.stage-card p { margin: 0 0 24px; }

Apply these rules to all similar stage cards and avoid overriding with near-identical values on a per-card basis. In production, express the roles via shared design tokens.

Content Adaptation

Test with two-line stage names, longer status text, and varied log-entry links. Verify that natural height changes do not break grouping clarity. If action areas need alignment, handle it through layout (e.g., flexbox) rather than inserting custom whitespace per card.

Acceptance Verification

Adjusted interface
Adjusted interface

Figure 2: Same-type cards now share identical content-spacing rules.

Compare the two versions to confirm spatial consistency across repeated content; cross-check the stylesheet to ensure tokens are actually shared.

☐ Title-to-status and content-to-action distances are consistent across same-type cards.

☐ Intra-group, inter-group, and card-to-card distinctions remain clear.

☐ Under long stage names, content does not overlap and action ownership stays obvious.

Application Exercise

Unify spacing for code-inspection, unit-test, and image-build stage cards. Deliberately include a two-line stage name. Deliver a component sketch and a spacing-role table documenting which tier serves which relationship and how long content extends naturally.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

frontend developmentcomponent designCSSUI designdesign tokensvisual consistencyspacing system
Cilantro Loves Linux
Written by

Cilantro Loves Linux

Focused on Linux system operations and maintenance technology exchange, regularly publishing in-depth technical articles covering core areas such as system architecture, performance optimization, and security hardening. Whether you are a beginner or a seasoned expert, you can find valuable resources to enhance your skills and solve problems here. Follow us to explore the mysteries of Linux operations!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.