Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML HTML Video and Audio Media Basics The Audio Element

James Croxford
James Croxford
12,573 Points

Placing audio/video tags into a div which already contains an audio/video element won't show on page?

As per the title really. I'm just practicing this course again, and threw the code into a website I'm currently creating for a portfolio of work.

I've noticed that if I have a div, containing a audio/video element inside, that will appear as intended when I render the webpage. However, if I then throw one or more other audio or video tags inside that same div, then those players won't appear on the webpage.

So this seems to only show the first video:

        <div class="video-audio-example-wrapper">
          <h2>Video Example 1</h2>
          <!--- Method 1 --->
          <video src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" type="video/mp4" controls />
          <!--- Controls attribute- Boolean, so by having the attribute there it means it is true and will display controls. Controls will be browser default. --->
          <!--- can also use autoplay attribute --->

          <h2>Video Example 2</h2>
          <!--- Method 2 --->
          <video controls> 
            <source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" type="video/mp4" />
            <source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.ogg" type="video/ogg" />
          </video>
          <!--- allows for multiple sources of video for browser compatability by putting source into a seperate element inside of video element --->

           <h2>Audio Example</h2>
          <!--- Audio tag- like video tags, either a single tag representing the entire elements, or an open & closing tag with child elements underneath  --->
          <audio controls>
            <source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge-audio.mp3" />
          </audio>

          </div>

But then here I can see both videos and the audio element?

        <div class="video-audio-example-wrapper">
          <h2>Video Example 1</h2>
          <!--- Method 1 --->
          <video src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" type="video/mp4" controls />
          <!--- Controls attribute- Boolean, so by having the attribute there it means it is true and will display controls. Controls will be browser default. --->
          <!--- can also use autoplay attribute --->

          <h2>Video Example 2</h2>


          </div>

         <!--- Method 2 --->
          <video controls> 
            <source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" type="video/mp4" />
            <source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.ogg" type="video/ogg" />
          </video>
          <!--- allows for multiple sources of video for browser compatability by putting source into a seperate element inside of video element --->

           <h2>Audio Example</h2>
          <!--- Audio tag- like video tags, either a single tag representing the entire elements, or an open & closing tag with child elements underneath  --->
          <audio controls>
            <source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge-audio.mp3" />
          </audio>

Is this a quirk of workspaces, or is there an underlying reason for this?

1 Answer

Ezra Siton
Ezra Siton
12,631 Points

Wrong markup - missing closing tag for video element

You write:

<!--- Wrong - Method 1 --->
<video src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" 
type="video/mp4" controls />

correct

Missing closing tag </video> (So you get "weird results" like not showing the next heading and video):

<!--- Correct Method 1 --->
<video src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" 
type="video/mp4" controls /></video>

For the future:

Please mark as a solution to close this topic :)