Hypertext Markup Language Martin Kruli Martin Neask by
Hypertext Markup Language Martin Kruliš, Martin Nečaský by Martin Kruliš (v 1. 0) 6. 3. 2021 1
What is HTML? � HTML = Hypertext Markup Language ◦ World Wide Web's markup language ◦ Language for describing the structure of Web pages � Web page ◦ Semi-structured document �Form of structured data with non-formal structure model �Basically a plain text interleaved by markers (tags) that impose some form of internal structure ◦ Structure denoted in a form of HTML markup by Martin Kruliš (v 1. 0) 6. 3. 2021 2
What is HTML? <!DOCTYPE html> <html lang="en"> <head> <title>Simple web page</title> </head> <body> <h 1>Simple web page</h 1> <p>This is a <em>web page</em> with <a href="http: //whatwg. org/html">HTML 5</a> markup. </p> </body> </html> by Martin Kruliš (v 1. 0) 6. 3. 2021 3
HTML Syntax � HTML Document ◦ Is structured as a tree �Browsers represent the tree in Document Object Model (DOM), which can be manipulated with Java. Script ◦ Various types of nodes �Elements, text, attributes, comments, … by Martin Kruliš (v 1. 0) 6. 3. 2021 4
HTML Syntax � DOM Document Tree Example <html> <body> <h 1>DOM Example</h 1> <p> Document Object Model is an API … h 1 </p> <img src="url" alt="text">. . . </body> DOM Example </html> html body … p img src alt Document Object Model … by Martin Kruliš (v 1. 0) 6. 3. 2021 5
HTML Syntax � HTML Element ◦ Represents a fragment of a web page �Gives semantic meaning to its content ◦ Opening and closing tags work as parentheses for the content (what falls into the element) �Elements without content may omit closing tag �Elements have to be nested (no overlapping) ◦ Attributes �Name-value pairs specified in opening tag �Values are optional and they are optionally enclosed in single or double quotes (recommended) �Quotes are mandatory if the value contains ", ', <, or > by Martin Kruliš (v 1. 0) 6. 3. 2021 6
HTML Syntax � Comments ◦ Enclosed in <!-- and --> ◦ Not displayed when page is rendered � Entities ◦ ◦ ◦ &entity-name; Provide a way to encode special characters <, >, &, " - < , > , & , " - non-braking space Numerically represented characters ü - “ü” by Martin Kruliš (v 1. 0) 6. 3. 2021 7
Evolution of HTML www. whatwg. org 1995 HTML 2. 0 1997 HTML 3. 2 XML 1. 0 2001 2000 1999 HTML 4. 01 2014 HTML 5 www. w 3. org XHTML 1. 0 XHTML 1. 1 XHTML 2 by Martin Kruliš (v 1. 0) 6. 3. 2021 2010 8
Evolution of HTML � What. WG ◦ http: //whatwg. org/html ◦ "Living Standard" (see Last Updated) � W 3 C ◦ http: //www. w 3. org/TR/html 5/ ◦ Formal standardization process �Stages of W 3 C a document (draft, CR, R) by Martin Kruliš (v 1. 0) 6. 3. 2021 9
Web of Documents � Current World Wide Web is sometimes referred to as Web of Documents ◦ HTML as a format for representing documents published on the Web ◦ URLs as unique global identifiers of documents ◦ HTTP for localization and accessing documents by their URLs ◦ Hyperlinks between documents to link related documents on the Web by Martin Kruliš (v 1. 0) 6. 3. 2021 10
Web of Documents http: //. . . Web Page http: //example. com/page. html http: //. . . Web Page http: //. . . Web Page by Martin Kruliš (v 1. 0) 6. 3. 2021 11
Hyperlinks � Hyperlinks ◦ Links to resources which are exposed to user of current document to navigate to those resources <a href="http: //www. google. com">Google</a> �Attribute href specifies URL of linked resource �Content is visible to user (text or any inline elements) ◦ Identifying fragment of a web page �<p id="Para 2">. . . </p> �Is then referenced by fragment part of an URL �<a href="#Para 2">. . . </a> �<a href="http: //www. page. com#Para 2">. . . </a> by Martin Kruliš (v 1. 0) 6. 3. 2021 12
HTML Body � Markup in HTML(5) Body ◦ Text level semantics elements ◦ ◦ ◦ �Denote parts of the text in a HTML document with a specific semantics Sectioning content Grouping content Tables, forms External sources (images) Hyperlinks … by Martin Kruliš (v 1. 0) 6. 3. 2021 13
Text Level Semantics Element Description em Represents stress emphasis of its content. The level of stress is given by the level of nesting of particular em elements strong Represents strong importance of its content. small Represents a side comment. s Represents no longer relevant or accurate content. cite Represents a title of a work (book, article, game, software, song, opera, . . . ). abbr Represents an abbreviation or acronym, optionally with its expansion in title attribute. data Represents its content enriched with its machine readable notation in value attribute. time Represents its content which is a determination of time with machine readable notation in datetime attribute. i Represents its content in a manner indicating different quality of text b Represents its content to which attention is being drawn br Represents a line break by Martin Kruliš (v 1. 0) 6. 3. 2021 14
Sectioning Content � Defining ◦ ◦ Internal Structure of Document Body Content of document is divided into sections Sections are divided to subsections section element – a generic section article element - self-contained section �Independently distributable and reusable �E. g. , a blog post or newspaper article ◦ aside element – separate section �Marginal content �E. g. , a did-you-know aside box ◦ nav element – section containing navigation links by Martin Kruliš (v 1. 0) 6. 3. 2021 15
Sectioning Content <article> <p>This article summarizes technologies. . . </p> <nav> <a href=". . . ">HTML</a><a href=". . . ">CSS</a> </nav> <section> <p>We will start with HTML. </p> <section><p>First, we will go to history. </p></section> <section><p>Then, we will deal with actual 5. 0. </p></section> <aside> <p>Did you know that SGML is a predecessor of HTML? </p> </aside> <section><p>CSS is the second technology. </p></section> <nav> <div><a href=". . . ">Home</a><a href=". . . ">Contact</a></div> </nav> </article> <article>Another article</article> by Martin Kruliš (v 1. 0) 6. 3. 2021 16
Headers and Footers � Headers and Footers ◦ Within a section or for the whole document ◦ header element �Distinguishes header of the nearest section (hierarchically) �Intended (but not required) to contain heading elements (h 1 – h 6) ◦ footer element �Distinguishes footer of the nearest section (hierarchically) �Usually contains copyrights, author info, etc. by Martin Kruliš (v 1. 0) 6. 3. 2021 17
Sectioning Content <article> <header> <h 1>NSWI 117 – Summary of technologies</h 1> </header> <section> <header> <h 1>HTML</h 1> </header> <p>We will start with HTML. </p> </section> <footer> <nav> <div><a href=". . . ">Home</a> <a href=". . . ">Contact</a></div> </nav> </footer> </article> by Martin Kruliš (v 1. 0) 6. 3. 2021 18
Section Headings � Heading Elements h 1 – h 6 ◦ Heading of the nearest section ◦ Headings have rank (level of importance) �Number gives relative rank �h. X has higher rank than h. Y if �X < Y and h. X and h. Y are in the same section �h. Y is in subsection of h. X �h. X has the same rank as h. Y iff they are both from the same section and X = Y by Martin Kruliš (v 1. 0) 6. 3. 2021 19
Section Headings <body> <h 1>NSWI 117 -. . . </h 1> <p>At this page, . . . </p> <h 2>HTML</h 2> • <p>About HTML. . . </p> <h 3>HTML History</h 3> <h 3>HTML Today</h 3> <h 2>CSS</h 2> <p>About CSS. . . </p> </body> NSWI 117 - … • HTML History • HTML Today • CSS by Martin Kruliš (v 1. 0) 6. 3. 2021 20
Section Headings <body> <h 1>NSWI 117 -. . . </h 1> <p>At this page, . . . </p> <section> <h 2>HTML</h 2> <p>About HTML. . . </p> <section> <h 3>HTML History</h 3> </section> <h 3>HTML Today</h 3> </section> <section> <h 2>CSS</h 2> <p>About CSS. . . </p> </section> </body> • NSWI 117 - … • HTML History • HTML Today • CSS by Martin Kruliš (v 1. 0) 6. 3. 2021 21
Section Headings <body> <h 1>NSWI 117 -. . . </h 1> <p>At this page, . . . </p> <section> <h 1>HTML</h 1> <p>About HTML. . . </p> <section> <h 1>HTML History</h 1> </section> <h 6>HTML Today</h 6> </section> <section> <h 1>CSS</h 1> <p>About CSS. . . </p> </section> </body> • NSWI 117 - … • HTML History • HTML Today • CSS by Martin Kruliš (v 1. 0) 6. 3. 2021 22
Grouping Content Element Description p Represents a paragraph pre Represents a block of preformatted text div Element with no special meaning. It is just a block of text. main Represents a block with a dominant content of another block. ul Represents an unordered list ol Represents an ordered list li Represents a list item by Martin Kruliš (v 1. 0) 6. 3. 2021 23
List Example <ul> <li>First item</li> <li>Second item: <ol> <li>HI</li> <li>HELLO</li> <li>GOOD MORNING</li> </ol> </li> <li>Third item</li> </ul> • First item • Second item: 1. HI 2. HELLO 3. GOOD MORNING • Third item by Martin Kruliš (v 1. 0) 6. 3. 2021 24
Tables Element Description table thead table head tbody table body tfoot table footer tr table row th table head td table data (cell) by Martin Kruliš (v 1. 0) 6. 3. 2021 25
Sample Table <table> <thead> <tr> <th>Name</th><th>Email</th><th>Address</th> </tr> </thead> <tbody> <tr> <td>Joe White</td> <td>joe@white. abc</td> <td>Lloyd Ave, Boston</td> </tr> <tr> Name Email <td>Bill Black</td> <td>bill@black. def</td> Joe White joe@white. abc <td>---</td> </tr> </tbody> Bill Black bill@black. def </table> by Martin Kruliš (v 1. 0) Address Lloyd Ave, Boston --- 6. 3. 2021 26
Irregular Tables � Spanning Table Cells ◦ Virtually grouping content of multiple logical cells ◦ Attribute colspan of element td �Spans selected cell over several following columns �Specifies the number of columns taken by the cell ◦ Attribute rowspan of element td �Spans selected cell over several following rows �Specifies the number of rows taken by the cell by Martin Kruliš (v 1. 0) 6. 3. 2021 27
Irregular Tables <table> <tr> <td colspan="2">Adults</td> <td>2</td> </tr> <tr><td>Adult 1</td><td>34</td><td rowspan="2">2</td></tr> <tr><td>Adult 2</td><td>32</td></tr> <td colspan="2">Children</td> <td>3</td> </tr> Adults <tr><td>Child 1</td><td>4</td><td>1</td></tr> Adult 1 <tr><td>Child 2</td><td>8</td><td rowspan="2">2</td></tr> <tr><td>Child 3</td><td>12</td></tr> Adult 2 </table> Children 2 34 32 3 Child 1 4 Child 2 8 Child 3 12 by Martin Kruliš (v 1. 0) 6. 3. 2021 2 28
Forms � HTML Form ◦ Component of web page composed of UI controls ◦ User can interact with form controls �Adding text, selecting options, clicking on buttons, … �Data provided by user can be processed by script � Element form ◦ Attribute method – HTTP method used for transfer �post – data are transferred in HTTP request body �get – data are encoded in URL (query part) ◦ Attribute action – URL where the data are sent to by Martin Kruliš (v 1. 0) 6. 3. 2021 29
Forms � Form Controls ◦ input �Basic input controls �Various types based on input attributes ◦ textarea �Input for longer (multi row) texts ◦ select �Selection list with options ◦ button �Submit or reset button by Martin Kruliš (v 1. 0) 6. 3. 2021 30
Forms Example <form method="get" action="http: //www. example. org/script. php"> Name: <input name="name". . . > Phone: <input name="phone". . . > Preferred delivery time: <input name="time". . . > Comments: <textarea name="comments"></textarea> <button type="submit">Submit Order</button> </form> http: //www. example. org/script. php ? name=John+Smith&phone=555 -1234& time=5 pm&comments=unleashed+dog+at+house by Martin Kruliš (v 1. 0) 6. 3. 2021 31
Forms � Element input - basic form input field ◦ Attribute name specifies identifier of the field �For script which processes the data on server ◦ Attribute type specifies type of the input �text – input is one line of text �+ attribute maxlength – maximal text length �password – same as text but hidden input characters �radio – exclusive choice (radio buttons) from set of fields with the same name �+ attribute value – value send to server (when selected) �+ attribute checked="checked" – default choice �checkbox – multiple choice, same logic as radio by Martin Kruliš (v 1. 0) 6. 3. 2021 32
Element input Example <form method="post" action="http: //www. example. org/script. php"> <p> Name: <input type="text" name="full. Name" maxlength="5"> Password: <input type="password" name="password"> </p> <p>Age: 0 -18: <input type="radio" name="age" value="0"> 19 -65: <input type="radio" name="age" value="19"> 66 -*: <input type="radio" name="age" value="65"> </p> <p>Product: <input type="checkbox" name="product" value="BMW">BMW <input type="checkbox" name="product" value="AUD">Audi <input type="checkbox" name="product" value="POR">Porsche </p> </form> by Martin Kruliš (v 1. 0) 6. 3. 2021 33
Forms � Element input ◦ Attribute type specifies type of the input �submit – submission button �+ attribute value contains displayed button value �reset – reset button �+ attribute value contains displayed button value �hidden – submitted value hidden to user �Fixed value, user cannot change it �file – file submission �Browser allows selecting file on local disk, which is then uploaded to the server by Martin Kruliš (v 1. 0) 6. 3. 2021 34
Element input Example <form method="post" action="http: //www. example. org/script. php"> <p> Name: <input type="text" name="full. Name" maxlength="5"> Password: <input type="password" name="password"> </p> <input type="hidden" name="request. Code" value="H 38 a. JJJ"> <input type="submit" value="Submit Form"> <input type="reset" value="Reset Form"> </form> by Martin Kruliš (v 1. 0) 6. 3. 2021 35
Forms � Element input ◦ The control element might be further specified ◦ maxlength attribute �Maximum number of characters allowed in a text field ◦ size attribute �Number of characters visible in a text field ◦ value attribute �Specifies default/selected field value ◦ disabled="disabled" attribute �Specifies that field is disabled when form loads by Martin Kruliš (v 1. 0) 6. 3. 2021 36
Element input Example <form. . . > <input name="full_name" maxlength="32" size="16" value="Martin Nečaský" disabled="true" title="First name followed by family name. "> <button type="submit">Submit</button> </form> by Martin Kruliš (v 1. 0) 6. 3. 2021 37
Forms � Element select ◦ List of options user selects from ◦ Sub-element option �Content is shown to the user �Attribute value – submitted value �Attribute selected="selected" – default value ◦ Attribute multiple="multiple" �Allows user to select more values ◦ Attribute size �Number of options (rows) displayed to the user �If size=1, the list is shown as drop-down box by Martin Kruliš (v 1. 0) 6. 3. 2021 38
Element select Example <form. . . > <p>Product: <select name="product" size="4" multiple="multiple"> <option value="BMW">BMW</option> <option value="AUD" selected="selected">Audi</option> <option value="MER">Mercedes</option> <option value="SKO">Skoda</option> <option value="CHE">Chevrolet</option> <option value="TOY">Toyota</option> <option value="FOR">Ford</option> </select> </p> </form> by Martin Kruliš (v 1. 0) 6. 3. 2021 39
Forms � Additional Form Elements ◦ Making the form structured and better readable ◦ fieldset element �Groups logically related fields ◦ legend element �Caption for a fieldset element ◦ label element �Caption for a single element (e. g. , an input element) ◦ title attribute �Balloon tip hint for a field �(This is attribute may be used with any HTML element) by Martin Kruliš (v 1. 0) 6. 3. 2021 40
Element select Example <form. . . > <p><label>Name: <input. . . ></label></p> <fieldset> <legend>Contact information</legend> <p><label>Phone: <input. . . ></label></p> <p><label>Email: <input. . . ></label></p> </fieldset> <legend>Timing</legend> <p> <label for="time">Preferred delivery time: </label> <input id="time" title="Time in hh: mm format. ". . . > </p> </fieldset> <p><label>Comments: <textarea></label></p> <button>Submit Order</button> </form> by Martin Kruliš (v 1. 0) 6. 3. 2021 41
Forms in HTML 5 � Element ◦ ◦ ◦ ◦ input HTML 5 Types search - search query field tel - phone number field url - absolute URL (e. g. , page address) field email - email address field date, time, datetime - date/time field number – number (entered as text) field range - number (entered by slide bar) field color – color selection field by Martin Kruliš (v 1. 0) 6. 3. 2021 42
Forms in HTML 5 � HTML 5 input Attributes ◦ autocomplete attribute �Turns field’s automatic completion on/off ◦ autofocus attribute �Turns the focus to the field when the page loads ◦ pattern attribute �Regular expression for field value validation ◦ placeholder attribute �Hint for the user to help with filling the field ◦ required attribute �Field value is mandatory form submission by Martin Kruliš (v 1. 0) 6. 3. 2021 43
Element select Example <form. . . > <input name="phone" autocomplete="off" autofocus="autofocus" pattern="[0 -9]{9}" placeholder="Fill in your 9 -digit phone number" required="required"> <button>Submit</button> </form> by Martin Kruliš (v 1. 0) 6. 3. 2021 44
Submitting Forms � When Form Is Submitted … ◦ Data are encoded and sent to selected destination using given method (get/post) ◦ enctype attribute of element form specifies the format of the encoded data �application/x-www-form-urlencoded �multipart/form-data �text/plain by Martin Kruliš (v 1. 0) 6. 3. 2021 45
Submitting Forms Example <form method="post" action="? " enctype=". . . "> Full Name: <input name="fullname" type="text"> Gender: <input name="gender" type="radio" value="M"> male, <input name="gender" type="radio" value="F"> female <input name="student" type="checkbox" value="1"> student <input type="hidden" name="tag" value="#a& Hx 9%"> <button type="submit">Submit</button> </form> by Martin Kruliš (v 1. 0) 6. 3. 2021 46
Submitting Forms Example � application/x-www-form-urlencoded fullname=Martin+Kruli%C 5%A 1&gender=M&studen t=1&tag=%23 a%26 Hx 9%25 � text/plain fullname=Martin Kruliš gender=M student=1 tag=#a&Hx 9% by Martin Kruliš (v 1. 0) 6. 3. 2021 47
Submitting Forms Example � multipart/form-data --------------- 88242493723271 Content-Disposition: form-data; name="fullname" Martin Kruliš ---------------88242493723271 Content-Disposition: form-data; name="gender" M ---------------88242493723271 Content-Disposition: form-data; name="student" 1 ---------------88242493723271 Content-Disposition: form-data; name="tag" #a&Hx 9% ---------------88242493723271 -- by Martin Kruliš (v 1. 0) 6. 3. 2021 48
Images � Element img ◦ Include image in the document contents ◦ Attribute src – the URL of an image to be loaded ◦ Attributes width and height - image size in pixels �It is a good practice to let the browser know the size before the image is loaded (or if it fails) ◦ Attribute alt – alternative textual representation �Briefly describes, what the image shows �Used, when the image loading fails ◦ Attribute title – same as in form controls by Martin Kruliš (v 1. 0) 6. 3. 2021 49
Document Metadata � Additional Information about The Document ◦ Inside element head ◦ title - document title or name �Identify document for users (browser window caption) ◦ base - URL base for resolving relative addresses ◦ link - links document to other resources �Cascading stylesheet files, for instance ◦ style - embeds style information inside document �Contents is written in CSS stylesheet syntax ◦ meta - additional metadata, HTTP supplements �Description, keywords, document author, … by Martin Kruliš (v 1. 0) 6. 3. 2021 50
Document Metadata <html> <head> <title>Technologies for …</title> <base href="http: //www. ksi. mff. cuni. cz/index. html"> <link rel="stylesheet" href="default. css"> <style type="text/css"> body { font-size: 12 pt; } </style> <meta name="keywords" content="html, example"> <meta http-equiv="content-type" content="text/html; charset=utf-8"> </head> </html> by Martin Kruliš (v 1. 0) 6. 3. 2021 51
More on Links � HTML 5 Definition of Link ◦ Link represents relationship of particular type between current document and other web resource ◦ Syntactically defined by element link and a ◦ Two kinds of links (according to HTML 5 spec. ) �Links to external resources �Augment/further specify current document �Hyperlinks �Exposed to the user to navigate between resources �The kind depends on the element used and on the relationship type (attribute rel) by Martin Kruliš (v 1. 0) 6. 3. 2021 52
More on Links � Link Specification ◦ href attribute �URL of resource linked by relationship ◦ rel attribute �Type of relationship ◦ media attribute �Media linked resource applies to �E. g. , print, screen, all ◦ type attribute �MIME type of linked resource �text/html, application/xhtml+xml, text/css, application/pdf by Martin Kruliš (v 1. 0) 6. 3. 2021 53
More on Links Link type link a Description alternate H H Alternate representation of current document author H H Author of document icon ER - Icon representing current document stylesheet ER - Stylesheet for current document licence H H Copyright license covering current document first H H First document of a series current document is part of last H H Last document of a series current document is part of next H H Next document in a series current document is part of by Martin Kruliš (v 1. 0) 6. 3. 2021 54
More on Links <html> <head> <title>NSWI 117 – Materials</title> <link rel="stylesheet" href="default. css" type="text/css" media="screen"> <link rel="stylesheet" href="default-print. css" type="text/css" media="print"> <link rel="alternate" href="materials. pdf" type="application/pdf" media="print"> </head> <body> <footer>Author: <a href="http: //www. ksi. mff. cuni. cz/~necasky" rel="author"> Martin Nečaský</a> </footer> </body> </html> by Martin Kruliš (v 1. 0) 6. 3. 2021 55
HTML Markup – 4. 01 vs. 5 � Differences ◦ No sense to go through particular differences in this lecture ◦ See http: //www. w 3. org/TR/html 5 -diff by Martin Kruliš (v 1. 0) 6. 3. 2021 56
Discussion by Martin Kruliš (v 1. 0) 6. 3. 2021 57
- Slides: 57