jQuery plugin: Fullscreen Background

27

If you’re a webdeveloper or designer I am pretty sure you’ve run into the problem of people wanting to have “fullscreen content” or just background images that will stretch in the most optimal way to the users screen.
Lately I found that a lot of people are asking for fullscreen backgrounds, videos and other types on stuff. So to prevent myself from reinventing the wheel over and over again I made a small jQuery plugin, and thought you guys might like it too.

So here it is: Fullscreen Background for jQuery.

Tweet

Download
Download from GitHub Example
Look at the goods

How to use.

And using it is so easy; anyone can do it!

Oh, and it works in every browser I could test it in. (IE7 and higher, Firefox, Opera, Safari and Chrome)

Here’s a short step by step installation guide:

  1. Put the following code in the <head> section of your webpage:

    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="jquery.fullscreenBackground.js">
    </script>
    
  2. Have the following structure in your HTML (or something similar):

    <div class="content">
        Content goes here
    </div>
    <div id="background-image">
        <img src="path/to/img.jpg" alt="" width="800" height="600" />
    </div>
    
  3. Remember to define the width and height of the images! This is important.
  4. Then, in your CSS. Make sure the content (not the background image container) is absolute and has a higher z-index than 1.
  5. Finally add this in a piece of Javascript, preferably in $(document).ready();
    $("#background-image").fullscreenBackground();
    

The options!

The plugin allows a few settings to give to the function:

selector (default: “img”)
The selector that will be used when digging through the element you’re calling the function on.

fillOnResize (default: true)
Set to true if the image has to resize to the screen if the screensize changes. I think most will leave this set to true.

defaultCss (default: true)
Set to true if you want to add some standard CSS to the elements. If you are experiencing problems you can set this to false and do the CSS in your own stylesheet.

Conclusion:

Quick and easy: it really does the trick here.

Absolutely no rocket science, but it will prevent you from coding it again in the future.

Let me know what you think!

Articles like this one

Articles like this one

If you liked this article you can add this post to:


 

19 Comments

  1. Orgnix Creatives said: May 21, 2025 at 7:23 am | Permalink

    Thanks for sharing. We are looking around for an easier way to do a fullscreen background. By the way, the artwork you use in your example is beautiful. Who’s the artist?


  2. Tony said: May 22, 2025 at 10:49 am | Permalink

    Hi, thank you for sharing this useful plugin, Could you explain me please, how to center the div with the text? I mean, i want it to be placed exactly in the middle even if the resolution changes…

    thank you for the help

    Tony


  3. Gaya said: May 24, 2025 at 11:12 am | Permalink

    @Orgnix: I don’t know. Stumbled on it a while back. Love it too 🙂 thanks.

    @Tony: You can position the div in Javascript.


  4. Teru said: June 15, 2025 at 5:04 pm | Permalink

    Thank you for your great work. I would like to use this at work. What is license?


  5. e11world said: July 11, 2025 at 6:02 pm | Permalink

    Good method to do this and the artwork used in the example is stunning.


  6. Matt Magi said: July 15, 2025 at 7:36 pm | Permalink

    Been looking for a lightweight version of the supersized plugin that is strictly just for a background image found lots but they were all dated back to 2010-2011, glad I stumbled across this its going to work perfect!


  7. Magnus said: July 31, 2025 at 8:34 pm | Permalink

    hi!
    This is really great plugin 🙂 big thx!
    I have one problem though..
    i think its my css that is the problem, but anyway, il have to ask you..
    This should work fine on mobile devices such as iphone right? 🙂


  8. Larry said: August 3, 2025 at 2:49 am | Permalink

    About 145px of my image cuts off from the top. I noticed it does the same thing on your example too. Is there anyway to properly display my image from the top and left?


  9. Brad said: September 13, 2025 at 4:16 pm | Permalink

    Pretty good, but it would be better if the image would fade in once loaded instead of revealing itself as it loads.


  10. Frank said: September 15, 2025 at 10:04 am | Permalink

    Great work! It would be fantastic if the image could be loaded from a CSS element instead of from the HTML markup.


  11. Rajesh said: October 31, 2024 at 2:22 pm | Permalink

    Good work bro..so simple and easy to use. Please work around on it to make a simple background slideshow.
    The image used in the demo is amazing..really great


  12. Casey said: November 28, 2024 at 12:10 am | Permalink

    I’ve got to say, I love this. It was easy to use and works great! I have one question though, is there a way to use this for dynamically resizing a php file? My header is php and I’d like for it to resize along with the background for different screen resolutions.


  13. Jerome Heuze said: December 12, 2024 at 4:00 am | Permalink

    Great plug in – Thank you.

    Tip: if you do not want to see the scrolling bars when your content is not long enough just have a reset css in your code – that will fix it. 🙂


  14. Jerome Heuze said: December 12, 2024 at 4:05 am | Permalink

    oh by the way you can use position:relative; as well instead of absolute for your content blocks.

    header, #content, footer {z-index:2;position: relative;display:block;}


  15. Yess! said: January 27, 2025 at 1:16 pm | Permalink

    Will this also work for video? Like the video tag in html5?


  16. Yess! said: January 27, 2025 at 1:17 pm | Permalink

    Some more info:

    I want to have a background video, but it should be full screen and resize when you make your browser smaller/bigger (html5 video tag I use).


  17. Gaya said: January 28, 2025 at 9:20 am | Permalink

    @Yess!: This script works with different types of tags. Try this: $(element).fullscreenBackground({ selector: “video” });


  18. Vince said: January 30, 2025 at 4:47 am | Permalink

    Great script! I need my image to anchor on the top right corner, the script by default anchors it with the top left. I’m not very familiar with JS, so how would I modify it so that when the window shrinks, the top right of the image is still in the viewport? Thanks


  19. Enache said: February 7, 2025 at 7:33 am | Permalink

    Great little piece of work, i need to ask you if it’s posibile to have more than one background like this on a page to resize like that, i mean to have two div one on top of either. Thanks in advance


Leave a Comment

Your email is never shared. Get your own avatar with gravatar! Required fields are marked *

*

*