LayerwiseLayerwise
  • Features
  • Pricing
  • Templates
  • Docs
DownloadDownload
FeaturesPricingTemplatesDocsAI Website BuilderVibe CodingPersonal Software
DownloadDownload
  1. Glossary
  2. /
  3. Layout

Padding vs margin

Also called margin vs padding or CSS box model

Padding is the space inside an element’s border, around its content, while margin is the space outside the border that pushes other elements away.

const SETTINGS = [
  { title: 'Mentions', text: 'When someone tags you in a comment.' },
  { title: 'Deploys', text: 'When a project you own goes live.' },
  { title: 'Invites', text: 'When you are added to a team.' }
];

export function NotificationSettings() {
  return (
    <section className='max-w-md'>
      {/* Margin: space outside the heading, pushing it away from what's above. */}
      <h2 className='mt-12 text-xl font-semibold'>Notifications</h2>
      {/* gap spaces the cards evenly, so none of them need margins. */}
      <div className='mt-4 flex flex-col gap-4'>
        {SETTINGS.map((setting) => (
          // Padding: room inside the border, filled with the card's background.
          <div key={setting.title} className='rounded-xl border bg-muted p-6'>
            <h3 className='font-medium'>{setting.title}</h3>
            <p className='text-sm text-muted-foreground'>{setting.text}</p>
          </div>
        ))}
      </div>
      {/* More padding makes the button itself bigger. */}
      <button
        type='button'
        className='mt-6 rounded-lg bg-primary px-5 py-3 text-sm font-medium text-primary-foreground'
      >
        Save changes
      </button>
    </section>
  );
}
Give the buttons 12px vertical and 20px horizontal padding so the labels have room inside, and space the cards in the list 16px apart with gap on the flex container instead of margins. Keep 24px of padding inside each card and 48px of margin above each section heading.

Paste into Layerwise or any AI coding tool.

Padding vs margin explained

Every element is a set of nested boxes, called the box model: the content in the middle, then padding, then the border, then margin. Padding adds room inside the element and takes on its background color, so a button with more padding looks bigger. Margin adds empty, transparent space outside the border, so it moves neighbors away.

A quick rule: if the space should feel like part of the element (a roomy button, a card with space around its text), use padding. If it is distance between separate things (between cards, below a heading), use margin, or better, gap on the parent flex or grid container, which spaces every child evenly with no margins at all.

Two details trip people up. In normal page flow, the vertical margins of stacked blocks overlap: a 24px bottom margin above a 16px top margin leaves 24px in total, the larger of the two. And by default an element’s padding is added to its width; box-sizing: border-box, which Tailwind turns on everywhere, counts padding inside the width instead.

Related terms

All terms

Flexbox

A CSS layout mode that lines items up in a row or a column and controls how they share space, align, and wrap.

CSS Grid

A CSS layout system that places items on rows and columns at once, so content lines up in both directions.

Container

A wrapper that caps content at a maximum width and centers it, so lines stay readable on wide screens and keep padding on small ones.

Card

A bordered, rounded container that groups one item’s image, title, details, and actions so it can sit in a list or grid with others.

Build it with Layerwise

Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.

DownloadDownloadRead the docs
LayerwiseLayerwise

Build full-stack web apps in minutes with AI.

Product

  • Features
  • Pricing
  • Download
  • Templates

Solutions

  • AI Website Builder
  • Vibe Coding
  • Personal Software

Resources

  • Documentation
  • Changelog
  • Blog
  • Vibe Coding Glossary
  • llms.txt
  • llms-full.txt

Company

  • About
  • Contact

Legal

  • Privacy
  • Analytics Privacy
  • Terms
  • Security
  • Abuse

© 2026 Layerwise. All rights reserved.

Entrances & exits

  • Fade in
  • Slide in
  • Scale in
  • Pop in
  • Blur in
  • Reveal animation
  • Enter and exit animations

Timing & sequencing

  • Duration
  • Delay
  • Keyframes
  • Tweening
  • Stagger
  • Orchestration
  • Fill mode
  • Stepped animation
  • Looping animation
  • Yoyo animation

Easing

  • Easing
  • Linear easing
  • Ease-in
  • Ease-out
  • Ease-in-out
  • Cubic-bezier
  • Asymmetric easing
  • Overshoot easing

Springs & physics

  • Spring animation
  • Stiffness
  • Damping
  • Mass
  • Bounce
  • Velocity
  • Momentum
  • Interruptible animation
  • Rubber-banding

Transforms

  • Translate
  • Scale
  • Rotate
  • Skew
  • 3D flip
  • Perspective
  • Transform origin
  • Origin-aware animation

State transitions

  • Crossfade
  • Morph
  • Shared element transition
  • Layout animation
  • Height auto animation
  • Direction-aware transition
  • Continuity transition
  • Page transition
  • View Transitions API

Scroll effects

  • Scroll reveal
  • Scroll-driven animation
  • Parallax scrolling
  • Scrollytelling
  • Scroll pinning
  • Horizontal scroll section
  • Scroll progress bar
  • Scroll snap
  • Smooth scrolling

Interaction feedback

  • Hover effect
  • Press feedback
  • Ripple effect
  • Shake animation
  • Hold to confirm
  • Drag gesture
  • Drag to reorder
  • Swipe to dismiss
  • Pull to refresh
  • Magnetic button
  • Custom cursor
  • 3D tilt card
  • Spotlight card

Text effects

  • Typewriter effect
  • Text scramble
  • Split text animation
  • Text morph
  • Rotating words
  • Gradient text
  • Shimmer text
  • Number ticker
  • Tabular numbers
  • Underline animation

Loops & ambient motion

  • Marquee
  • Pulse animation
  • Float animation
  • Orbit animation
  • Idle animation
  • Particle background
  • Border beam
  • Confetti
  • Animated gradient

Visual effects

  • Blur
  • Clip-path
  • Mask
  • Before/after slider
  • SVG line drawing
  • Lottie animation

Motion principles

  • Purposeful animation
  • Anticipation
  • Follow-through
  • Squash and stretch
  • Perceived performance
  • Frequency of use
  • Spatial consistency
  • Reduced motion

Animation performance

  • Frame rate (FPS)
  • Jank
  • GPU acceleration
  • will-change
  • Layout thrashing

Layout

  • Hero section
  • Above the fold
  • Sticky header
  • Sidebar
  • Bento grid
  • Card
  • Flexbox
  • CSS Grid
  • Padding vs margin
  • Responsive design
  • Container
  • Masonry layout
  • Split screen
  • Z-index
  • Overflow

Components

  • Button variants
  • Modal
  • Drawer
  • Popover
  • Tooltip
  • Dropdown menu
  • Context menu
  • Toast notification
  • Tabs
  • Segmented control
  • Accordion
  • Carousel
  • Command palette
  • Combobox
  • Toggle switch
  • Checkbox
  • Radio button
  • Date picker
  • Breadcrumb
  • Pagination
  • Infinite scroll
  • Badge
  • Avatar stack
  • Empty state
  • Skeleton screen
  • Spinner
  • Progress bar
  • Data table
  • Stepper
  • Floating label
  • Inline validation
  • Alert banner
  • Tag input

States & patterns

  • Interaction states
  • Focus ring
  • Loading state
  • Optimistic UI
  • Debounce
  • Lazy loading
  • Dark mode
  • Micro-interaction
  • Affordance
  • Undo
  • Drag and drop
  • Keyboard shortcut

Visual styles

  • Glassmorphism
  • Liquid glass
  • Neumorphism
  • Claymorphism
  • Neo-brutalism
  • Skeuomorphism
  • Flat design
  • Mesh gradient
  • Aurora background
  • Grain texture
  • Glow effect
  • Drop shadow
  • Border radius
  • Grid background
  • Typographic hierarchy
  • Accent color
  • Color contrast

Vibe coding & AI

  • Vibe coding
  • Prompt
  • Context window
  • Token
  • AI agent
  • Tool call
  • Hallucination
  • Diff
  • Live preview
  • Checkpoint
  • Git commit
  • Deploy
  • Frontend and backend
  • API
  • Database
  • Rules file
  • MCP
  • Plan mode
  • Visual edit
Back
Save
Share
Margin
6px
Padding
6px
Content
Save