Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
CSS

How to Make Two Adjacent DIVs the Same Height with HTML and CSS

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Put both boxes in the same flex or grid container and let the layout stretch them to the height of the tallest one. Do not assign guessed fixed heights to the individual DIVs.

<div class="columns">
  <div class="column">Shorter content</div>
  <div class="column">Longer content<br>More content</div>
</div>
.columns {
  display: flex;
  gap: 1rem;
  align-items: stretch;
}

.column {
  flex: 1;
}

In a horizontal flex row, the tallest item establishes the row height and the other item stretches across that height. The same principle works with CSS Grid.

Use flexbox for two adjacent DIVs

Flexbox is usually the simplest solution when the main requirement is one row of columns. Flex items in a row stretch on the cross axis by default, so align-items: stretch is normally redundant but makes the intent explicit.

.columns {
  display: flex;
  gap: 1rem;
  align-items: stretch;
}

.column {
  flex: 1 1 0;
  box-sizing: border-box;
  padding: 1rem;
  background: #f2f2f2;
}

The item containing more text determines the row’s height. Its sibling receives the same outer height, including its padding and border according to the chosen box-sizing rule.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Make the columns wrap on small screens

If the boxes should sit side by side only when there is enough room, allow the flex row to wrap and change the direction at a narrow breakpoint.

.columns {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.column {
  flex: 1 1 20rem;
}

@media (max-width: 42rem) {
  .columns {
    flex-direction: column;
  }
}

When items wrap onto separate flex lines, stretching applies within each line; items on different lines are not required to have one shared height.

Use CSS Grid for row-and-column card layouts

Grid is a strong choice when the design is inherently a set of rows and columns, especially when cards may wrap into additional rows.

.columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.column {
  padding: 1rem;
}

Grid items in the same row stretch to that row’s track height, which is established by the tallest content in the row. minmax(0, 1fr) prevents long unbroken content from forcing a track wider than its available space.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Responsive Grid columns

.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1rem;
}

This allows cards to move to new rows as the available width changes. Equal height is guaranteed within each grid row, not across every card in the entire grid.

Equal outer boxes versus equal footers

Stretching equalizes the outer boxes. It does not automatically place buttons, links, or other footer content at the same vertical position when the cards have different internal structures.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

To pin a footer to the bottom of each card, make each card a vertical flex container and allow the main content area to grow.

.column {
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

.column__content {
  flex: 1;
}

.column__footer {
  margin-top: 1rem;
}
<div class="column">
  <div class="column__content">
    <h3>Heading</h3>
    <p>Variable-length content.</p>
  </div>
  <div class="column__footer">
    <a href="/details">Read more</a>
  </div>
</div>

Why fixed heights and margin hacks fail

  • Text wraps differently as the viewport, font, or language changes.
  • Images, borders, and padding can add to the rendered size.
  • Content added later can overflow a fixed-height box.
  • Manual margins synchronize one specific screenshot rather than the layout’s actual content.

Let the parent layout calculate the row height instead. Use a fixed height only when the design genuinely requires a fixed viewport or component dimension and overflow behavior has been deliberately designed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

If the boxes differ by one pixel

Inspect the element whose background makes the mismatch visible before changing the parent layout. A child border, padding, margin, or box-sizing rule can create an apparent one-pixel difference even when the layout is stretching both siblings correctly.

In the original SitePoint discussion, a responder traced the visible discrepancy to a 1px white bottom border on the final advertising-text item and suggested removing it from that last item:

.abs_top_items:last-child {
  border-bottom: none;
}

Debugging checklist

  1. Use browser developer tools to inspect both computed heights.
  2. Check child borders, especially on the last element.
  3. Check padding and margins on the parent and its children.
  4. Check whether one element uses box-sizing: border-box while another uses the default content-box model.
  5. Temporarily apply contrasting backgrounds and outlines to identify which box is actually different.
  6. Remove the smallest offending border or normalize the box-sizing rules instead of adding a compensating height.

CSS table-cell as an alternative

A table-like layout can also equalize adjacent siblings:

.columns {
  display: table;
  width: 100%;
  border-spacing: 1rem 0;
}

.column {
  display: table-cell;
  width: 50%;
  vertical-align: top;
}

This reproduces table-cell sizing behavior and can suit layouts that are naturally table-like. Flexbox generally provides more direct control over alignment, spacing, ordering, and distribution, while Grid is better when explicit rows and columns are central to the design.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choosing the right method

Need Recommended layout Reason
Two boxes in one horizontal row Flexbox One-dimensional alignment and spacing are straightforward.
Cards arranged in rows and columns CSS Grid Shared row tracks stretch items to the tallest card in each row.
Legacy table-like sizing behavior Table-cell display Uses table layout’s intrinsic equal-height behavior.
Buttons aligned at each card’s bottom Flex or Grid outer layout plus column flex inside each card The growing content area pushes the footer downward.

Browser support and testing

Flexbox and Grid are the current layout tools for this problem, but the sources for the original question do not provide a browser-version compatibility matrix. Test the exact browser versions your site supports, particularly if you must accommodate older Internet Explorer deployments. Do not treat a forum-era workaround as a blanket guarantee for every browser.

Complete example

<div class="cards">
  <article class="card">
    <div class="card__content">
      <h2>Short card</h2>
      <p>A small amount of text.</p>
    </div>
    <a class="card__footer" href="/one">Open</a>
  </article>
  <article class="card">
    <div class="card__content">
      <h2>Long card</h2>
      <p>More text makes this card taller, so the other card stretches to the same row height.</p>
    </div>
    <a class="card__footer" href="/two">Open</a>
  </article>
</div>
.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.card {
  display: flex;
  flex-direction: column;
  padding: 1rem;
  border: 1px solid #ccc;
  box-sizing: border-box;
}

.card__content {
  flex: 1;
}

.card__footer {
  margin-top: 1rem;
}

@media (max-width: 42rem) {
  .cards {
    grid-template-columns: 1fr;
  }
}

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.