{"id":95,"date":"2026-04-07T01:18:54","date_gmt":"2026-04-07T01:18:54","guid":{"rendered":"https:\/\/gigz.pk\/css\/?post_type=lesson&#038;p=95"},"modified":"2026-04-20T12:05:49","modified_gmt":"2026-04-20T12:05:49","slug":"background-position-and-size","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/css\/lesson\/background-position-and-size\/","title":{"rendered":"Background Position and Size"},"content":{"rendered":"\n<p>Background images are an important part of web design. CSS provides powerful properties to control how background images are placed and scaled. The two main properties used are background-position and background-size.<\/p>\n\n\n\n<p>Background Position<\/p>\n\n\n\n<p>The background-position property defines where the background image appears within an element. By default, the image is placed at the top left corner.<\/p>\n\n\n\n<p>You can use keywords such as top, bottom, left, right, and center to control the position.<\/p>\n\n\n\n<p>Example<br>background-position: center;<\/p>\n\n\n\n<p>This places the image in the center of the element.<\/p>\n\n\n\n<p>You can also combine values.<\/p>\n\n\n\n<p>Example<br>background-position: top right;<\/p>\n\n\n\n<p>This moves the image to the top right corner.<\/p>\n\n\n\n<p>It is also possible to use pixel or percentage values.<\/p>\n\n\n\n<p>Example<br>background-position: 50% 50%;<\/p>\n\n\n\n<p>This centers the image both horizontally and vertically.<\/p>\n\n\n\n<p>Example<br>background-position: 20px 30px;<\/p>\n\n\n\n<p>This moves the image 20 pixels from the left and 30 pixels from the top.<\/p>\n\n\n\n<p>Background Size<\/p>\n\n\n\n<p>The background-size property controls the size of the background image.<\/p>\n\n\n\n<p>You can set exact values.<\/p>\n\n\n\n<p>Example<br>background-size: 200px 150px;<\/p>\n\n\n\n<p>This sets the width to 200 pixels and height to 150 pixels.<\/p>\n\n\n\n<p>You can also use percentages.<\/p>\n\n\n\n<p>Example<br>background-size: 100% 100%;<\/p>\n\n\n\n<p>This stretches the image to fill the entire element.<\/p>\n\n\n\n<p>There are also special values.<\/p>\n\n\n\n<p>The cover value scales the image to completely cover the element while maintaining aspect ratio. Some parts of the image may be cropped.<\/p>\n\n\n\n<p>Example<br>background-size: cover;<\/p>\n\n\n\n<p>The contain value scales the image so that it fits inside the element without cropping. Empty space may remain.<\/p>\n\n\n\n<p>Example<br>background-size: contain;<\/p>\n\n\n\n<p>Combining Position and Size<\/p>\n\n\n\n<p>You can use both properties together to create better layouts.<\/p>\n\n\n\n<p>Example<br>background-position: center;<br>background-size: cover;<\/p>\n\n\n\n<p>This combination is commonly used for full-width banners and hero sections.<\/p>\n\n\n\n<p>Best Practices<\/p>\n\n\n\n<p>Use cover for full background sections such as headers or banners.<\/p>\n\n\n\n<p>Use contain when you want the entire image to be visible.<\/p>\n\n\n\n<p>Avoid stretching images too much as it can reduce quality.<\/p>\n\n\n\n<p>Use high-quality images for better visual results.<\/p>\n\n\n\n<p>Conclusion<\/p>\n\n\n\n<p>Understanding background-position and background-size helps you control how images appear on your website. These properties allow you to create responsive and visually appealing designs with ease.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-95","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>Background Position and Size - 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\/background-position-and-size\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Background Position and Size - CSS learning mastery\" \/>\n<meta property=\"og:description\" content=\"Background images are an important part of web design. CSS provides powerful properties to control how background images are placed and scaled. The two main properties used are background-position and background-size. Background Position The background-position property defines where the background image appears within an element. By default, the image is placed at the top left [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/css\/lesson\/background-position-and-size\/\" \/>\n<meta property=\"og:site_name\" content=\"CSS learning mastery\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-20T12:05:49+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\\\/background-position-and-size\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/background-position-and-size\\\/\",\"name\":\"Background Position and Size - CSS learning mastery\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\"},\"datePublished\":\"2026-04-07T01:18:54+00:00\",\"dateModified\":\"2026-04-20T12:05:49+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/background-position-and-size\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/background-position-and-size\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/background-position-and-size\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Background Position and Size\"}]},{\"@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":"Background Position and Size - 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\/background-position-and-size\/","og_locale":"en_US","og_type":"article","og_title":"Background Position and Size - CSS learning mastery","og_description":"Background images are an important part of web design. CSS provides powerful properties to control how background images are placed and scaled. The two main properties used are background-position and background-size. Background Position The background-position property defines where the background image appears within an element. By default, the image is placed at the top left [&hellip;]","og_url":"https:\/\/gigz.pk\/css\/lesson\/background-position-and-size\/","og_site_name":"CSS learning mastery","article_modified_time":"2026-04-20T12:05:49+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\/background-position-and-size\/","url":"https:\/\/gigz.pk\/css\/lesson\/background-position-and-size\/","name":"Background Position and Size - CSS learning mastery","isPartOf":{"@id":"https:\/\/gigz.pk\/css\/#website"},"datePublished":"2026-04-07T01:18:54+00:00","dateModified":"2026-04-20T12:05:49+00:00","breadcrumb":{"@id":"https:\/\/gigz.pk\/css\/lesson\/background-position-and-size\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/css\/lesson\/background-position-and-size\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/css\/lesson\/background-position-and-size\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/css\/"},{"@type":"ListItem","position":2,"name":"Background Position and Size"}]},{"@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\/95","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=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}