How To Use a CSS Grid Template Area & Why It Can Save You Time

June 11, 2021
0 minute read

For website professionals, saving time on website builds and mockups is a must to stay competitive and profitable. One way to satisfy this business need is to use CSS grid templates and CSS grid template areas.

Many modern websites are built using grids, which divide a page into major regions and define the relationship between elements in terms of size, position, and layer. Grids make it easy to place elements into both columns and rows.

This means that whether you use code to create a CSS grid template, choose from grid template starters, use a theme built via grids, or use some plug-and-play design elements in a website builder like Duda, it pays to understand how CSS grid templates and grid template areas work.

The power of CSS grid is incorporated into Duda’s editor via DudaFlex sections, which enable digital marketing agencies and their customers to create pixel-perfect designs at breakneck speed inside our intuitive drag-and-drop site editor. With DudaFlex, you get the power of CSS grid-based designs in a fraction of the time it would take to develop them using the traditional coding methods outlined below.

CSS Grid Template Area Basics

A CSS grid template area makes a visual representation of the grid using both columns and rows. This makes for a faster design process than when line-based placement or grid-column and grid-row values are used. 


Why?


Using line-based placement isn’t as streamlined as grid template areas. And, as UI/UX Designer & Front-End Developer Ahmad Shadeed points out, when you change one element in grid-column, like the width of the sidebar span, you also have to individually change the width of the footer, main element, and other elements. 


With a CSS grid template area, you set the width in a single command and then the placements of the grid cells — and everything adjusts accordingly.


Another benefit to CSS grid template areas: they are responsive.

How To Use CSS Grid Template Areas

To reap the time saving benefits of designing with this method, build a CSS grid template and name your CSS grid template areas in two CSS coding steps. Common grid template areas to specify include header, menu, footer, sidebar, main content, etc. Once these are set up, they’re easy to move around within your grid template.


First, define names of your grid template areas with the grid-area property. This sets up the next step, which will create the grid-template layout.

For instance, below is an example from Mozilla that sets the grid areas with shortcuts for header, footer, content, and sidebar.

 

.header {

    grid-area: hd;

}

.footer {

    grid-area: ft;

}

.content {

    grid-area: main;

}

.sidebar {

    grid-area: sd;

}


Second, use grid-template areas property to define how the areas appear in the rows and columns. This creates your easy-to-use webpage template.

For instance, in the example below from Mozilla, the first line command sets the display as a grid. In the next line command, the columns are defined as “9” items long. In the next line command, the rows are set. Then, the CSS grid template areas are given their arrangements.

 

wrapper {

    display: grid;

    grid-template-columns: repeat(9, 1fr);

    grid-auto-rows: minmax(100px, auto);

    grid-template-areas:

      "hd hd hd hd   hd   hd   hd   hd   hd"

      "sd sd sd main main main main main main"

      "ft ft ft ft   ft   ft   ft   ft   ft";

}


As you see in the code above, you need to use the grid-template areas (names of your content areas) multiple times to add up to the number of columns in your grid template. The header “hd” above gets all nine widths in the column. In the next row, the sidebar as defined as “sb” in the code above gets three widths in the column, and the main content gets six widths of the column. In the third row, the footer gets all nine column widths.


Here is the HTML that follows the CSS. The HTML populates the grid template with the actual content.

 

<div class="wrapper">

    <div class="header">Header</div>

    <div class="sidebar">Sidebar</div>

    <div class="content">Content</div>

    <div class="footer">Footer</div>

</div>


And here is the result:

a diagram of a web page showing the header, sidebar, content area and footer.

Understanding the Code

You can use the shorthand CSS fraction code (fr), meaning fraction of the free space. The fraction command eliminates overflow on the x-axis even when you set a grid-column-gap value. With the fraction command, when, as in the above example, you set each column to “1fr,” the grid accounts for the grid-column-gap value and subtracts it from the total width for each column. 


You can also use the shorthand repeat code like above to make the columns repeat. For example, “grid-template-columns:repeat (9, 1fr);” shows the combined commands that specify the fraction code and the number of columns. For 6 columns or 12 columns or 15 columns, you would change the value after it repeats.


You also can easily control other ways the grid template appears.

For instance: 

  • You can set the grid-gap.
  • You can set a background color.
  • You can set padding.



Here’s another example, which uses the “container” command instead of the “wrapper” command.

 

.item-1 {

  grid-area: head;

}

.item-2 {

  grid-area: main;

}

.item-3 {

  grid-area: side;

}

.item-4 {

  grid-area: footer;

}


.container {

  display: grid;


  grid-template-columns: 2fr 2fr 1fr 2fr;

  grid-template-rows: 100px 200px 100px;


  grid-template-areas:

    "head head . side"

    "main main . side"

    "footer footer footer footer";

}


When the HTML with the actual content (not included in the above code) is added to this CSS grid template, it will result in:

a diagram of a web page showing the header, main area, sidebar and footer.

The above example uses additional shortcuts where the dot represents an empty grid shell. 


You can do a ton with this quickly by only changing a tiny bit of the code. For the above, you can completely revamp the layout to look like this:

a diagram of a website with a header, main area, sidebar and footer .

The only code that changed were where the spaces (using dots) land in the template — see below:

 

.container {

  /* ... */


  grid-template-areas:

    "head head  .    side"

    "main main main  side"

    ". footer footer side";


  /* ... */

}


Let's Play With CSS Grid Templates

There’s even more you can quickly accomplish once you name CSS grid template areas and create a template. For instance, you can also set a column that doesn’t change values followed by columns that do. Here’s how the code would be different with the first column set at 250px followed by repeating columns set by fraction of free area:

 

.grid {

  display: grid;

  grid-template-columns: 250px repeat(12, 1fr);

  grid-column-gap: 10px;

}


a red background with red stripes on it

What makes CSS grid template areas really stand out is you can make them fully responsive by adding a snippet of additional code. With CSS grid templates, you can easily tell the design how to respond based on a device’s pixel width and height.

Here’s an example from Mozilla:

 

@media (min-width: 500px) {

    .wrapper {

        grid-template-columns: repeat(9, 1fr);

        grid-template-areas:

          "hd hd hd hd   hd   hd   hd   hd   hd"

          "sd sd sd main main main main main main"

          "sd sd sd  ft  ft   ft   ft   ft   ft";

    }

}

@media (min-width: 700px) {

    .wrapper {

        grid-template-areas:

          "hd hd hd   hd   hd   hd   hd   hd hd"

          "sd sd main main main main main ft ft";

    }

}


This results in two columns when the screen is at least 700 pixels but three columns when the screen is smaller. (Note: The template areas were defined in separate code not affected by the additional media query code.)

The below example takes the Alligator.io layout above and makes it work on smaller screens.

Here’s the additional code (added onto the already set Alligator.io code above without changing anything in the previous code) that specifies the max width as a smartphone of 40em. Anything at that size width or smaller will display the stacked look.

 

@media screen and (max-width: 40em) {

  .container {

    grid-template-areas:

      "head head head head"

      "main main main main"

      "side side side side"

      "footer footer footer footer";

  }

}


a diagram of a web page with a header, main area, sidebar and footer .

Let’s look at another example from Shadeed that adds the media query code for three different types of devices. 

Here is the initial code for defining the template areas and the three-column grid:

 

.wrapper {

    display: grid;

    grid-template-columns: 1fr 1fr 1fr;

    grid-template-areas:

       "featured item-1 item-1"

       "featured item-2 item-2";

    grid-gap: 1.25rem;

}

 

.item.featured {

  grid-area: featured;

}

 

.item-2 {

  grid-area: item-1;

}

 

.item-3 {

  grid-area: item-2;

}


This is how it looks (with the labels added afterward to demonstrate placement; these wouldn’t show up without additional HTML code):

a grid CSS template showing a featured item 1 and a featured item 2

To make this fully responsive, do not change the code that defines the template areas, but add code for stacked layout and for the three-column layout with “Featured item” in column 1 and then “item 1” in column 2 and “item 2” in column 3. 

What Shadeed also does below is take the original code that created the CSS grid template and labels it with a media query.

 

/* Stacked Layout */

main {

  display: grid;

  grid-template-columns: 1fr 1fr 1fr;

  grid-template-areas: 

            "featured featured featured" 

            "item-1 item-1 item-1" 

            "item-2 item-2 item-2";

  grid-gap: 1.25rem;

}

 

/* 3-col Layout */

@media (min-width: 600px) {

  main {

    grid-template-areas: 

            "featured item-1 item-2" 

            "featured item-1 item-2";

  }

}

/* Featured Layout */

@media (min-width: 900px) {

  main {

    grid-template-areas: 

            "featured item-1 item-1" 

            "featured item-2 item-2";

  }

}


And here's what that looks like:

an illustration showing three different types of layouts for CSS grids: stacked, 3-col and featured.

Summing Up

CSS grid templates speed up design, which is why there are so many examples of prebuilt templates available. They’re also an invaluable tool for responsive websites.

Because of this — even though in a website builder platform like Duda you can cut and paste elements around without coding them in CSS — you’ll want to understand and master how CSS grid templates work to improve your web design skills.

Related Posts



A purple sign that says https://shop on it
By Renana Dar April 15, 2025
In this blog, we uncover the unknown world of subdomains, explaining what a subdomain is and how it works, the benefits of using a subdomain, common use cases for subdomains, the difference between a subdomain and a subdirectory, how subdomains impact SEO (with insights from Google’s John Mueller) and step-by-step instructions to add a subdomain to your Duda website.
A screenshot of a website showing a dashboard and new arrivals.
By Shawn Davis April 3, 2025
Build websites instantly with Duda's Instant Sites! Learn how to leverage the API, Connected Data, and Templates for scalable website creation and simplified data management.
By Shawn Davis March 27, 2025
If you work with patient information in the United States, you’re likely very, very familiar with HIPAA. What you might not be so confident about, though, is how it impacts your website. Thankfully, it’s not as scary as it seems.
Show More

Did you find this article interesting?


Thanks for the feedback!
A screenshot of a plumber's website with a
By Renana Dar May 5, 2025
Many SMBs still hesitate to embrace eCommerce. As the agency partner, you have the opportunity to tear down the perceived walls of eCommerce and show clients how eCommerce can make their business more efficient, accessible, and profitable. Read all about it!
A computer screen with a graph on it and a purple background.
By Santi Clarke April 24, 2025
Learn how platform ecosystems drive revenue and why they are essential for the growth of SaaS businesses.
By Santi Clarke April 24, 2025
One of the greatest challenges for SaaS platforms is keeping users engaged long-term. The term “stickiness” refers to a product's ability to retain users and make them want to return. In the context of SaaS platforms, creating a sticky product means that users consistently find value, experience seamless interactions, and continue using the product over time. The following are 7 practical strategies you can take to improve the stickiness of your SaaS solution. 1. Offer websites that help customers build their digital presence One of the most effective ways to make your SaaS platform sticky is by offering websites to your users. Many businesses today need an online presence, and by providing a platform where your customers can easily build and manage their websites, you increase their reliance on your product. When you offer users a website-building solution, you’re helping them create something foundational to their business. Websites, in this case, aren’t just a tool—they become a part of their identity and brand. This deepens their engagement with your platform, as they need your product to maintain and update their site, ultimately making them less likely to churn. Plus, websites naturally encourage frequent updates, content creation, and customer interactions, which means your users will return to your platform regularly. When you can give your users the tools to create something so essential to their business, you make them more dependent on your platform. This creates a higher barrier to exit, as migrating a fully built website to another service is no small task. In fact, websites are some of the stickiest products you can sell, so adding them to your product portfolio can be one of the best decisions you can to keep your customers using your technology for the long haul. 2. Deliver continuous value through product innovation The key to keeping users coming back to your SaaS platform is ensuring that they consistently see value in it. This means not only meeting their immediate needs but also evolving to address their growing demands. Constant product innovation is essential for keeping your users satisfied and invested in your platform. One way to achieve this is through regular updates that add new features or improvements based on user feedback. A SaaS platform that evolves with its users will keep them engaged longer, making it harder for competitors to steal their attention. Encourage user feedback and prioritize updates that create tangible improvements. This creates an ongoing relationship with your users, which boosts stickiness. 3. Offer a multi-product solution Another powerful way to increase your platform’s stickiness is by offering a suite of products or features that integrate well together. When your users adopt multiple products, they are more likely to stay because they become embedded in your ecosystem. The benefits of this strategy are clear. Research shows that once users adopt more than one product, especially when they integrate >4 tools into their workflow, their likelihood of churn decreases significantly. This happens because the more a user integrates into your suite of products, the harder it is for them to switch to a competitor. These users have invested time in learning your ecosystem and rely on it for their day-to-day operations, making it much harder for them to make the switch. 4. Create a personal connection with your users Human connection is one of the most powerful drivers of user retention. People don’t want to feel like they’re using a cold, faceless platform. By offering exceptional customer support, personalized communication, and community engagement, you build a relationship with your users that goes beyond the product itself. Make sure your support team is responsive, knowledgeable, and empathetic. You can also consider offering tailored onboarding experiences to ensure users understand how to make the most of your platform. When users feel like their success matters to you, they are more likely to remain loyal. 5. Leverage data to personalize the user experience Using data to drive personalization is another strategy that can significantly increase the stickiness of your platform. By tracking user behavior and usage patterns, you can tailor the experience to each individual user’s needs. This could mean recommending features they haven’t yet explored or sending them reminders about tools they may not be fully utilizing. Personalization gives users the feeling that the platform was designed specifically for them, making it harder to walk away from. By demonstrating that you understand their unique needs, you can build a stronger connection and ultimately increase retention rates. 6. Focus on seamless integrations and API capabilities To further increase stickiness, consider expanding your product’s ability to integrate with other tools your users already rely on. Whether it’s email marketing software, CRM systems, or social media management tools, seamless integrations add tremendous value by making it easier for users to incorporate your platform into their existing workflows. The more your product can work in tandem with other popular tools, the more indispensable it becomes. In fact, users who depend on integrations are less likely to churn since their entire ecosystem is tied to your platform’s functionality. 7. Encourage user advocacy and community building User advocacy is another powerful tool in building a sticky product. When users feel a sense of community or even ownership over the platform, they become your most passionate promoters. Encourage your users to share their success stories, join community forums, or contribute to product development through beta testing or feedback loops. A thriving user community not only increases user engagement but also creates a sense of loyalty. When users are part of something larger than themselves, they are more likely to remain committed to your platform, reducing churn and increasing lifetime value. Create deep, lasting customer relationships Making your SaaS platform sticky is all about creating a deep, lasting connection with your users. This requires building a platform that continuously delivers value, creating a seamless and personalized experience, and integrating features that keep users coming back. By focusing on product innovation, offering a multi-product ecosystem, and fostering strong user relationships, you’ll be well on your way to reducing churn and boosting user retention. Stickiness isn’t just a nice-to-have; it’s essential for long-term success. Focus on creating a platform that users can’t imagine living without, and you’ll see them stick around for the long haul.
Show More

Latest posts