I want my background image to cover my whole web page but it keeps on repeating. Is there a way to set it to non-repetition via HTML?
-
2How are you setting the background image in HTML not CSS? – Heretic Monkey Sep 09 '19 at 11:29
-
– Saba Sep 09 '19 at 11:30
-
2The `background` attribute is deprecated/obsolete in HTML5. – Heretic Monkey Sep 09 '19 at 11:35
-
yes it is not supported in HTML 5 check here: https://www.w3schools.com/tags/att_body_background.asp – adel Sep 09 '19 at 11:36
-
what is your reason not to use CSS? This is exactly what CSS is for! – Martin Sep 09 '19 at 12:05
3 Answers
You can't.
First of all, background
is an obsolete attribute. Browsers still support it.
Second, it is not part of HTML5, as you can see in the list of attributes of the body element (see also global attributes). Which also you are not using HTML5, stop pretending you are.
And finally, there never was an attribute to control how the background repeats. At least not documented.
Why do you want this? Even - not so good - old IE6 supports CSS background-repeat
and background-size
. Well, except it has problems with PNGs. There are hacks. See Background repeat doesn't seem to work in IE6 and IE6 PNG Transparency CSS background-repeat Fix.
I tried to look how people did this past millelium. You know, around Windows 95. Could not find anything. Perhaps somebody older than me knows, I began learning HTML when we had Windows 98 and IE6. However, I bet the answer is you could not do it.
Why don't you use CSS (and HTML5 by the way) for a change?

- 31,890
- 5
- 57
- 86
-
@SabaKhan `Why don't you use CSS (and HTML5 by the way) for a change?` I want to know your answer... – Ritesh Khandekar Sep 09 '19 at 12:12
-
Actually we have to design a pure html based website as our task. That's why! – Saba Sep 09 '19 at 12:13
-
1@SabaKhan Well, the only idea I have for you is to make the image bigger than the contents of the page. Edit: well, I suppose another alternative is not having a background. – Theraot Sep 09 '19 at 12:15
-
Yes, Every Display has not same size so you can't be able to get same image output everytime – Ritesh Khandekar Sep 09 '19 at 12:25
You need to use inline css (style).
<body style="background: url('images/bg.gif');background-repeat: no-repeat;background-size: cover">

- 718
- 6
- 11