Gesan
Gesan

Reputation: 17

Ways to add video to a website using code

I recently began coding my first webpages and it's lots of fun. Currently I have a project which requires me to add a video to a certain section of the webpage. The problem is that I have never done that before and I'm absolutely clueless as to how to add a video by means of coding. Could somebody be so kind to introduce me to some ways to accomplish this?

In case it is relevant I am trying to build a One-page website and I'm using the following languages: html, css & javascript

Upvotes: 1

Views: 405

Answers (2)

james_bond
james_bond

Reputation: 6906

You can take examples from this page

It depends on the format and where the video is hosted. That page provides some examples, one is:

<video src="videofile.webm" autoplay poster="posterimage.jpg">
Sorry, your browser doesn't support embedded videos, 
but don't worry, you can <a href="videofile.webm">download it</a>
and watch it with your favorite video player!
</video>

Upvotes: 3

Pabs123
Pabs123

Reputation: 3435

Assuming you want a static video, just use a Video Tag and set its source to whatever video you want.

If it's some dynamic video, you can use javascript to set the src element of the video tag after it has loaded.

If it's not a video that exists online, you can use an input as well as The object api to set the source of the video tag.

Upvotes: 0

Related Questions