Performance: Background repeat
Background repeat affects how the browser paints repeated images, impacting paint time and memory usage.
Jump into concepts and practice - no test required
body {
background-image: url('pattern.png');
background-repeat: no-repeat;
background-size: cover;
}body {
background-image: url('pattern.png');
background-repeat: repeat;
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| background-repeat: repeat with large image | Minimal | 0 | High due to many repeated paints | [X] Bad |
| background-repeat: no-repeat with scaled image | Minimal | 0 | Low paint cost with single image | [OK] Good |
background-repeat: no-repeat; do to a background image?no-repeatno-repeat means the background image will not be repeated at all.repeat-x or repeat-y repeat the image horizontally or vertically, but no-repeat shows it once.no-repeat means no repeating [OK]repeat-x repeats the background image horizontally, repeat-y vertically, no-repeat no repetition, and repeat repeats both ways.repeat-x is correct.div {
background-image: url('pattern.png');
background-repeat: repeat-y;
width: 200px;
height: 400px;
}background-repeat: repeat-y;section {
background-image: url('tile.png');
background-repeat: repeat-x;
}background-repeat valuerepeat-x repeats the image only horizontally, not vertically.repeat should be used instead.repeat-x repeats only horizontally, not vertically. -> Option Abackground-repeat: repeat-y; and adjusting the container height to exactly 3 times the image height, the image will repeat vertically 3 times and then stop.background-repeat: repeat-y; and set the container height to 3 times the image height. -> Option B