×

Hupspot guide to CSS aspect ratio

CSS Aspect Ratio Guide for Hubspot Developers

If you build or maintain pages for Hubspot, understanding how to control CSS aspect ratio is essential for clean, responsive layouts, especially when dealing with images, videos, and embedded content.

This guide explains the modern aspect-ratio property, shows how it compares to older padding hacks, and walks through practical examples you can reuse in landing pages, blogs, and custom modules.

What Is CSS Aspect Ratio and Why It Matters for Hubspot Layouts

Aspect ratio is the proportional relationship between width and height. Common aspect ratios include 1:1 (square), 16:9 (widescreen), and 4:3 (traditional video). In responsive design, it prevents layout shifts by reserving the right amount of vertical space before media finishes loading.

When you work with Hubspot templates or custom coded modules, consistent aspect ratios help you:

  • Keep image grids aligned on all devices
  • Prevent layout jumping as images and videos load
  • Maintain design consistency across blog posts and landing pages
  • Control how embeds resize in flexible containers

How the aspect-ratio Property Works in Hubspot Themes

The modern CSS aspect-ratio property lets you define a preferred width-to-height ratio directly on a block-level or replaced element. This is easier and more readable than older padding-based workarounds.

The basic syntax is:

.ratio-box {
  aspect-ratio: 16 / 9;
}

You can use either a fraction or a single number:

  • aspect-ratio: 1 / 1; for a square
  • aspect-ratio: 16 / 9; for widescreen
  • aspect-ratio: 4 / 3; for classic video
  • aspect-ratio: 0.75; equivalent to 3 / 4

When applied in a Hubspot layout, the browser uses this ratio to calculate height based on the available width and reserves that space up-front, which reduces cumulative layout shift.

Hubspot-Friendly Examples Using CSS Aspect Ratio

Below are practical patterns you can plug into your Hubspot stylesheets or module CSS to keep your design predictable.

Hubspot Image Cards With Fixed Aspect Ratio

For blog listing cards or image-based CTAs, you may want all thumbnails to share the same ratio, even if the original images differ.

.hs-card-image {
  aspect-ratio: 4 / 3;
  width: 100%;
  object-fit: cover;
  display: block;
}

In a Hubspot template, apply hs-card-image to the <img> element so images are cropped but consistently sized across cards.

Hubspot Video Embeds at 16:9

For YouTube or Vimeo embeds in Hubspot rich text modules or coded templates, you can give the wrapping container an aspect ratio to keep it responsive.

.hs-video-wrapper {
  aspect-ratio: 16 / 9;
  width: 100%;
}

.hs-video-wrapper iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

Wrap the iframe in a div with the hs-video-wrapper class to maintain the ratio while the width changes.

Hubspot Grid Layouts With Mixed Content

When building a card grid in a Hubspot theme, consistent aspect ratios keep titles, buttons, and excerpts aligned across columns.

.hs-card-media {
  aspect-ratio: 3 / 2;
  width: 100%;
  overflow: hidden;
}

.hs-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

This approach works for product listings, resource libraries, or any grid where visual balance matters.

Legacy Padding Hack vs. Modern Aspect Ratio in Hubspot

Before broad support for aspect-ratio, developers used a padding-based trick to preserve proportions. You will still see this older pattern in many codebases and some Hubspot templates.

Traditional Padding-Bottom Technique

The traditional method relies on percentage padding, which is calculated from the width of the element.

.ratio-16-9 {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 9 / 16 * 100 */
}

.ratio-16-9 > * {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

This works in older browsers, but it is less readable and requires extra wrapper markup, which complicates Hubspot modules and content editing.

Why Use aspect-ratio Instead in Hubspot

  • Simpler code: one line instead of multiple declarations and wrappers
  • More semantic markup with fewer nested divs
  • Easier maintenance for teams managing many Hubspot templates
  • Cleaner integration with modern layout systems like CSS Grid and Flexbox

Whenever browser support for your audience permits, prefer the native property and only fall back to padding hacks when absolutely necessary.

Implementing CSS Aspect Ratio in Hubspot Step by Step

Use this workflow to integrate aspect ratio into your Hubspot pages or themes.

1. Identify Components That Need a Stable Ratio

Start by auditing your Hubspot pages for elements that commonly cause layout jumps:

  • Blog featured images and listing thumbnails
  • Hero banners with background images
  • Video embeds and webinar recordings
  • Thumbnail galleries and resource cards

2. Choose the Best Aspect Ratio for Each Component

Select a consistent ratio that fits your design system:

  • 1:1 for neat, square grids
  • 4:3 for document previews or classic slides
  • 16:9 for video-first layouts and media sections

Note the ratio you choose so designers and developers on your Hubspot team can reuse it consistently.

3. Add Utility Classes to Your Hubspot Stylesheets

Create reusable utility classes that content editors can apply via module settings or HTML fields.

.hs-ar-1-1 { aspect-ratio: 1 / 1; }
.hs-ar-4-3 { aspect-ratio: 4 / 3; }
.hs-ar-16-9 { aspect-ratio: 16 / 9; }

In your Hubspot theme or coded files, editors can then apply hs-ar-16-9 to containers or media elements without writing custom CSS each time.

4. Combine Aspect Ratio With Flex and Grid

CSS aspect-ratio integrates smoothly with modern layout tools you already use in Hubspot themes.

.hs-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
}

.hs-card-grid .hs-card-media {
  aspect-ratio: 3 / 2;
}

This lets card media stay visually consistent while the number of columns adapts to screen size.

Testing and Browser Support for Hubspot Audiences

The aspect-ratio property has strong support in modern browsers. For most Hubspot installations targeting up-to-date browsers, you can use it without issue. When legacy support is required, consider:

  • Using the padding hack as a fallback in a separate class
  • Providing a simplified layout for older browsers
  • Testing key templates and landing pages in your analytics’ top browser versions

Run visual tests on core Hubspot pages such as the homepage, high-traffic blog posts, and lead-generation landing pages to confirm that content loads without jumps.

Further Learning and Hubspot Optimization Resources

The underlying CSS techniques covered here are based on the concepts explained in the official aspect ratio documentation and tutorials. You can explore the original reference for more code examples and details at this external guide on CSS aspect ratio.

For broader optimization around templates, performance, and search visibility beyond Hubspot itself, you can study advanced implementation strategies and audits from specialized consultancies such as Consultevo, then adapt their recommendations to your own environment.

By standardizing CSS aspect ratios in your Hubspot theme, you reduce layout shifts, improve visual consistency, and create a smoother experience for visitors across devices while keeping your codebase easier to maintain.

Need Help With Hubspot?

If you want expert help building, automating, or scaling your Hubspot , work with ConsultEvo, a team who has a decade of Hubspot experience.

Scale Hubspot

“`

Verified by MonsterInsights