Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): draw Card default border inside padding for spacing fidelity (#3767)

Kenton Quatmance936408416e
diff --git a/.changeset/card-border-inset-padding.md b/.changeset/card-border-inset-padding.md
new file mode 100644
index 0000000000..b093a18e22
--- /dev/null
+++ b/.changeset/card-border-inset-padding.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Card: draw the `default` variant's border inside its padding and drop the invisible border from the other variants, so a card's total inset (border + padding) matches the spacing token exactly instead of being 1px larger on every side. (#3712)
+@kentonquatman
diff --git a/packages/core/src/Card/Card.tsx b/packages/core/src/Card/Card.tsx
index 1b2ea57a6e..6653f9dc8a 100644
--- a/packages/core/src/Card/Card.tsx
+++ b/packages/core/src/Card/Card.tsx
@@ -44,8 +44,10 @@ import {themeProps} from '../utils/themeProps';
* - Non-semantic palette: `blue | cyan | gray | green | orange | pink | purple | red | teal | yellow`
* Each uses the corresponding `--color-background-<name>` token (20% opacity tint).
*
- * All variants include a transparent border to prevent layout jitter
- * when switching variants. Themes can override borderWidth/borderColor.
+ * Only `default` draws a visible border. Its border width is subtracted from
+ * the padding so the total inset (border + padding) equals the padding token —
+ * keeping content geometry faithful to the spacing scale and identical to the
+ * borderless variants. Themes can override borderWidth/borderColor.
*/
export type CardVariant =
| 'default'
@@ -71,12 +73,18 @@ const styles = stylex.create({
'--_card-radius': radiusVars['--radius-container'],
borderRadius: 'var(--_card-radius)',
overflow: 'clip',
- borderWidth: borderVars['--border-width'],
- borderStyle: 'solid',
- borderColor: 'transparent',
},
+ // The border is drawn *inside* the padding — its width is subtracted from
+ // each side — so total inset (border + padding) equals the padding token
+ // rather than exceeding it by the border width.
withBorder: {
+ borderWidth: borderVars['--border-width'],
+ borderStyle: 'solid',
borderColor: colorVars['--color-border-emphasized'],
+ paddingInlineStart: `calc(var(--container-padding-inline-start) - ${borderVars['--border-width']})`,
+ paddingInlineEnd: `calc(var(--container-padding-inline-end) - ${borderVars['--border-width']})`,
+ paddingBlockStart: `calc(var(--container-padding-block-start) - ${borderVars['--border-width']})`,
+ paddingBlockEnd: `calc(var(--container-padding-block-end) - ${borderVars['--border-width']})`,
},
// Fixed-height cards scroll content; overflow: auto also clips to border-radius
scrollable: {
@@ -266,7 +274,6 @@ export function Card({
stylex.props(
styles.card,
variantStyles[variant],
- variant === 'default' && styles.withBorder,
hasFixedHeight && styles.scrollable,
dynamicStyles.sizing(
width ?? null,
@@ -296,6 +303,9 @@ export function Card({
!useThemeDefault &&
effectivePadding !== 4 &&
containerPaddingBlockEndVarStyles[effectivePadding],
+ // Applied after the container padding so the border-inset calc wins;
+ // it reads the --container-padding-* vars set above.
+ variant === 'default' && styles.withBorder,
xstyle,
),
className,