HTML Links.docx

21
HTML Links « Previous Next Chapter » Links are found in nearly all Web pages. Links allow users to click their way from page to page. Try it Yourself - Examples HTML links How to create links in an HTML document. (You can find more examples at the bottom of this page) HTML Hyperlinks (Links) The HTML <a> tag defines a hyperlink. A hyperlink (or link) is a word, group of words, or image that you can click on to jump to another document. When you move the cursor over a link in a Web page, the arrow will turn into a little hand. The most important attribute of the <a> element is the href attribute, which indicates the link’s destination. By default, links will appear as follows in all browsers: An unvisited link is underlined and blue A visited link is underlined and purple

Transcript of HTML Links.docx

HTML Links PreviousNext Chapter

Links are found in nearly all Web pages. Links allow users to click their way from page to page.

Try it Yourself - ExamplesHTML linksHow to create links in an HTML document. (You can find more examples at the bottom of this page)

HTML Hyperlinks (Links)The HTML tag defines a hyperlink.A hyperlink (or link) is a word, group of words, or image that you can click on to jump to another document.When you move the cursor over a link in a Web page, the arrow will turn into a little hand.The most important attribute of the element is the href attribute, which indicates the links destination.By default, links will appear as follows in all browsers: An unvisited link is underlined and blue A visited link is underlined and purple An active link is underlined and red

HTML Link SyntaxThe HTML code for a link is simple. It looks like this:Link text The href attribute specifies the destination of a link.ExampleVisit W3Schools which will display like this: Visit W3SchoolsClicking on this hyperlink will send the user to W3Schools' homepage.Tip: The "Link text" doesn't have to be text. It can be an image or any other HTML element.

HTML Links - The target AttributeThe target attribute specifies where to open the linked document.The example below will open the linked document in a new browser window or a new tab:ExampleVisit W3Schools!

Try it yourself

HTML Links - The id AttributeThe id attribute can be used to create a bookmark inside an HTML document.Tip: Bookmarks are not displayed in any special way. They are invisible to the reader.ExampleAn anchor with an id inside an HTML document:Useful Tips Section Create a link to the "Useful Tips Section" inside the same document:Visit the Useful Tips Section Or, create a link to the "Useful Tips Section" from another page:

Visit the Useful Tips Section

Imagelink

Create a link of an image:

No border around the image, but still a link:

MAiLTO link

This is an email link:

Send Mail

Note: Spaces between words should be replaced by %20 to ensure that the browser will display the text properly.

How to enable and tags in all major browsersTo make HTML5 video and audio tags work in all major browsers, simply add the following line of code somewhere in the of your document. That's it! There is no second step!How to embed videoYou can embed video into your page using the following code. For more information and troubleshooting, please visit the video wiki page. How to embed audioYou can embed audio into your page using the following code. For more information and troubleshooting, please visit the audio wiki page. Why use html5media?HTML5 video and audio tags were designed to make embedding a video as easy as embedding an image. They were also designed to give users a faster experience by doing away with browser plugins such as Adobe Flash.Unfortunately, older browsers don't support HTML5 video and audio tags, and even modern browsers don't support a consistent set of video codecs, making embedding a video rather difficult.The html5media project makes embedding video or audio as easy as it was meant to be. It's a fire-and-forget solution, and doesn't require installing any files on your server. Unlike many other HTML5 video players, it allows people to use the video controls supplied by their own web browser. It's one of the smallest, fastest solutions available, and as browser technology improves it will become even faster.Video code html

Video code 2

Playing the Object

If you cannot see this, your computer doesn't support the format

Problems, Problems, and SolutionsDisplaying videos in HTML is not easy!You must add a lot of tricks to make sure your video will play in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera) and on all hardware (PC, Mac , iPad, iPhone). In this chapter W3Schools summarizes the problems and the solutions.

The ElementThe purpose of the tag is to embed multimedia elements in HTML pages.The following HTML fragment displays a Flash video embedded in a web page:Example

Try it yourself Problems If the browser does not support Flash, the video will not play iPad and iPhone do not support Flash videos If you convert the video to another format, it will still not play in all browsers

Using The ElementThe purpose of the tag is to embed multimedia elements in HTML pages.The following HTML fragment displays a Flash video embedded in a web page:Example

Try it yourself Problems: If the browser does not support Flash, the video will not play iPad and iPhone do not support Flash videos If you convert the video to another format, it will still not play in all browsers

Using the HTML5 ElementThe HTML5 tag defines a video or movie.The element works in all modern browsers.The following HTML fragment displays a video in OGG, MP4, or WEBM format:Example

Your browser does not support the video tag.

Try it yourself Problems: You must convert your videos to many different formats The element does not work in older browsers

The Best HTML SolutionThe example below uses 4 different video formats. The HTML 5 element tries to play the video either in MP4, OGG, or WEBM format. If this fails, the code "falls back" to try the element. If this also fails, it "falls back" to the element:HTML 5 + +

Try it yourself Problems: You must convert your videos to many different formats

The YouTube SolutionThe easiest way to display videos in HTML is to use YouTube (see next chapter)!

Using A HyperlinkIf a web page includes a hyperlink to a media file, most browsers will use a "helper application" to play the file.The following code fragment displays a link to a Flash video. If a user clicks on the link, the browser will launch a helper application to play the file:ExamplePlay a video file

Try it yourself

A Note About Inline VideosWhen a video is included in a web page it is called inline video.If you plan to use inline videos, be aware that many people find it annoying. Also note that some users might have turned off the inline video option in their browser.Our best advice is to include inline videos only in pages where the user expects to see a video. An example of this is a page which opens after the user has clicked on a link to see the video.

HTML Multimedia TagsNew: New tags in HTML5.TagDescription

Defines an embedded object

Defines an embedded object

Defines a parameter for an object

NewDefines sound content

NewDefines a video or movie

NewDefines multiple media resources for media elements ( and )

NewDefines text tracks for media elements ( and )

Previous

Click the Link to Play the Object

Play a video file

AUDIO TAGS

HTML Audio PreviousNext Chapter

Sounds can be played in HTML by many different methods.

Problems, Problems, and SolutionsPlaying audio in HTML is not easy!You must know a lot of tricks to make sure your audio files will play in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera) and on all hardware (PC, Mac , iPad, iPhone). In this chapter W3Schools summarizes the problems and the solutions.

Using Plug-insA plug-in is a small computer program that extends the standard functionality of the browser. Plug-ins can be added to HTML pages using the tag or the tag. These tags define containers for resources (normally non-HTML resources), which, depending on the type, will either be displayed by the browsers, or by an external plug-in.

Using The ElementThe tag defines a container for external (non-HTML) content.The following code fragment should play an MP3 file embedded in a web page:Example

Try it yourself Problems: Different browsers support different audio formats If a browser does not support the file format, the audio will not play without a plug-in If the plug-in is not installed on the users' computer, the audio will not play If you convert the file to another format, it will still not play in all browsers

Using The ElementThe tag can also define a container for external (non-HTML) content.The following code fragment should play an MP3 file embedded in a web page:Example

Try it yourself Problems: Different browsers support different audio formats If a browser does not support the file format, the audio will not play without a plug-in If the plug-in is not installed on the users' computer, the audio will not play If you convert the file to another format, it will still not play in all browsers

Using the HTML5 ElementThe HTML5 tag defines sound, such as music or other audio streams.The element works in all modern browsers.The following example uses the tag, and specifies one MP3 file (for Internet Explorer, Chrome, and Safari), and one OGG file (for Firefox and Opera). If anything fails it displays a text:Example

Your browser does not support this audio format.

Try it yourself Problems: You must convert the audio files into different formats The element does not work in older browsers

The Best HTML SolutionThe example below uses the HTML5 element and tries to play the audio either as MP3 or OGG. If it fails, the code "falls back" to try the element:Example

Try it yourself Problems: You must convert the audio files into different formats The element cannot "fall-back" to display an error message

Yahoo Media Player - An Easy Way to Add Audio to Your SiteThe FREE Yahoo Media Player is definitely a favorite: You simply let Yahoo do the job of playing your songs. It plays MP3 and a lot of other formats. You can add it to your page (or blog) with a single line of code, and easily turn your HTML page into a professional playlist:ExamplePlay Sound

Try it yourself To use it, insert the following JavaScript at the bottom of your web page: Then, simply link to your audio files in your HTML, and the JavaScript code automatically creates a play button for each song:

Play Song 1Play Song 2......The Yahoo Media Player presents your readers with a small play button instead of a full player. However, when you click the button, a full player pops up. Note that the player is always docked and ready at the bottom of the window. Just click on it to slide it out.

Using A HyperlinkIf a web page includes a hyperlink to a media file, most browsers will use a "helper application" to play the file.The following code fragment displays a link to an MP3 file. If a user clicks on the link, the browser will launch a helper application to play the file:ExamplePlay the sound

Try it yourself

A Note About Inline SoundsWhen sound is included in a web page, or as part of a web page, it is called inline sound.If you plan to use inline sounds, be aware that many people will find it annoying. Also note that some users might have turned off the inline sound option in their browser.Our best advice is to include inline sounds only in pages where the user expects to hear sounds. An example of this is a page which opens after the user has clicked on a link to hear a recording.

HTML Multimedia TagsNew: New tags in HTML5.TagDescription

Defines an embedded object

Defines an embedded object

Defines a parameter for an object

NewDefines sound content

NewDefines a video or movie

NewDefines multiple media resources for media elements ( and )

NewDefines text tracks for media elements ( and )

PreviousNext Chapter

If you cannot hear the sound, your computer or browser doesn't support the sound format.Or, you have your speakers turned off.

Your browser does not support this audio format.

Play mp3Play wav

Linking To a Song

Click here to play the sound