IT Engineering I Instructor: Behrang Assemi tbassemi@gmail.com HTML IT Engineering I Instructor: Behrang Assemi tbassemi@gmail.com
What is HTML? Hypertext Markup Language Hypertext:Text with links to other documents A key technology for the Web A simple language for specifying document structure and content "page description language" Derived from the Standard Generalized Markup Language (SGML) language system
What is Markup? HTML An <emph>important</emph> concept Markup languages have special elements that mark formatting or semantics The marks are ASCII text "inserted" into the ASCII text representing document content Unlike programming languages, data is primary HTML An <emph>important</emph> concept LaTeX An {\em important} concept
HTML Markup (Tags) Simple start tag: <TITLE> End tag: </TITLE> Start tag with attributes: <body bgcolor=white> <body bgcolor="white" >
Tag syntax (1) tag ::= < element-name attribute-pair* > attribute-pair ::= attribute-name = string element-name ::= sequence of letters and digits, starting with letter attribute name ::= same as element-name string ::= sequence of characters, often quoted
Tag and Element syntax (2) Tags are mostly case-insensitive exception: some attribute values End tags element-name is preceded by a slash / never have attributes Boolean attributes don’t need values
Practicing HTML! If you make a mistake in HTML… What do you need? you will not bomb or crash; your web page just won't look right. It is easy to correct the code. What do you need? A web browser Internet Explorer Mozilla FireFox SeaMonkey Opera A text editor Notepad Notepad++ UltraEdit
HTML Structure Minimal legal HTML document: <html> <head> <title> Test Document</title> </head> <body> <!– This is a comment Content goes here --> </body> </html>
HTML has two parts HEAD: Information about the document TITLE: appears in title bar META: description of your page <meta name="description" content="Free Web tutorials on HTML"> This meta element defines keywords for your page: <meta name="keywords" content="HTML,XML,JavaScript"> Other <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> BODY: visible content of document For now: we ignore scripts and frames Two kinds: block structure phrase structure
First HTML Example 5 <!-- Fig. 4.1: main.html --> 6 <!-- Our first Web page --> 7 8 <html> 9 <head> 10 <title>Internet and WWW How to Program - Welcome</title> 11 </head> 12 13 <body> 14 <p>Welcome to XHTML!</p> 15 </body> 16 </html>
Headers/Headings Headers/Headings Six levels (H1… H6) <h1>Most major heading</h1> <h2>Next level heading</h2> <h3>Next level heading</h3> <h4>Next level heading</h4> <h5>Next level heading</h5> <h6>Least major heading</h6>
Headers/Headings (example) 5 <!-- Fig. 4.4: header.html --> 6 <!-- XHTML headers --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Internet and WWW How to Program - Headers</title> 11 </head> 12 13 <body> 14 15 <h1>Level 1 Header</h1> 16 <h2>Level 2 header</h2> 17 <h3>Level 3 header</h3> 18 <h4>Level 4 header</h4> 19 <h5>Level 5 header</h5> 20 <h6>Level 6 header</h6> 21 22 </body> 23 </html>
Linking Anchor <a>: basis of hypertext links defines a section of linkable material <HREF>: URL of link target Example <a href="http://www.somewhere.com/#aTarget" > A Link to Somewhere Else </a>
15 <h1>Here are my favorite sites</h1> 16 17 <p><strong>Click a name to go to that page.</strong></p> 18 19 <!-- Create four text hyperlinks --> 20 <p><a href = "http://www.deitel.com">Deitel</a></p> 21 22 <p><a href = "http://www.prenhall.com">Prentice Hall</a></p> 23 24 <p><a href = "http://www.yahoo.com">Yahoo!</a></p>
5 <. -- Fig. 4. 6: contact. html --> 6 < 5 <!-- Fig. 4.6: contact.html --> 6 <!-- Adding email hyperlinks --> 7 8 <html> 9 <head> 10 <title>Internet and WWW How to Program - Contact Page</title> 11 </head> 12 13 <body> 14 15 <p> 16 My email address is 17 <a href = "mailto:deitel@deitel.com"> 18 deitel@deitel.com 19 </a> 20 . Click the address and your browser will 21 open an e-mail message and address it to me. 22 </p> 23 </body> 24 </html>
Lists Lists Simple lists all use "list items" <LI> (end optional) Unordered lists <UL></UL> Ordered lists <OL></OL> Definition lists Definition list <Dl></DL> Definition term<DT> Definition data <DD> Lists of all types may be nested -- Don’t forget the end tags!
5 <. -- Fig. 4. 10: links2. html --> 6 < 5 <!-- Fig. 4.10: links2.html --> 6 <!-- Unordered list containing hyperlinks --> 7 8 <html> 9 <head> 10 <title>Internet and WWW How to Program - Links</title> 11 </head> 12 13 <body> 14 15 <h1>Here are my favorite sites</h1> 16 17 <p><strong>Click on a name to go to that page.</strong></p> 18 19 <!-- create an unordered list --> 20 <ul> 21 22 <!-- add four list items --> 23 <li><a href = "http://www.deitel.com">Deitel</a></li> 24 25 <li><a href = "http://www.w3.org">W3C</a></li> 26 27 <li><a href = "http://www.yahoo.com">Yahoo!</a></li> 28 29 <li><a href = "http://www.cnn.com">CNN</a></li> 30 </ul> 31 </body> 32 </html>
5 <. -- Fig. 4. 11: list. html --> 6 < 5 <!-- Fig. 4.11: list.html --> 6 <!-- Advanced Lists: nested and ordered --> 7 8 <html> 9 <head> 10 <title>Internet and WWW How to Program - Lists</title> 11 </head> 12 13 <body> 14 15 <h1>The Best Features of the Internet</h1> 16 17 <!-- create an unordered list --> 18 <ul> 19 <li>You can meet new people from countries around 20 the world.</li> 21 <li> 22 You have access to new media as it becomes public: 23
24 <. -- this starts a nested list, which uses a --> 25 < 24 <!-- this starts a nested list, which uses a --> 25 <!-- modified bullet. The list ends when you --> 26 <!-- close the <ul> tag. --> 27 <ul> 28 <li>New games</li> 29 <li> 30 New applications 31 32 <!-- nested ordered list --> 33 <ol> 34 <li>For business</li> 35 <li>For pleasure</li> 36 </ol> 37 </li> 38 39 <li>Around the clock news</li> 40 <li>Search engines</li> 41 <li>Shopping</li> 42 <li> 43 Programming 44 45 <!-- another nested ordered list --> 46 <ol> 47 <li>XML</li> 48 <li>Java</li>
49 <li>XHTML</li> 50 <li>Scripts</li> 51 <li>New languages</li> 52 </ol> 53 54 </li> 55 56 </ul> <!-- ends the nested list of line 27 --> 57 </li> 58 59 <li>Links</li> 60 <li>Keeping in touch with old friends</li> 61 <li>It is the technology of the future!</li> 62 63 </ul> <!-- ends the unordered list of line 18 --> 64 65 </body> 66 </html>
Block Structure Paragraph: <p> (end optional) <BR> forced line break <HR> horizontal rule <PRE> preformatted text Preserves spaces and line breaks
Presentation Phrase Structure Whitespace is collapsed Font changes Bold <B> , italic <I> , Teletype text <TT> <FONT> specifies font to use, deprecated <font size="3" color="red"> This is some text! </font> <font size="1" color="blue"> This is some text! </font> <font face="arial" color="red"> This is some text! </font> Emphasis <EM>, <STRONG>, <CODE>, etc. Subscripts <SUB> and superscripts <SUP> This is some text!
Images Images <IMG> Example: SRC attribute: URL of image ALT attribute: alternative text Example: <IMG SRC= "martian.gif" WIDTH=100 HEIGHT=100 ALT="Martian" >
5 <. -- Fig. 4. 7: picture. html --> 6 < 5 <!-- Fig. 4.7: picture.html --> 6 <!-- Adding images with XHTML --> 7 8 <html> 9 <head> 10 <title>Internet and WWW How to Program - Welcome</title> 11 </head> 12 13 <body> 14 15 <p> 16 <img src = "xmlhtp.jpg" height = "238" width = "183" 17 alt = "XML How to Program book cover" /> 18 <img src = "jhtp.jpg" height = "238" width = "183" 19 alt = "Java How to Program book cover" /> 20 </p> 21 </body> 22 </html>
Tables <TABLE>: Intended for display of tabular data Widely used for formatting control <TR>: table row <TD>: table data (individual cell data) <TH>: Table Header cell in a table. usually bold.
Other table related tags Complex model <THEAD>, <TFOOT>, <TBODY> <COLGROUP>, <COL> <CAPTION> table caption.
Frame Example (Cont’d)
Framesets and Frames display more than one Web page/HTML document in the same browser window. The browser window is divided into multiple regions, or frames Each frame displays a unique web page Each frame is independent of the others
Frame Example <HTML> <HEAD> <title> The first frames page</title> </HEAD> <FRAMESET rows =20%,60%,20%> <FRAME NAME = “myTopFrame" SRC="top.html"> <FRAME NAME = “myMiddleFrame" SRC="middle.html"> <FRAME NAME = “myBottomFrame" SRC="bottom.html"> </FRAMESET> </HTML>
Frames (cont.) FRAMESET elements define a collection of frames A 2x2 grid. <FRAMESET rows="80%,20%" cols="20%,80%" > Three columns: the second has a fixed width of 250 pixels (useful, for example, to hold an image with a known size). The first receives 25% of the remaining space and the third 75% of the remaining space. <FRAMESET cols="1*,250,3*"> ...the rest of the definition... </FRAMESET> FRAME elements specify the source of each frame’s content in left-to-right, top-to-bottom order
More complex frames
Linking in frames <a href="foo.html" target="myframe"> Each frame may contain hyperlinks Each hyperlink can be targeted to different frame or a new window <a href="foo.html" target="myframe"> _blank opens a new, unnamed window _self opens the link in the current frame (default) _top opens the link in the full, unframed browser window (throws you out of the frameset) _parent opens the link in the immediate frameset parent (calling frame)
Can you design Google page?
...HTML Forms <form>: Just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on the Web pages Purpose: to ask the user for information to sent back to the server A form is an area that can contain the form elements Example <form parameters> ...form elements... </form>
HTML Forms Form elements: buttons, checkboxes, text fields, radio buttons, drop-down menus. A form usually contains a Submit button to send the information filled in the form elements to the server
The <form> tag… The <form arguments> ... </form> tag encloses form elements (and probably other HTML tags as well) The arguments of form tell what to do with the user input action="url" (required) Specifies where to send the data when the Submit button is clicked
...The <form> tag method="get" (default) method="post" Form data is sent as a URL with ?form_data info appended to the end method="post" Form data is sent in the body of the URL request
The <form> tag target="target" where to open the page sent as a result of the request target= _blank open in a new window target= _top use the same window
Understanding data encoding name/value pairs reserved set of characters for separators + for space & for separating pairs hexadecimal encoding first=Ali&last=Alavi&simple=Submit+Name
Transporting data: GET method Simple, default method Limit of 1024 chars for the URL Only a limited information can be transmitted in this way. Appends encoded data to the URL http://mysite.com/register.php?first=Ali&last=Alavi&simple=Submit+Name Searching IT Engineeing in google: http://www.google.com/search?hl=en&q=IT+Engineering Advantage: you can bookmark the form
Transporting data: POST method The data is sent in the body of the http request. Thus it can be as long as you want.
The <input> tag Most, but not all of the form elements with a type="..." argument to tell which kind of element it is. type can be text, checkbox, radio, password, hidden, submit, reset, button, file, or image Other common input tag arguments include: name: the name of the element value: the "value" of the element
Text, Textarea, password A text field: <input type="text" name="textfield" value="with an initial value" > A multi-line text field <textarea name="textarea" cols="24" rows="2" >Hello</textarea> A password field: <input type="password" name="textfield3" value="secret" >
Buttons A submit button: <input type="submit" name=“mysubmit" value="Submit" > A reset button: <input type="reset" name=“myreset" value="Reset" > A plain button: <input type="button" name=“mypushmebutton" value="Push Me" >
Checkboxes A checkbox: <input type="checkbox" name="checkbox" value=“val1" checked> type: "checkbox" name: used to refer this form element value: value to be returned when the element is checked Note that there is no text associated with the checkbox — you have to supply text in the surrounding HTML
Radio buttons Radio buttons: <br> <input type="radio" name="radiobutton" value="myValue1"> male<br> <input type="radio" name="radiobutton" value="myValue2" checked>female<br> grouping If two or more radio buttons have the same name, the user can only select one of them at the same time As with checkboxes, radio buttons do not contain any text
Drop-down menu or list A menu or list: <select name="select"> <option value="FF0000"> red </option> <option value="008000"> green</option> <option value="0000FF"> blue </option> </select> Additional arguments: size: the number of items visible in the list (default is "1") multiple: if set to "true", any number of items may be selected (default is "false")
Hidden fields including hidden fields A hidden field: <input type="hidden" name="hiddenField" value="yeyeyeyeye"> <-- right there, don’t you see it? What reason is this for? All input fields are sent back to the server, including hidden fields This is a way to include information that the user doesn’t need to see
A complete example!? <html> <head> <title> Get Identity </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" > </head> <body> <p><b> Who are you? </b></p> <form method="post" action=" " > <p> Name: <input type="text" name="textfield" > </p> <p> Gender: <input type="radio" name="gender" value="m" >Male <input type="radio" name="gender" value="f" >Female</p> </form> </body> </html>
An email form! <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Feedback Form</title> </head> <body bgcolor="white"> <h1>Feedback Form</h1> <form action="mailto:tbassemi@gmail.com" method="get" enctype="text/plain"> Name:<input type="text" name="name" size="30" /><br /> Please rate my site from 1 to 10 (1 = bad and 10 = good): <br /> <select name="rating"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option selected>10</option> </select><br /> How would you suggest I improve it?<br /> <textarea name="improve" rows="5" cols="30"></textarea> <br /> <input type="submit" value="Send feedback!" /> <input type="reset" /> </form> </body> </html>
META Tag Used in HEAD: This meta element defines a description of your page: <meta name="description" content="Free Web tutorials on HTML"> This meta element defines keywords for your page: <meta name="keywords" content="HTML,XML,JavaScript"> The following meta, automatically refreshes the page to the most recent version, or redirect to another page after a preset number of seconds: <meta http-equiv="refresh" content="5; url=newurl.html"> Other <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> <META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 2007 08:21:57 GMT"> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> <META HTTP-EQUIV="Content-Language" CONTENT="en-GB"> <META HTTP-EQUIV="Content-Language" CONTENT="fa"> <META HTTP-EQUIV="Set-Cookie" CONTENT="cookievalue=xxx;expires=Friday, 31-Dec-2007 23:59:59 GMT; path=/">