{"id":108,"date":"2026-04-07T01:32:17","date_gmt":"2026-04-07T01:32:17","guid":{"rendered":"https:\/\/gigz.pk\/css\/?post_type=lesson&#038;p=108"},"modified":"2026-04-07T01:32:18","modified_gmt":"2026-04-07T01:32:18","slug":"z-index-and-stacking","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/css\/lesson\/z-index-and-stacking\/","title":{"rendered":"Z-index and Stacking"},"content":{"rendered":"\n<p>Z-index is a CSS property that controls the vertical order of elements on a web page. It decides which element appears in front and which one stays behind when elements overlap each other.<\/p>\n\n\n\n<p>Understanding Stacking<\/p>\n\n\n\n<p>When multiple elements are placed on a page, they are stacked one above another. By default, elements follow the order in which they appear in the HTML. Elements written later usually appear on top of earlier ones.<\/p>\n\n\n\n<p>What is Z-index<\/p>\n\n\n\n<p>Z-index allows you to control this stacking order manually. It works only on elements that have a position value such as relative absolute or fixed.<\/p>\n\n\n\n<p>A higher z index value means the element will appear in front of elements with lower values.<\/p>\n\n\n\n<p>Example of Z-index<\/p>\n\n\n\n<p>div one is positioned with z index 1<br>div two is positioned with z index 2<\/p>\n\n\n\n<p>In this case div two will appear above div one because it has a higher z index value.<\/p>\n\n\n\n<p>Position Requirement<\/p>\n\n\n\n<p>Z-index only works when an element has a position property set to relative absolute fixed or sticky. If position is not set, z index will not affect the element.<\/p>\n\n\n\n<p>Stacking Context<\/p>\n\n\n\n<p>A stacking context is a group of elements that are stacked together. When a new stacking context is created, the z index values inside it only work within that context.<\/p>\n\n\n\n<p>Some properties that create a new stacking context include position with a z index value opacity less than one and transform.<\/p>\n\n\n\n<p>Common Use Cases<\/p>\n\n\n\n<p>Z-index is often used for navigation menus dropdowns modals tooltips and overlapping images. It helps ensure that important elements stay visible above others.<\/p>\n\n\n\n<p>Best Practices<\/p>\n\n\n\n<p>Use small and meaningful z index values instead of very large numbers<br>Keep your stacking order organized and consistent<br>Avoid unnecessary stacking contexts to prevent confusion<br>Test overlapping elements to ensure correct display<\/p>\n\n\n\n<p>Conclusion<\/p>\n\n\n\n<p>Z-index is a powerful tool for controlling how elements overlap on a webpage. By understanding stacking and positioning you can design clean and professional layouts with proper layering of content.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-108","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>Z-index and Stacking - 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\/z-index-and-stacking\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Z-index and Stacking - CSS learning mastery\" \/>\n<meta property=\"og:description\" content=\"Z-index is a CSS property that controls the vertical order of elements on a web page. It decides which element appears in front and which one stays behind when elements overlap each other. Understanding Stacking When multiple elements are placed on a page, they are stacked one above another. By default, elements follow the order [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/css\/lesson\/z-index-and-stacking\/\" \/>\n<meta property=\"og:site_name\" content=\"CSS learning mastery\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-07T01:32:18+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\\\/z-index-and-stacking\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/z-index-and-stacking\\\/\",\"name\":\"Z-index and Stacking - CSS learning mastery\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\"},\"datePublished\":\"2026-04-07T01:32:17+00:00\",\"dateModified\":\"2026-04-07T01:32:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/z-index-and-stacking\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/z-index-and-stacking\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/z-index-and-stacking\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Z-index and Stacking\"}]},{\"@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":"Z-index and Stacking - 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\/z-index-and-stacking\/","og_locale":"en_US","og_type":"article","og_title":"Z-index and Stacking - CSS learning mastery","og_description":"Z-index is a CSS property that controls the vertical order of elements on a web page. It decides which element appears in front and which one stays behind when elements overlap each other. Understanding Stacking When multiple elements are placed on a page, they are stacked one above another. By default, elements follow the order [&hellip;]","og_url":"https:\/\/gigz.pk\/css\/lesson\/z-index-and-stacking\/","og_site_name":"CSS learning mastery","article_modified_time":"2026-04-07T01:32:18+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\/z-index-and-stacking\/","url":"https:\/\/gigz.pk\/css\/lesson\/z-index-and-stacking\/","name":"Z-index and Stacking - CSS learning mastery","isPartOf":{"@id":"https:\/\/gigz.pk\/css\/#website"},"datePublished":"2026-04-07T01:32:17+00:00","dateModified":"2026-04-07T01:32:18+00:00","breadcrumb":{"@id":"https:\/\/gigz.pk\/css\/lesson\/z-index-and-stacking\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/css\/lesson\/z-index-and-stacking\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/css\/lesson\/z-index-and-stacking\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/css\/"},{"@type":"ListItem","position":2,"name":"Z-index and Stacking"}]},{"@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\/108","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=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}