{"id":93,"date":"2026-04-07T01:17:26","date_gmt":"2026-04-07T01:17:26","guid":{"rendered":"https:\/\/gigz.pk\/css\/?post_type=lesson&#038;p=93"},"modified":"2026-04-20T11:57:11","modified_gmt":"2026-04-20T11:57:11","slug":"background-colors-and-images-in-css","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/css\/lesson\/background-colors-and-images-in-css\/","title":{"rendered":"Background Colors and Images in CSS"},"content":{"rendered":"\n<p>Background styling is an important part of web design. It helps make a website look attractive and improves the user experience. In CSS, you can set background colors and images for any HTML element such as the body, div, or sections.<\/p>\n\n\n\n<p>Background Color<\/p>\n\n\n\n<p>The background color property is used to set the color behind an element. You can use color names, hexadecimal values, RGB, or HSL.<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<p>body {<br>background-color: lightblue;<br>}<\/p>\n\n\n\n<p>You can also apply background color to specific elements.<\/p>\n\n\n\n<p>div {<br>background-color: yellow;<br>}<\/p>\n\n\n\n<p>Background Image<\/p>\n\n\n\n<p>The background image property is used to add an image behind an element. This is useful for creating visually appealing designs.<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<p>body {<br>background-image: url(&#8220;background.jpg&#8221;);<br>}<\/p>\n\n\n\n<p>Make sure the image path is correct so the browser can load it properly.<\/p>\n\n\n\n<p>Background Repeat<\/p>\n\n\n\n<p>By default, background images repeat both horizontally and vertically. You can control this behavior using the background repeat property.<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<p>body {<br>background-image: url(&#8220;pattern.png&#8221;);<br>background-repeat: no-repeat;<br>}<\/p>\n\n\n\n<p>Other values include repeat, repeat-x, and repeat-y.<\/p>\n\n\n\n<p>Background Position<\/p>\n\n\n\n<p>This property is used to control the position of the background image.<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<p>body {<br>background-image: url(&#8220;image.jpg&#8221;);<br>background-position: center;<br>}<\/p>\n\n\n\n<p>You can also use values like top, bottom, left, right, or specific pixel positions.<\/p>\n\n\n\n<p>Background Size<\/p>\n\n\n\n<p>The background size property controls the size of the image.<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<p>body {<br>background-image: url(&#8220;image.jpg&#8221;);<br>background-size: cover;<br>}<\/p>\n\n\n\n<p>Cover makes the image fill the entire area, while contain fits the image inside the container.<\/p>\n\n\n\n<p>Background Attachment<\/p>\n\n\n\n<p>This property defines whether the background image scrolls with the page or stays fixed.<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<p>body {<br>background-image: url(&#8220;image.jpg&#8221;);<br>background-attachment: fixed;<br>}<\/p>\n\n\n\n<p>Fixed backgrounds stay in place while scrolling.<\/p>\n\n\n\n<p>Shorthand Background Property<\/p>\n\n\n\n<p>You can combine multiple background properties into one line.<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<p>body {<br>background: lightblue url(&#8220;image.jpg&#8221;) no-repeat center;<br>}<\/p>\n\n\n\n<p>Best Practices<\/p>\n\n\n\n<p>Use light background colors for better readability<br>Choose high-quality images<br>Avoid using very large images to keep the website fast<br>Ensure text is clearly visible on the background<\/p>\n\n\n\n<p>Conclusion<\/p>\n\n\n\n<p>Background colors and images help create attractive and user-friendly websites. By using CSS properties correctly, you can design modern and professional web pages.<\/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) > Backgrounds &#038; Borders > Background Colors &#038; Images<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1776686205710\"><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-1776686205423\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":0,"template":"","class_list":["post-93","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 Colors and Images in CSS - CSS learning mastery<\/title>\n<meta name=\"description\" content=\"Learn CSS background colors and images with simple examples. Improve website design using easy and effective styling techniques.\" \/>\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-colors-and-images-in-css\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Background Colors and Images in CSS - CSS learning mastery\" \/>\n<meta property=\"og:description\" content=\"Learn CSS background colors and images with simple examples. Improve website design using easy and effective styling techniques.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/css\/lesson\/background-colors-and-images-in-css\/\" \/>\n<meta property=\"og:site_name\" content=\"CSS learning mastery\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-20T11:57:11+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\\\/background-colors-and-images-in-css\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/background-colors-and-images-in-css\\\/\",\"name\":\"Background Colors and Images in CSS - CSS learning mastery\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\"},\"datePublished\":\"2026-04-07T01:17:26+00:00\",\"dateModified\":\"2026-04-20T11:57:11+00:00\",\"description\":\"Learn CSS background colors and images with simple examples. Improve website design using easy and effective styling techniques.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/background-colors-and-images-in-css\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/background-colors-and-images-in-css\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/background-colors-and-images-in-css\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS Fundamentals (Beginner) > Backgrounds & Borders > Background Colors & Images\"}]},{\"@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 Colors and Images in CSS - CSS learning mastery","description":"Learn CSS background colors and images with simple examples. Improve website design using easy and effective styling techniques.","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-colors-and-images-in-css\/","og_locale":"en_US","og_type":"article","og_title":"Background Colors and Images in CSS - CSS learning mastery","og_description":"Learn CSS background colors and images with simple examples. Improve website design using easy and effective styling techniques.","og_url":"https:\/\/gigz.pk\/css\/lesson\/background-colors-and-images-in-css\/","og_site_name":"CSS learning mastery","article_modified_time":"2026-04-20T11:57:11+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\/background-colors-and-images-in-css\/","url":"https:\/\/gigz.pk\/css\/lesson\/background-colors-and-images-in-css\/","name":"Background Colors and Images in CSS - CSS learning mastery","isPartOf":{"@id":"https:\/\/gigz.pk\/css\/#website"},"datePublished":"2026-04-07T01:17:26+00:00","dateModified":"2026-04-20T11:57:11+00:00","description":"Learn CSS background colors and images with simple examples. Improve website design using easy and effective styling techniques.","breadcrumb":{"@id":"https:\/\/gigz.pk\/css\/lesson\/background-colors-and-images-in-css\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/css\/lesson\/background-colors-and-images-in-css\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/css\/lesson\/background-colors-and-images-in-css\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/css\/"},{"@type":"ListItem","position":2,"name":"CSS Fundamentals (Beginner) > Backgrounds & Borders > Background Colors & Images"}]},{"@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\/93","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=93"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}