introduction to html farhan nisar university of peshawar

57
Introduction to Html Farhan Nisar University of Peshawar

Upload: xavier-burns

Post on 26-Mar-2015

229 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Html Farhan Nisar University of Peshawar

Introduction to Html

Farhan Nisar

University of Peshawar

Page 2: Introduction to Html Farhan Nisar University of Peshawar

HTML Introduction

• HTML is a language for describing web pages.• HTML stands for Hyper Text Markup Language• HTML is not a programming language, it is

a markup language• A markup language is a set of markup tags• HTML uses markup tags to describe web pages•

Page 3: Introduction to Html Farhan Nisar University of Peshawar

HTML Tags

• HTML markup tags are usually called HTML tags• HTML tags are keywords surrounded by angle

brackets like <html>• HTML tags normally come in pairs like <b> and </b>• The first tag in a pair is the start tag, the second tag is

the end tag• Start and end tags are also called opening

tags and closing tags•

Page 4: Introduction to Html Farhan Nisar University of Peshawar

EXAMPLE

• <html><body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body></html>

Page 5: Introduction to Html Farhan Nisar University of Peshawar

HTML Headings

• <h1>This is a heading</h1><h2>This is a heading</h2><h3>This is a heading</h3>

• HTML Paragraphs

•<p>This is a paragraph.</p><p>This is another paragraph.</p>

Page 6: Introduction to Html Farhan Nisar University of Peshawar

HTML Links

• <a href="http://www.FARHAN0.WEBS.com">This is a link</a>

• HTML Images

• <img src=“ALONE.jpg" width="104" height="142" />

Page 7: Introduction to Html Farhan Nisar University of Peshawar

HTML Attributes

• HTML elements can have attributes• Attributes provide additional

information about an element• Attributes are always specified in the start

tag• Attributes come in name/value pairs

like: name="value“• <a href="http://www.FARHAN.com">This

is a link</a>

Page 8: Introduction to Html Farhan Nisar University of Peshawar

HTML Lines

• The <hr /> tag creates a horizontal line in an HTML page.

• <p>This is a paragraph</p><hr /><p>This is a paragraph</p><hr /><p>This is a paragraph</p>

Page 9: Introduction to Html Farhan Nisar University of Peshawar

HTML Comments

• Comments can be inserted into the HTML code to make it more readable and understandable. Comments are ignored by the browser and are not displayed.

• <!-- This is a comment -->

Page 10: Introduction to Html Farhan Nisar University of Peshawar

HTML Line Breaks

• Use the <br /> tag if you want a line break (a new line) without starting a new paragraph:

• <p>This is<br />a para<br />graph with line breaks</p>

Page 11: Introduction to Html Farhan Nisar University of Peshawar

HTML Formatting Tags

• HTML uses tags like <b> and <i> for formatting output, like bold or italic text.

• These HTML tags are called formatting tags (look at the bottom of this page for a complete reference).

<i> Defines italic text

• <strong> Defines strong text

Page 12: Introduction to Html Farhan Nisar University of Peshawar

The HTML <font> Tag 

<font> tag is deprecated in HTML 4, and removed from HTML5.

• The World Wide Web Consortium (W3C) has removed the <font> tag from its recommendations.

• In HTML 4, style sheets (CSS) should be used to define the layout and display properties for many HTML elements. 

• The example below shows how the HTML could look by using the <font> tag:

Page 13: Introduction to Html Farhan Nisar University of Peshawar

Example

• <p><font size="5" face="arial" color="red">This paragraph is in Arial, size 5, and in red text color.</font></p>

<p><font size="3" face="verdana" color="blue">This paragraph is in Arial, size 5, and in red text color.</font></p>

Page 14: Introduction to Html Farhan Nisar University of Peshawar

Styling HTML with CSS

• CSS was introduced together with HTML 4, to provide a better way to style HTML elements.

• CSS can be added to HTML in the following ways:

• in separate style sheet files (CSS files)• in the style element in the HTML head section• in the style attribute in single HTML element

Page 15: Introduction to Html Farhan Nisar University of Peshawar

HTML Style Example - Background Color

• <html>

<body style="background-color:yellow;"><h2 style="background-color:red;">This is a heading</h2><p style="background-color:green;">This is a paragraph.</p></body>

</html>

Page 16: Introduction to Html Farhan Nisar University of Peshawar

HTML Style Example - Font, Color and Size

• <html>

<body><h1 style="font-family:verdana;">A heading</h1><p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p></body>

</html>

Page 17: Introduction to Html Farhan Nisar University of Peshawar

HTML Style Example - Text Alignment

• <html>

<body><h1 style="text-align:center;">Center-aligned heading</h1><p>This is a paragraph.</p></body>

</html>

Page 18: Introduction to Html Farhan Nisar University of Peshawar

HTML Hyperlinks (Links)

• A hyperlink (or link) is a word, group of words, or image that you can click on to jump to a new document or a new section within the current document.

• When you move the cursor over a link in a Web page, the arrow will turn into a little hand.

• Links are specified in HTML using the <a> tag.• The <a> tag can be used in two ways:• To create a link to another document, by using the href

attribute• To create a bookmark inside a document, by using the

name attribute• Syntex• <a href="url">Link text</a>

Page 19: Introduction to Html Farhan Nisar University of Peshawar

Example

• <a href="http://www.Farhan.com/">Visit farhan</a>

• HTML Links - The target Attribute

• <a href="http://www.farhan.com/" target="_blank">Visit farhan!</a>

Page 20: Introduction to Html Farhan Nisar University of Peshawar

HTML Images - 

• The <img> tag is empty, which means that it contains attributes only, and has no closing tag.

• To display an image on a page, you need to use the src attribute. Src stands for "source". The value of the src attribute is the URL of the image you want to display

• . <img src="url" alt="some_text"/> • <img src=“rock.jpg" alt=" rock" width="304"

height="228" />

Page 21: Introduction to Html Farhan Nisar University of Peshawar

HTML Tables

• Tables are defined with the <table> tag.

• A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the <td> tag). td stands for "table data," and holds the content of a data cell. A <td> tag can contain text, links, images, lists, forms, other tables, etc

Page 22: Introduction to Html Farhan Nisar University of Peshawar

• <table border="1"><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr><tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>

Page 23: Introduction to Html Farhan Nisar University of Peshawar

HTML Table Headers

• <table border="1"><tr><th>Header 1</th><th>Header 2</th></tr><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr><tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>

Page 24: Introduction to Html Farhan Nisar University of Peshawar

HTML ListsUnordered Lists

• An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.

• <ul><li>Coffee</li><li>Milk</li></ul>

Page 25: Introduction to Html Farhan Nisar University of Peshawar

HTML Ordered Lists

• An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.

• <ol><li>Coffee</li><li>Milk</li></ol>

Page 26: Introduction to Html Farhan Nisar University of Peshawar

HTML Definition Lists

• A definition list is a list of items, with a description of each item.

• The <dl> tag defines a definition list.• The <dl> tag is used in conjunction with <dt>

(defines the item in the list) and <dd> (describes the item in the list):

• <dl><dt>Coffee</dt><dd>- black hot drink</dd><dt>Milk</dt><dd>- white cold drink</dd></dl>

Page 27: Introduction to Html Farhan Nisar University of Peshawar

HTML Forms

• HTML forms are used to pass data to a server.• A form can contain input elements like text

fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements.

• The <form> tag is used to create an HTML form:• <form>

.input elements.</form>

Page 28: Introduction to Html Farhan Nisar University of Peshawar

Text Fields

• <form>First name: <input type="text" name="firstname" /><br />Last name: <input type="text" name="lastname" />Password: <input type="password" name="pwd" />

• </form>

Page 29: Introduction to Html Farhan Nisar University of Peshawar

Radio Buttons

• <form><input type="radio" name="sex" value="male" /> Male<br /><input type="radio" name="sex" value="female" /> Female</form>

Page 30: Introduction to Html Farhan Nisar University of Peshawar

Checkboxes

• <form><input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br /><input type="checkbox" name="vehicle" value="Car" /> I have a car </form>

Page 31: Introduction to Html Farhan Nisar University of Peshawar

Submit Button

• <form name="input" action="html_form_action.asp" method="get">Username: <input type="text" name="user" /><input type="submit" value="Submit" /></form>

Page 32: Introduction to Html Farhan Nisar University of Peshawar

The HTML frameset Element

• The frameset element holds one or more frame elements. Each frame element can hold a separate document.

• The frameset element states HOW MANY columns or rows there will be in the frameset, and HOW MUCH percentage/pixels of space will occupy each of them.

Page 33: Introduction to Html Farhan Nisar University of Peshawar

The HTML frame Element

• <frameset cols="25%,75%">   <frame src="frame_a.htm" />   <frame src="frame_b.htm" /></frameset>

• Note:• <frameset>Defines a set of frames• <frame />Defines a sub window (a frame)• <iframe>Defines an inline sub window

(frame)

Page 34: Introduction to Html Farhan Nisar University of Peshawar

HTML Iframes

• An iframe is used to display a web page within a web page.

<iframe src="URL"></iframe>

Page 35: Introduction to Html Farhan Nisar University of Peshawar

Use iframe as a Target for a Link

• An iframe can be used as the target frame for a link

• <iframe src="demo_iframe.htm" name="iframe_a"></iframe><p><a href="http://www.alone.com" target="iframe_a">alonee.com</a></p>

Page 36: Introduction to Html Farhan Nisar University of Peshawar

HTML Colors

• HTML colors are defined using a hexadecimal notation (HEX) for the combination of Red, Green, and Blue color values (RGB).

• The lowest value that can be given to one of the light sources is 0 (in HEX: 00). The highest value is 255 (in HEX: FF)

Page 37: Introduction to Html Farhan Nisar University of Peshawar

Entities

• &lt; is the same as <&gt; is the same as >&#169; is the same as ©

• <div>Defines a section in a document

• <style>Defines style information for a document

• <link />Defines the relationship between a document and an external resource

Page 38: Introduction to Html Farhan Nisar University of Peshawar

Blockquote

• <!-- This is a comment -->• <blockquote>

Text quoted from a source.</blockquote>

• <address>Written by farhan.com<br /><a href="mailto:[email protected]">Email us</a><br />Address: Box 564, Disneyland<br />Phone: +12 34 56 78</address>

Page 39: Introduction to Html Farhan Nisar University of Peshawar

HTML Layouts - Using Tables

• <html><body>

<table width="500" border="0"><tr><td colspan="2" style="background-color:#FFA500;"><h1>Main Title of Web Page</h1></td></tr>

<tr valign="top"><td style="background-color:#FFD700;width:100px;text-align:top;"><b>Menu</b><br />HTML<br />CSS<br />JavaScript</td><td style="background-color:#EEEEEE;height:200px;width:400px;text-align:top;">Content goes here</td></tr>

</table>

</body></html>

Page 40: Introduction to Html Farhan Nisar University of Peshawar

HTML Doctypes

• A doctype declaration refers to the rules for the markup language, so that the browsers render the content correctly

• <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.f16.org/TR/html4/loose.dtd"><html><head><title>Title of the document</title></head>

<body>The content of the document......</body>

</html>

Page 41: Introduction to Html Farhan Nisar University of Peshawar

External Style Sheet

• An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the <head> section:

• <head><link rel="stylesheet" type="text/css" href="mystyle.css" /></head>

Page 42: Introduction to Html Farhan Nisar University of Peshawar

Internal Style Sheet

• An internal style sheet can be used if one single document has a unique style. Internal styles are defined in the <head> section of an HTML page, by using the <style> tag, like this:

• <head><style type="text/css">body {background-color:yellow;}p {color:blue;}</style></head>

Page 43: Introduction to Html Farhan Nisar University of Peshawar

Inline Style

• An inline style can be used if a unique style is to be applied to one single occurrence of an element.

• To use inline styles, use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example below shows how to change the text color and the left margin of a paragraph:

• <p style="color:blue;margin-left:20px;">This is a paragraph.</p>

Page 44: Introduction to Html Farhan Nisar University of Peshawar

The HTML title Element

• <html><head><title>Title of the document</title></head>

<body>The content of the document......</body>

</html>

Page 45: Introduction to Html Farhan Nisar University of Peshawar

The HTML base Element

• <head><base href="http://www.f16.com/images/" /><base target="_blank" /></head>

Page 46: Introduction to Html Farhan Nisar University of Peshawar

The HTML script Element

• <script type="text/javascript">document.write("Hello World!")</script>

Page 47: Introduction to Html Farhan Nisar University of Peshawar

The HTML noscript Element

• <script type="text/javascript">document.write("Hello World!")</script><noscript>Sorry, your browser does not support JavaScript!</noscript>

Page 48: Introduction to Html Farhan Nisar University of Peshawar

ADD a video

• <html>

• <body>

• <embed src=“farhan.mp4”>

• </body>

• </html>

Page 49: Introduction to Html Farhan Nisar University of Peshawar

URL - Uniform Resource Locator

• When you click on a link in an HTML page, an underlying <a> tag points to an address on the world wide web.

• A Uniform Resource Locator (URL) is used to address a document (or other data) on the world wide web.

• scheme://host.domain:port/path/filename • scheme - defines the type of Internet service. The most common

type is http• host - defines the domain host (the default host for http is www)• domain - defines the Internet domain name, like w3schools.com• :port - defines the port number at the host (the default port number

for http is 80) • path - defines a path at the server (If omitted, the document must

be stored at the root directory of the web site)• filename - defines the name of a document/resource

Page 50: Introduction to Html Farhan Nisar University of Peshawar

The Easiest Way to Add Audio to Your Site

• <a href="song.mp3">Play Song</a>

<script type="text/javascript" src="http://mediaplayer.yahoo.com/js"></script>

Page 51: Introduction to Html Farhan Nisar University of Peshawar

Playing Audio in HTML

• <audio controls="controls" height="50px" width="100px">  <source src="song.mp3" type="audio/mpeg" />  <source src="song.ogg" type="audio/ogg" /><embed height="50px" width="100px" src="song.mp3" /></audio>

Page 52: Introduction to Html Farhan Nisar University of Peshawar

Using the Yahoo Media Player

• <a href="song.mp3">Play Song</a>

<script type="text/javascript" src="http://mediaplayer.yahoo.com/js"></script>

Page 53: Introduction to Html Farhan Nisar University of Peshawar

Using A Hyperlink

• If a web page includes a hyperlink to a media file, most browsers will use a "helper application" to play the file.

<a href="song.mp3">Play the song</a>

Page 54: Introduction to Html Farhan Nisar University of Peshawar

Playing Videos in HTML

• <!DOCTYPE HTML>• <html>• <body>

• <video width="320" height="240" controls="controls">• <source src="movie.ogg" type="video/ogg" />• <source src="movie.mp4" type="video/mp4" />•   <source src="movie.webm" type="video/webm" />• <object width="320" height="240" src="movie.mp4">• <embed width="320" height="240" src="movie.swf">• Your browser does not support video• </embed>• </object>• </video>

• </body>• </html>

Page 55: Introduction to Html Farhan Nisar University of Peshawar

Video in Full screen

• If a web page includes a hyperlink to a media file, most browsers will use a "helper application" to play the file.

• <a href="intro.swf">Play a video file</a>

Page 56: Introduction to Html Farhan Nisar University of Peshawar

Playing a YouTube Video in HTML

• <iframe width="420" height="345"src="http://www.youtube.com/embed/XGSy3_Czz8k"></iframe>

Page 57: Introduction to Html Farhan Nisar University of Peshawar

FANKS

• Special thanks to Raza who helped me