DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober 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
World desk4 min

How to Use the CSS `fr` Unit in Grid Layouts

CSS Grid’s fr unit divides leftover space between flexible tracks. Learn how ratios, gaps, automatic minimums, and minmax() affect the result.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In CSS Grid, fr allocates a proportional share of the space left for flexible tracks after fixed track sizes and gaps are accounted for. Use equal factors such as 1fr 1fr for equal flexible columns, or 1fr 2fr for a 1:2 flex-factor ratio. If a track refuses to shrink, its automatic minimum size—and sometimes the grid item’s own content—may be the reason.

What does fr mean in CSS?

fr is the flexible length unit for CSS Grid tracks. The W3C CSS Grid Layout Module Level 2 specification defines it as “a fraction of the leftover space in the grid container.” The specification describes how flexible tracks share that remaining space.

As an Amazon Associate I earn from qualifying purchases.

That means 1fr is not automatically one percent or one fixed fraction of the container’s full width. Fixed-size tracks and gaps take space first, and track-sizing constraints can affect the final result. Flexible tracks divide the space available to them in proportion to their flex factors.

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

How do equal and unequal fr values work?

The number before fr is a flex factor. With two flexible tracks, 1fr 1fr assigns them equal factors; 1fr 2fr assigns the second track twice the factor of the first. The ratio describes how flexible space is shared, not a guarantee of exact final widths if content-based minimums or other sizing rules intervene. Fractional factors such as 2.5fr are valid. MDN’s <flex> reference documents the unit.

#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
.equal-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.wide-second-column {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1rem;
}

How do you combine flexible tracks with fixed sizes?

Use a fixed track for a region that should retain a set size and an fr track for the space-taking region. Remember that the gap is also part of the container space, so the flexible track receives what remains after fixed tracks and gaps are accounted for.

.layout {
  display: grid;
  grid-template-columns: 16rem 1fr;
  gap: 1.5rem;
}

Here the first column is fixed at 16rem; the second is flexible. If the grid container is too narrow for its fixed track, gap, and other constraints, the layout may still overflow—the fr value does not override those constraints.

How do you choose between a fixed column count and responsive repetition?

Use repeat(3, 1fr) when you want exactly three equal explicit tracks. Use auto-fill with minmax() when the repeated track count should respond to available space and each track needs a minimum size you choose for its content.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
/* Three equal columns */
.three-columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

/* Responsive count; choose a minimum that fits your cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 1rem;
}

In the responsive example, 14rem is an example floor, not a universal recommendation. Choose a minimum that suits the content and the space available. MDN’s Grid basics guide and its minmax() reference cover these patterns.

Rank #3
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

Why can a 1fr track overflow or refuse to shrink?

A bare flexible track has an automatic minimum size, effectively minmax(auto, 1fr) for a 1fr track. That minimum can be influenced by grid items and their content. A long unbreakable word, wide image, or other intrinsically wide content can therefore keep the track wider than expected.

If the track must be allowed to shrink below its content-based automatic minimum, set its minimum to zero explicitly:

.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

minmax(min, max) defines a track-size range. Its maximum may be an fr value, but its minimum may not. For example, minmax(200px, 1fr) gives the track a 200px floor and a flexible maximum; minmax(0, 1fr) permits the track minimum to reach zero. If the maximum is smaller than the minimum, the maximum is ignored and the minimum is used. MDN documents these rules.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Removing the track’s automatic minimum does not automatically make every item inside it fit. Depending on the markup and content, the item may also need wrapping, min-width: 0, or deliberate overflow handling. Choose the treatment that matches the content rather than treating minmax(0, 1fr) as a universal overflow fix.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to diagnose an unexpected Grid width

  1. Identify the flexible tracks. Check the computed or declared grid-template-columns or grid-template-rows values and note which tracks use fr.
  2. Account for space already used. Include fixed-size tracks and the grid’s gap values when considering what remains for flexible tracks.
  3. Check automatic minimums. Look for long unbreakable text, wide images, or other content that may establish a track’s minimum size. Try minmax(0, 1fr) only when the track should be allowed to shrink below that minimum.
  4. Choose the intended floor. Use a meaningful minimum such as minmax(200px, 1fr) when the track must not become narrower than the content can use; use a zero minimum only when that is acceptable.
  5. Inspect the grid item, too. If content still escapes the track, test wrapping, min-width: 0, or an appropriate overflow rule on the item. Verify the result with your actual markup and content.

Browser availability

MDN marks both the <flex> value and minmax() as Baseline Widely available; MDN gives March 2017 for <flex> and October 2017 for minmax(). Those dates do not specify individual browser versions. If your project targets a particular legacy browser, check MDN’s current compatibility information for that browser.

Or skip the browser setup

If you need screenshots of a page to inspect a Grid layout, ScreenshotNeo can return an image from one GET request. Its capture process accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, with response headers identifying the page verdict and billing status. Its MCP server provides screenshot, page-info, and PDF-capture tools for AI agents.

For example, capture a page as WebP with cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. ScreenshotNeo has a free plan with 1,000 screenshots per month and no card required; paid plans start at $5 for 3,000 screenshots. Learn about ScreenshotNeo or sign up for the free plan.

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

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

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.