Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to display video background in html

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 264
    Comment on it

    In this post, you will learn about video display in background using html and css. There is video tag in HTML5 which you can use to embed a video in your web page.

    <video width=450" height=340" controls autoplay>
      <source src=abc.mp4" type="video/mp4">
      <source src=abc.ogg" type="video/ogg">
    </video>

    If you do not add controls attribute, it will not display video controls like play, pause or volume. autoplay attribute can be used to start a video automatically.

    There can be multiple source file in different format as browser will check for the suitable format for that video. It is supported by all the major browsers like firefox, chrome, safari, IE.

    Following is the example:

    HTML:

    <!DOCTYPE html>
    <html>
    <head>
    <title>background video</title>
    </head>
    <body>
        <video webkit-playsinline="" data-setup="{}" preload="auto" class="vjs-tech" id="big-video-vid-1_html5_api" style="position: absolute; width: 100%;" autoplay="" poster="null" src="http://static.mediaboom.com/wp-content/themes/mb3/video/backgrounds/home.mp4" src="http://static.mediaboom.com/wp-content/themes/mb3/video/backgrounds/home.ogv"></video>
        <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
        tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
        quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
        consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
        cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
        proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
    
    </body>
    </html>

    CSS:
     

    video{ position: fixed;
        top: 50%;
        left: 50%;
        min-width: 100%;
        min-height: 100%;
        width: auto;
        height: auto;
        -webkit-transform: translateX(-50%) translateY(-50%);
        transform: translateX(-50%) translateY(-50%);
        -ms-transform: translateX(-50%) translateY(-50%);
        -webkit-transform: translateX(-50%) translateY(-50%);
        z-index: -100;
    }

    You can check a demo here.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: