{"id":3331,"date":"2022-04-25T14:00:00","date_gmt":"2022-04-25T14:00:00","guid":{"rendered":"https:\/\/cssdeck.com\/blog\/?p=3331"},"modified":"2022-04-25T10:00:30","modified_gmt":"2022-04-25T10:00:30","slug":"the-background-image-property-in-css","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/the-background-image-property-in-css\/","title":{"rendered":"The Background-Image Property in CSS"},"content":{"rendered":"\n<p>A user&#8217;s customer experience is influenced by what they see on a site, and it will also impact how readily users can navigate the website overall.<\/p>\n\n\n\n<p>Applying graphics to the background-image property in CSS of specific portions of a website is typically more aesthetically attractive and engaging than just altering the foreground color.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"600\" height=\"423\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/04\/Screenshot-1392.png\" alt=\"\" class=\"wp-image-3332\" \/><\/figure><\/div>\n\n\n\n<p>Setting one or more wallpaper pictures for a component is done with the background-image attribute. The image is placed in the upper left corner by design. To provide two or more photos, we must use a comma to divide the URLs for each image.<\/p>\n\n\n\n<p>Context layers are stacked on top of each other to create the backdrop pictures. The initial layer is drawn as though it was nearest to the user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p>background-image: url(&#8216;url&#8217;)|none|initial|inherit;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Property Values Include:<\/h2>\n\n\n\n<p>Url (&#8216;URL): This provides the image&#8217;s URL. If you want to enter the URL of more than one picture, use a comma to differentiate the URLs.<\/p>\n\n\n\n<p>None: This is a normal situation where no picture may be shown.<\/p>\n\n\n\n<p>Initial: This property is intended to define the property&#8217;s initial value.<\/p>\n\n\n\n<p>Inherit: The property is passed down from the parent node.<\/p>\n\n\n\n<p>The following parameters might also be applied with the background-image property:<\/p>\n\n\n\n<p>Linear-gradient (): This function creates a background picture with a linear gradient of at least two colors from top to bottom.<\/p>\n\n\n\n<p>Radial-gradient (): This function creates a radial-gradient wallpaper image with at least two colors from the center to the margin.<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/what-are-css-image-rulers\/\">What are CSS Image Rulers to Follow<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Web Pages that are Compatible&nbsp;<\/h2>\n\n\n\n<p>Background image property in CSS is supported by the following browsers:<\/p>\n\n\n\n<p>Google Chrome 1.0<\/p>\n\n\n\n<p>Microsoft Edge 4.0<\/p>\n\n\n\n<p>Firefox 1.0<\/p>\n\n\n\n<p>Opera 3.5<\/p>\n\n\n\n<p>Safari 1.0<\/p>\n\n\n\n<p>The initial stage is to ensure you have an assets directory (folder) set up to house all of the photos you&#8217;ll need for your project.<\/p>\n\n\n\n<p>For instance, in the project we&#8217;re working on, we may establish a pictures directory and add a picture named sunset.png that we wish to use.<\/p>\n\n\n\n<p>This might be the entire page (using the body selector in CSS to target the body&gt; element in our HTML) or just a single section element.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Stop Background Repeat<\/h2>\n\n\n\n<p>By convention, it repeats when you attach a background picture to a component.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"600\" height=\"371\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/04\/Screenshot-1393.png\" alt=\"\" class=\"wp-image-3333\" \/><\/figure><\/div>\n\n\n\n<p>If the picture is smaller than the tag it is the backdrop for, it will be repeated to fill up the gap.<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/image-hover-effects-adding-box-shadow\/\">Image Hover Effects: Adding Box Shadow<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What can we do to prevent this from happening?<\/h2>\n\n\n\n<p>We may adjust the orientation in which the picture returns or prevent it from recurring at all using the background-repeat property, which accepts four values.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"600\" height=\"193\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/04\/Screenshot-1394.png\" alt=\"\" class=\"wp-image-3334\" \/><\/figure><\/div>\n\n\n\n<p>If the background-repeat property is not set, this is the default value. In this scenario, the picture is reproduced both horizontally and vertically, in both the x- and y-direction, until the space is filled.<\/p>\n\n\n\n<p>The no-repeat property prevents the picture from recurring in all orientations, and the picture appears only once.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Set Background Position<\/h2>\n\n\n\n<p>After inserting a background picture and preventing it from recurring, we may improve its location inside the tag&#8217;s backdrop to better manage how it appears.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"600\" height=\"387\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/04\/Screenshot-1395.png\" alt=\"\" class=\"wp-image-3335\" \/><\/figure><\/div>\n\n\n\n<p>To do so, we&#8217;ll use the background-image property in CSS.&nbsp;<\/p>\n\n\n\n<p>The selection accepts two inputs. The first is the horizontal position, sometimes known as the x-axis (how far across the tag). The second is the vertical position, sometimes known as the y-axis (how far down the tag).<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/how-to-center-an-image-in-css\/\">How To Center An Image In CSS<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is the Best Way to Resize a Background Image?<\/h2>\n\n\n\n<p>The background-size property may be used to alter the size of the background picture.<\/p>\n\n\n\n<p>It accepts two values, much like the preceding properties described. One for horizontal (x) and one for vertical (y) dimensions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Use the Background Attachment Property<\/h2>\n\n\n\n<p>We may decide where the wallpaper picture is connected with the background-attachment attribute, which determines whether the picture is permanent or not to the browser.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"600\" height=\"254\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/04\/Screenshot-1396-1.png\" alt=\"attachment property\" class=\"wp-image-3337\" \/><\/figure><\/div>\n\n\n\n<p>The default option is background-attachment: scroll, which means the backdrop picture remains with its tag and scrolls vertically and horizontally with us as we scroll back and forth the page.<\/p>\n\n\n\n<p>Background-attachment: fixed; is the property&#8217;s second possible value.<\/p>\n\n\n\n<p>This keeps the background picture in the same place, fixed to the page and the browser&#8217;s viewport.<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/how-to-add-a-background-image-in-css\/\">How To Add A Background Image In CSS<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Background Gradients<\/h2>\n\n\n\n<p>The background image property in CSS may also be used to inform the browser to generate a gradient.<\/p>\n\n\n\n<p>The background image is a linear gradient rather than a URL in this scenario.<\/p>\n\n\n\n<p>The most straightforward method is to indicate the angle. This determines the gradient&#8217;s pattern and how the colors will merge. Finally, add two colors that you wish to mix in a gradient for the tag&#8217;s background.<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>A user&#8217;s customer experience is influenced by what they see on a site, and it will also impact how readily users can navigate the website overall.<\/p>\n<p>Applying graphics to the background-image property in CSS of specific portions of a website is [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/the-background-image-property-in-css\/\" title=\"Click to read 'The Background-Image Property in CSS'\">Read Article<\/a><\/p>\n","protected":false},"author":21,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,183],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3331"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=3331"}],"version-history":[{"count":2,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3331\/revisions"}],"predecessor-version":[{"id":3341,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3331\/revisions\/3341"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=3331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=3331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=3331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}