Free Tool

CSS Size Generator

Generate CSS width and height properties with multiple units, constraints, and responsive options. Perfect for quick CSS snippets.

Dimensions

Constraints (Optional)

Additional Properties

Generated CSS

.element {
  width: 1200px;
  height: 800px;
}

Common Size Presets

Multiple Units

Support for px, %, em, rem, vw, vh, and auto units for maximum flexibility.

Aspect Ratio

Modern aspect-ratio property support for responsive sizing without padding hacks.

Constraints

Add min/max width and height constraints for better responsive control.

Copy & Paste

One-click copy of generated CSS code ready to paste into your stylesheet.

Common Presets

Quick access to commonly used size patterns like hero sections and cards.

Object-Fit Support

Generate object-fit properties for images and videos with proper sizing.

Understanding CSS Size Units

Absolute Units

  • px (pixels): Fixed size, 1px = 1/96th of an inch. Best for precise control.

Relative Units

  • % (percentage): Relative to parent element's size. Great for fluid layouts.
  • em: Relative to current element's font size. Compounds when nested.
  • rem: Relative to root (html) font size. More predictable than em.
  • vw (viewport width): 1vw = 1% of viewport width. Perfect for responsive designs.
  • vh (viewport height): 1vh = 1% of viewport height. Ideal for full-screen sections.

Modern Properties

  • aspect-ratio: Maintains width-to-height ratio automatically. Replaces old padding-bottom hack.
  • object-fit: Controls how images/videos fit their container (cover, contain, fill, etc.).
  • max-width/min-width: Set boundaries for responsive sizing.

Best Practices

  • Use rem for font-relative sizing to respect user preferences
  • Use % or vw/vh for responsive layouts
  • Add max-width to prevent content from becoming too wide on large screens
  • Use aspect-ratio for media elements to prevent layout shift
  • Combine units: width: 100%; max-width: 1200px; for flexible containers