
- CSS - Home
- CSS - Roadmap
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Types
- CSS - Measurement Units
- CSS - Selectors
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS - Cascading
- CSS - Universal Selectors
- CSS - ID Selectors
- CSS - Group Selectors
- CSS - Class Selectors
- CSS - Child Selectors
- CSS - Element Selectors
- CSS - Descendant Selectors
- CSS - General Sibling Selectors
- CSS - Adjacent Sibling Selectors
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Advanced Features
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS Interview Questions
- CSS Online Quiz
- CSS Online Test
- CSS Mock Test
- CSS - Quick Guide
- CSS - Cheatsheet
- CSS - Properties References
- CSS - Functions References
- CSS - Color References
- CSS - Web Browser References
- CSS - Web Safe Fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - grid-template-areas Property
CSS grid-template-areas property defines named sections within a grid that outline the arrangement of the cells and identify them with specific names. The element of the grid can then use these name to refer to the specific region using the grid-area property.
Syntax
grid-template-areas: none | item-names;
Property Values
Value | Description |
---|---|
none | It specifies no named regions in the grid layout. |
item-names | It is a string sequence with region names that specify the sizes of the rows and columns. |
Examples of CSS Grid Template Areas Property
The following examples explain the grid-template-areas property with different values.
Grid Template Areas Property with None Value
To not have any named regions in the grid layout and the items displayed in their natural flow, we use the none value. The size of the items depend on their content. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: grid; background-color: lightgrey; grid-gap: 10px; padding: 20px; } .container > div padding: 20px; text-align: center; color: white; border: 3px solid blue; background-color: #4775d1; grid-template-areas: none; </style> </head> <body> <h2> CSS grid-template-areas property </h2> <h4> grid-template-areas: none </h4> <div class="container"> <div> Item-1 </div> <div> Item-2 </div> <div> Item-3 </div> <div> Item-4 </div> </div> </body> </html>
Grid Template Areas Property with Named Areas
To have specific named regions in the grid layout, we specify string sequences with region names to the grid-template-areas property. Each individual string sequence represents a row and the number of names inside the string represent the number of columns. The grid-area property has to be used to refer to the region. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .container { display: grid; background-color: lightgrey; grid-gap: 10px; padding: 20px; } .container>div { padding: 20px; text-align: center; color: white; border: 3px solid blue; } .container1 { grid-template: 'header header header header' 'sidebar1 content content sidebar2' 'footer footer footer footer'; } .container2 { grid-template: '. . . .' '. . item item'; } .container2>div { background-color: lightcoral; } .cont1-item1 { background-color: #05445e; grid-area: header; } .cont1-item2 { background-color: #75e6da; grid-area: sidebar1; } .cont1-item3 { background-color: #189ab4; grid-area: content; } .cont1-item4 { background-color: #8bcd50; grid-area: footer; } .cont1-item5 { background-color: #75e6da; grid-area: sidebar2; } .cont2-item1 { grid-area: item; } </style> </head> <body> <h2> CSS grid-template-areas property </h2> <p> <strong> grid-template-areas: 'header header header header' 'sidebar1 content content sidebar2' 'footer footer footer footer' </strong> ; The layout has three rows indicated by three separate strings and four columns indicated by the number of items inside strings ' ' </p> <div class=" container container1"> <div class="cont1-item1"> This is header </div> <div class="cont1-item2"> This is sidebar1 </div> <div class="cont1-item3"> This is content </div> <div class="cont1-item4"> This is footer </div> <div class="cont1-item5"> This is sidebar2 </div> </div> <p> <strong> grid-template-areas: '. . . .''. . item item' </strong> ; the layout has 2 rows and 4 columns, item1 is placed in the second row and takes 2 columns space. </p> <div class=" container container2"> <div class="cont2-item1"> Item-1 </div> <div> Item-2 </div> <div> Item-3 </div> <div> Item-4 </div> <div> Item-5 </div> <div> Item-6 </div> </div> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
grid-template-areas | 57 | 16 | 52 | 10 | 44 |