{"id":77,"date":"2026-04-06T18:10:53","date_gmt":"2026-04-06T18:10:53","guid":{"rendered":"https:\/\/gigz.pk\/css\/?post_type=lesson&#038;p=77"},"modified":"2026-04-18T16:10:07","modified_gmt":"2026-04-18T16:10:07","slug":"width-and-height","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/css\/lesson\/width-and-height\/","title":{"rendered":"Width and Height"},"content":{"rendered":"\n<p>Width and height are used to control the size of elements on a web page. They help define how much space an element takes horizontally and vertically.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is Width<\/h3>\n\n\n\n<p>Width sets how wide an element will be. It can be defined using different units such as pixels, percentages, or viewport units.<\/p>\n\n\n\n<p>Example<br>div {<br>width: 300px;<br>}<\/p>\n\n\n\n<p>This sets the element width to 300 pixels.<\/p>\n\n\n\n<p>You can also use percentage values<br>div {<br>width: 50%;<br>}<\/p>\n\n\n\n<p>This means the element will take up 50 percent of its parent container.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is Height<\/h3>\n\n\n\n<p>Height sets how tall an element will be.<\/p>\n\n\n\n<p>Example<br>div {<br>height: 200px;<br>}<\/p>\n\n\n\n<p>This sets the height of the element to 200 pixels.<\/p>\n\n\n\n<p>You can also use percentage<br>div {<br>height: 100%;<br>}<\/p>\n\n\n\n<p>This makes the element take the full height of its parent. For this to work, the parent element must have a defined height.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Common Units<\/h3>\n\n\n\n<p>Pixels are fixed and do not change based on screen size<br>Percentages are relative to the parent element<br>Viewport width and height adjust based on screen size<\/p>\n\n\n\n<p>Example<br>div {<br>width: 50vw;<br>height: 50vh;<br>}<\/p>\n\n\n\n<p>This sets the element to half of the screen width and height.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Max and Min Values<\/h3>\n\n\n\n<p>You can control limits using max width, min width, max height, and min height.<\/p>\n\n\n\n<p>Example<br>img {<br>max-width: 100%;<br>height: auto;<br>}<\/p>\n\n\n\n<p>This ensures images do not overflow their container and stay responsive.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Important Notes<\/h3>\n\n\n\n<p>If width is not set, elements usually take full width by default<br>Height does not always expand automatically unless content increases<br>Overflow may occur if content is larger than the defined size<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Practice Task<\/h3>\n\n\n\n<p>Create a div with a fixed width and height<br>Try using percentage width<br>Experiment with max width for images<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/css\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">CSS Fundamentals (Beginner) > Box Model > Width &#038; Height<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1776528557014\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1776528556738\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":0,"template":"","class_list":["post-77","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>Width and Height - CSS learning mastery<\/title>\n<meta name=\"description\" content=\"Learn CSS width and height properties with simple examples. Control element size and create responsive web designs easily\" \/>\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\/width-and-height\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Width and Height - CSS learning mastery\" \/>\n<meta property=\"og:description\" content=\"Learn CSS width and height properties with simple examples. Control element size and create responsive web designs easily\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/css\/lesson\/width-and-height\/\" \/>\n<meta property=\"og:site_name\" content=\"CSS learning mastery\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-18T16:10:07+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\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/width-and-height\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/width-and-height\\\/\",\"name\":\"Width and Height - CSS learning mastery\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\"},\"datePublished\":\"2026-04-06T18:10:53+00:00\",\"dateModified\":\"2026-04-18T16:10:07+00:00\",\"description\":\"Learn CSS width and height properties with simple examples. Control element size and create responsive web designs easily\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/width-and-height\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/width-and-height\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/width-and-height\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS Fundamentals (Beginner) > Box Model > Width & Height\"}]},{\"@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":"Width and Height - CSS learning mastery","description":"Learn CSS width and height properties with simple examples. Control element size and create responsive web designs easily","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\/width-and-height\/","og_locale":"en_US","og_type":"article","og_title":"Width and Height - CSS learning mastery","og_description":"Learn CSS width and height properties with simple examples. Control element size and create responsive web designs easily","og_url":"https:\/\/gigz.pk\/css\/lesson\/width-and-height\/","og_site_name":"CSS learning mastery","article_modified_time":"2026-04-18T16:10:07+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/css\/lesson\/width-and-height\/","url":"https:\/\/gigz.pk\/css\/lesson\/width-and-height\/","name":"Width and Height - CSS learning mastery","isPartOf":{"@id":"https:\/\/gigz.pk\/css\/#website"},"datePublished":"2026-04-06T18:10:53+00:00","dateModified":"2026-04-18T16:10:07+00:00","description":"Learn CSS width and height properties with simple examples. Control element size and create responsive web designs easily","breadcrumb":{"@id":"https:\/\/gigz.pk\/css\/lesson\/width-and-height\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/css\/lesson\/width-and-height\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/css\/lesson\/width-and-height\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/css\/"},{"@type":"ListItem","position":2,"name":"CSS Fundamentals (Beginner) > Box Model > Width & Height"}]},{"@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\/77","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=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}