How to style a video iFrame?

Tags: jquery,css,iframe,html5-video

Problem :

I want to style my iFrame embedded video controls so it won't have the control style of the browser but my own styling. I have searched and couldn't get a suitable answer. Please do anyone know how I can achieve this through JavaScript or CSS or a link which can help me. I can see on some sites like YouTube that the video player is styled.

Solution :

You will need to add your CSS to the iframe by adding a link or style element to its content, just like you would do in a normal document.

Another approach that would fit your problem better is using shadow DOM. The following Javascript code illustrates how you can use this technique.

var host = document.createElement("div");
var shadow = host.createShadowRoot();

var video = document.createElement("video");

// ... set video.src, etc.

var style = document.createElement("style");

// set the styling of your video element, e.g.:
style.innerHTML = "video { border: 5px solid red; }";


// insert the host of the shadow root to the document, e.g.:

The styling you define will only be applied to the HTML inside of the shadow root, thus preventing the rest of your document of being styled. JSFiddle demo.

    CSS Howto..

    How to achieve a two column centered layout, with the main column expandable on wider screens?

    How do I get this menu to stay top right of the image on hover? - CSS, jQuery

    Bootstrap - How to keep the natural container layout while fixing the container to the bottom?

    Chrome (webkit?) not displaying images correctly in a slideshow

    How to use CSS selectors to retrieve specific links lying in some class using BeautifulSoup?

    jquery hide/show list elements from ul

    How to create a header.php and footer.php with CSS files?

    How to put all my elements in line horizontally and Should be Responsive using bootstrap?

    How do I set the width and height of a textarea using CSS?

    How to set the background image width using CSS?

    How to show css div depending upon model value?

    How to set full auto width for input tag

    How to divide in 4 equal parts a li menu

    How to make a navigation bar have equal spacing?

    In IE Compat View, Developer tools shows elements “style” with the class of the previous element

    How to organise my web content?

    How do you deal with Internet Explorer?

    How do I make a play button for my full page video?

    How do I output compressed CSS from Compass?

    How to set the select to have the width of the selected option

    How to make top/bottom borders appear ontop of left/right borders crossbrowser css

    How to dynamically change the style of a comma separated tags with html/css/jquery

    Does anyone know how's layout works?

    How to make text run top-to-bottom in CSS?

    How to add to css class in a single html tag? [duplicate]

    Mobile Toggle Menu - How to Push Content outside the view of the viewport?

    How to apply css class to an html element using jquery in ASP .NET MVC?

    How to hide the button keeping the position? [duplicate]

    Conditional css showing limit items

    How to align icon inserted with :before method?