Skip to content
Related Articles

Related Articles

How to specify a fixed background-image in CSS ?

View Discussion
Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 02 Jul, 2021

In this article, we are going to see how to specify a fixed background image in CSS. To keep your background fixed, scroll, or local in CSS, we have to use the background-attachment property.

Background-attachment: This property is used in CSS to set a background image as fixed or scroll. The default value of this property is scroll.

Values of background-attachment property:

  • Scroll: It is the default value for the background-attachment property. It is used to scroll the image with the background page.
  • Fixed: The background image will not scroll. It is fixed with the page.
  • Local: The background image will scroll with the content.

To keep your background image fixed, you have to use background-attachment property with the value Fixed.


background-attachment: fixed;



<!DOCTYPE html>
    <style type="text/css">
        h1 {
            text-align: center;
        #ex {
            text-align: center;
            background-position: center;
            background-repeat: no-repeat;
            background-attachment: fixed;
    <h1>Example for fixed Background Image</h1>
    <div id="ex">
            Paragraphs are the building blocks
            of papers. Many students define
            paragraphs in terms of length: a
            paragraph is a group of at least
            five sentences,
            a paragraph is half a page long,
            etc. In reality, though, the unity
            and coherence of ideas among
            sentences is what constitutes a
            A paragraph is defined as “a group
            of sentences or a single sentence
            that forms a unit” (Lunsford and
            Connors 116).
            Length and appearance do not
            determine whether a section in
            a paper is a paragraph.
            For instance, in some styles of
            writing, particularly journalistic
            styles, a paragraph can be just
            one sentence long. Ultimately, a
            paragraph is a sentence or group of
            sentences that support one main idea.
            In this handout, we will refer to this
            as the “controlling idea,” because it
            controls what happens in the rest
            of the paragraph.


Supported Browsers:

  • Google Chrome 1.0
  • Internet Explorer 4.0
  • Firefox 1.0
  • Opera 3.5
  • Safari 1.0

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!