{"id":124,"date":"2026-04-07T04:25:13","date_gmt":"2026-04-07T04:25:13","guid":{"rendered":"https:\/\/gigz.pk\/css\/?post_type=lesson&#038;p=124"},"modified":"2026-04-07T04:25:14","modified_gmt":"2026-04-07T04:25:14","slug":"gap-and-alignment","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/css\/lesson\/gap-and-alignment\/","title":{"rendered":"Gap and Alignment"},"content":{"rendered":"\n<p>Gap and alignment are important concepts in CSS that help you control spacing and positioning of elements in a clean and professional way. They are mainly used with Flexbox and Grid layouts to create well-structured designs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Understanding Gap in CSS<\/h3>\n\n\n\n<p>Gap is used to create space between elements inside a container. It is commonly used with Flexbox and Grid instead of adding margins to individual elements.<\/p>\n\n\n\n<p>There are three types of gap properties<\/p>\n\n\n\n<p>gap<br>row-gap<br>column-gap<\/p>\n\n\n\n<p>Example using Grid<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.container {<br>  display: grid;<br>  grid-template-columns: repeat(3, 1fr);<br>  gap: 20px;<br>}<\/pre>\n\n\n\n<p>Example using Flexbox<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.container {<br>  display: flex;<br>  gap: 15px;<br>}<\/pre>\n\n\n\n<p>Using gap makes your layout cleaner because you do not need to manage spacing for each element separately.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Understanding Alignment in CSS<\/h3>\n\n\n\n<p>Alignment controls how elements are positioned inside a container. It works both horizontally and vertically depending on the layout system.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Alignment in Flexbox<\/h4>\n\n\n\n<p>Flexbox uses the following properties for alignment<\/p>\n\n\n\n<p>justify-content controls horizontal alignment<br>align-items controls vertical alignment<br>align-self aligns a single item<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.container {<br>  display: flex;<br>  justify-content: center;<br>  align-items: center;<br>  height: 200px;<br>}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Alignment in Grid<\/h4>\n\n\n\n<p>Grid provides more control over alignment<\/p>\n\n\n\n<p>justify-items aligns items horizontally inside their cells<br>align-items aligns items vertically inside their cells<br>justify-content aligns the entire grid horizontally<br>align-content aligns the entire grid vertically<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.container {<br>  display: grid;<br>  height: 300px;<br>  justify-items: center;<br>  align-items: center;<br>}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Key Difference Between Gap and Alignment<\/h3>\n\n\n\n<p>Gap is used to create space between elements<br>Alignment is used to position elements inside a container<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Best Practices<\/h3>\n\n\n\n<p>Use gap instead of margins for consistent spacing<br>Use Flexbox for one dimensional layouts<br>Use Grid for two dimensional layouts<br>Combine gap and alignment for clean and responsive design<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Practice Exercise<\/h3>\n\n\n\n<p>Create a container with three boxes<br>Apply gap to add spacing between them<br>Center the boxes using alignment properties<\/p>\n\n\n\n<p><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-124","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Gap and Alignment - CSS learning mastery<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/css\/lesson\/gap-and-alignment\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Gap and Alignment - CSS learning mastery\" \/>\n<meta property=\"og:description\" content=\"Gap and alignment are important concepts in CSS that help you control spacing and positioning of elements in a clean and professional way. They are mainly used with Flexbox and Grid layouts to create well-structured designs. Understanding Gap in CSS Gap is used to create space between elements inside a container. It is commonly used [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/css\/lesson\/gap-and-alignment\/\" \/>\n<meta property=\"og:site_name\" content=\"CSS learning mastery\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-07T04:25:14+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/gap-and-alignment\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/gap-and-alignment\\\/\",\"name\":\"Gap and Alignment - CSS learning mastery\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\"},\"datePublished\":\"2026-04-07T04:25:13+00:00\",\"dateModified\":\"2026-04-07T04:25:14+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/gap-and-alignment\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/gap-and-alignment\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/gap-and-alignment\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Gap and Alignment\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\",\"name\":\"CSS learning mastery\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/css\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Gap and Alignment - CSS learning mastery","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/css\/lesson\/gap-and-alignment\/","og_locale":"en_US","og_type":"article","og_title":"Gap and Alignment - CSS learning mastery","og_description":"Gap and alignment are important concepts in CSS that help you control spacing and positioning of elements in a clean and professional way. They are mainly used with Flexbox and Grid layouts to create well-structured designs. Understanding Gap in CSS Gap is used to create space between elements inside a container. It is commonly used [&hellip;]","og_url":"https:\/\/gigz.pk\/css\/lesson\/gap-and-alignment\/","og_site_name":"CSS learning mastery","article_modified_time":"2026-04-07T04:25:14+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/gigz.pk\/css\/lesson\/gap-and-alignment\/","url":"https:\/\/gigz.pk\/css\/lesson\/gap-and-alignment\/","name":"Gap and Alignment - CSS learning mastery","isPartOf":{"@id":"https:\/\/gigz.pk\/css\/#website"},"datePublished":"2026-04-07T04:25:13+00:00","dateModified":"2026-04-07T04:25:14+00:00","breadcrumb":{"@id":"https:\/\/gigz.pk\/css\/lesson\/gap-and-alignment\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/css\/lesson\/gap-and-alignment\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/css\/lesson\/gap-and-alignment\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/css\/"},{"@type":"ListItem","position":2,"name":"Gap and Alignment"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/css\/#website","url":"https:\/\/gigz.pk\/css\/","name":"CSS learning mastery","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/css\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/lesson\/124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/media?parent=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}