User login

Recent comments

How to make youtube embed code XHTML valid

Recently I put youtube's embed video code on one of my website and tried check it on XHTML validator, I got some errors related to youtube code and my webpage became invalid. So here I found a way to make it valid with the help of css.

This is the code that youtube.com gives you:
<object width="384" height="313">
    <param name="movie" value="http://www.youtube.com/v/LU8DDYz68kM&amp;hl=en_US&amp;fs=1" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" />
    <embed width="384" height="313" src="http://www.youtube.com/v/LU8DDYz68kM&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true">
    </embed>
</object>
Here is the test results from validator.w3.org

The Solution:

We will do the following:
  1. Remove bad codes from the original code.
  2. Wrap the content with a div.
  3. Styling with CSS.

Remove width and height attribute from «object». Remove other «param» tags except the one shown below. Also remove any extention from video URL like I have done.

Valid code:
<div class="YTvideos">
    <object type="application/x-shockwave-flash" data="http://www.youtube.com/v/LU8DDYz68kM">
        <param name="movie" value="http://www.youtube.com/v/LU8DDYz68kM" />
    </object>
</div>

Styling

.YTvideos object{
	/* You can set it custom */
	width:384px;
	height:313px;
}

Final html code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>YT test</title>
    <style type="text/css">
        .YTvideos object {
            /* You can set it custom */
            width: 384px;
            height: 313px;
        }
    </style>
</head>
<body>
    <div class="YTvideos">
        <object type="application/x-shockwave-flash" data="http://www.youtube.com/v/LU8DDYz68kM">
            <param name="movie" value="http://www.youtube.com/v/LU8DDYz68kM" />
        </object>
    </div>
</body>
</html>
Now this is Valid XHTML
Posted under:

Comments on this post

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
12 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Custom Services

If you are looking a Drupal theme or project developer, feel free to contact me.

Contact

Recent Free Themes

Recent Articles


Browse