You can do this using the background-position property. However, you can control the position in which the background image is displayed. When you insert a background image, it is automatically positioned on the top-left corner of the element. For our, if we change its property to “background-repeat: repeat-y ”, it displays like this: For our, if we change its property to “background-repeat: repeat-x ”, it displays like this: Repeat-x: this repeats the image along the x-axis. It repeats the image until the entire background is covered.
![how to put background image in html from a folder how to put background image in html from a folder](https://media.cheggcdn.com/media%2F98e%2F98e453dc-2396-4234-90ca-29d1feca67d3%2Fphpb1c9Px.png)
Here is a brief explanation of these values. no-repeat, repeat, repeat-x, and repeat-y. The background-repeat property takes one of four values i.e. With this, the above would look like this: To avoid the above image from repeating, we’d simply write: You can set the position to center center to center the image in the pageīy default, the background image is tiled so that it fills the entire area of the element.īackground-image: url(images/orchids.jpg) The background-position property is to set the position of the background image. The other values for background-repeat are ‘repeat’, ‘repeat-x’ and ‘repeat-y’. The default is to tile the background image. The background-image property points to the URL of the image.īackground-repeat is set to no-repeat so that the browser won’t tile the background image.
HOW TO PUT BACKGROUND IMAGE IN HTML FROM A FOLDER CODE
This bit of CSS code sets the background image of the HTML Page. Here is a sample page where we are setting the background image of the entire pageīackground-image: url(sunset-sunrise-city-water-7629.jpg) Set the background image of the entire page background image covers only 30% of the containing element The background image is fit within the container element (parts of the background image may not be seen) The background image must cover the entire area The size of the background image Examples: The position of the background image Examples: The background is fixed and the content scrolls The background scrolls along with the content Whether the background should scroll along with the content Examples: Here is a quick reference to CSS Background properties: background-image In addition to the background-image URL, there are a number of properties that you can use to customise the display of the background image. Set the background image of the entire page.Yet another alternative is to use inline style in the HTML tag or element For instance, the image below is a background image of a with an id of image_bg as follows:īackground-image: url(images/sun-set-small.jpg) In fact, you can use any valid CSS selector. Similarly you can use a CSS id selector, a class selector or even a pseudo-class. The background-image property has to be part of a CSS rule.įor instance, the background image for a textarea can be added using the following rule:īackground-image: url(images/sun-set.jpg) For instance, you could write the property as follows:īackground-image : url(./mypics/bgimage.jpg) “image-url” refers to the absolute or relative url of the image. You can use the CSS “background-image” property to add a background image to an element. The best way to add a background image is via CSS.