Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS grid-auto-rows Property

Posted in CSS Tutorial
Updated on Oct 03, 2024
By Mari Selvan
👁️ 32 - Views
⏳ 4 mins
💬 1 Comment
CSS grid-auto-rows Property

Photo Credit to CodeToFun

🙋 Introduction

The grid-auto-rows property in CSS is used to specify the size of rows in a grid container. When you create a grid layout, you may define explicit rows and columns, but any additional rows created by content will use the grid-auto-rows property to determine their size.

This property is essential for creating flexible and dynamic grid layouts that adapt to varying content sizes.

💡 Syntax

The syntax for the grid-auto-rows property is straightforward. You can set it using length values, percentage values, or the auto keyword.

Syntax
Copied
Copy To Clipboard
.container {
  grid-auto-rows: value;
}

🎛️ Default Value

The default value of the grid-auto-rows property is auto, which means that the size of the row will be determined by the content inside it.

🏠 Property Values

ValueDescription
lengthSpecifies a fixed size for the rows, such as 100px, 2em, etc.
percentageSpecifies the size of the rows as a percentage of the grid container's size.
autoThe size of the rows is determined by the content inside them.
min-contentThe size of the rows is determined by the smallest content.
max-contentThe size of the rows is determined by the largest content.
frRepresents a fraction of the available space in the grid container.

📄 Example

In this example, we'll create a grid container with a defined height for auto-generated rows.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS grid-auto-rows Example</title>
  <style>
    .container {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      grid-auto-rows: 100px;
      gap: 10px;
    }
    .item {
      background-color: lightblue;
      padding: 10px;
      text-align: center;
    }
  </style>
</head>
<body>
  <h1>Grid with Custom Auto Rows</h1>
  <div class="container">
    <div class="item">Item 1</div>
    <div class="item">Item 2</div>
    <div class="item">Item 3</div>
    <div class="item">Item 4</div>
    <div class="item">Item 5</div>
    <div class="item">Item 6</div>
  </div>
</body>
</html>

🖥️ Browser Compatibility

The grid-auto-rows property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The grid-auto-rows property is a powerful tool for web developers looking to create flexible and dynamic grid layouts.

By controlling the size of automatically generated rows, you can ensure that your grid adapts to varying content sizes while maintaining a consistent and visually appealing layout. Experiment with different values to see how this property can enhance the design of your web projects.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy