143
Frontend for Developers HTML for WebApps

Frontend for developers

Embed Size (px)

DESCRIPTION

This presentation was done for MercadoLibre developers. The goal was improving the knowledge about HTML and avoid semantic ambiguities.

Citation preview

Page 1: Frontend for developers

Frontend for DevelopersHTML for WebApps

Page 2: Frontend for developers

The Web Browser

Page 3: Frontend for developers

Web BrowsersThe most important ones.

• Internet Explorer

• Chrome

• Firefox

• Safari

• Opera

Page 4: Frontend for developers

Web BrowsersChrome is bigger than Internet Explorer.

• Chrome

• Internet Explorer

• Firefox

• Safari

• Opera

Page 5: Frontend for developers

1. Parses HTML to construct the DOM tree

2. Renders tree construction

3. Creates layout of the render tree

4. Paints the render

Rendering engineHow it works?

Page 6: Frontend for developers

Web Browser’s parts retrieves resources from the server and visually presents them.

Page 7: Frontend for developers

The DOMis a language-independent API.

Page 8: Frontend for developers

The DOMis implemented in JavaScript in the browser.

Page 9: Frontend for developers

The DOM

html

head body

title h1 p h2 ul

li li

div

pspan img

is the object presentation of the HTML document.

Page 10: Frontend for developers

The DOMis the interface of HTML elements to the outside world.

Page 11: Frontend for developers

Rendering engineby browser.

Engine used by

Gecko Firefox, SeaMonkey, Galeon, Camino, K-Meleon, Flock, Epiphany-gecko ... etc

Presto Opera, Opera Mobile, Nintendo DS & DSi Browser, Internet Channel

Trident Internet Explorer, Windows Phone 7

WebKit Safari, Chrome, Adobe Air, Android Browser, Palm webOS, Symbian S60, OWB, Stream, Flock, RockMelt

Page 12: Frontend for developers

JavaScript engineby browser.

Engine used by

SpiderMonkey Mozilla Firefox

Rhino Mozilla

Carakan Opera

Chakra Internet Explorer > 9

JScript Internet Explorer < 8

V8 Chrome

Nitro Safari

Page 13: Frontend for developers

The User Experience

Page 14: Frontend for developers

• sparse, semantic markup contains all content

• end-user web browser preferences are respected

Progressive Enhancementaims to deliver information to the widest possible audience.

Page 15: Frontend for developers

Progressive Enhancementbasic content should be accessible to all web browsers.

Page 16: Frontend for developers

Progressive Enhancementbasic functionality should be accessible to all web browsers.

Page 17: Frontend for developers

Progressive Enhancementenhanced layout is provided by externally linked CSS.

Page 18: Frontend for developers

Progressive Enhancementenhanced behavior is provided by unobtrusive JavaScript.

Page 19: Frontend for developers

Polyfillsis a feature detection technique for regressive enhancement.

Page 20: Frontend for developers

• The Web Browser

• The User Experience

• The Content Layer

• The Visual Layer

• The Behavior Layer

FrontendIts parts.

Page 21: Frontend for developers

The Content Layer

Page 22: Frontend for developers

• HyperText Markup Language

• Markup language is not programming language

• The web is published in HTML

• It’s maintained by the W3C

What is HTML

Page 23: Frontend for developers

<p>It’s the content</p> Open tag & close tag. Element with content.

<img /> Unique tag. Element without content.

ElementsTypes of elements according to the tag.

Page 24: Frontend for developers

Attributes

<p id=”paragraph”>It’s the content</p> Open tag & close tag. Element with content.

<img src=”/image.jpg” alt=”It has a book.” /> Unique tag. Element without content.

Syntax.

Page 25: Frontend for developers

AttributesThe common attributes for the HTMLElement.

• title

• id

• class

• lang

• dir

• data-*

Page 26: Frontend for developers

Reserved Characters

Entities

Page 27: Frontend for developers

• < can be mixed with tags

• > can be mixed with tags

• “ the quotes start an attribute

• & the ampersand is also reserved

Reserved Characterscannot be used inside the document.

Page 28: Frontend for developers

< --------- &lt;

> --------- &gt;

& --------- &amp;

“ --------- &quote;

Entitiesare used to implement reserved characters.

Page 29: Frontend for developers

10 < 20 <p> 10 &lt; 20 </p>

20 > 10 <p> 10 &gt; 20 </p>

He said: “Don’t do it”<p>He said: &quot;Don’t do it&quot; </p>

Company & Co.<p> Company &amp; Co. </p>

Entitiesexamples.

Page 30: Frontend for developers

The Structurehtml, head & body

Page 31: Frontend for developers

<!doctype html><html>

<head><title>MercadoLibre</title>

</head><body>

<p>The basic content</p><!-- Comment -->

</body></html>

The doctypeis required to do cross browser.

Page 32: Frontend for developers

<!doctype html><html>

<head><title>MercadoLibre</title>

</head><body>

<p>The basic content</p><!-- Comment -->

</body></html>

The html elementis the root of the document.

Page 33: Frontend for developers

<!doctype html><html>

<head><title>MercadoLibre</title>

</head><body>

<p>The basic content</p><!-- Comment -->

</body></html>

The head elementis a collection of metadata.

Page 34: Frontend for developers

<!doctype html><html>

<head><title>MercadoLibre</title>

</head><body>

<p>The basic content</p><!-- Comment -->

</body></html>

The body elementis the place for the content.

Page 35: Frontend for developers

It’s the interface of HTML elements to the outside world

The DOM

Page 36: Frontend for developers

interface HTMLImageElement : HTMLElement { attribute DOMString alt; attribute DOMString src; attribute DOMString crossOrigin; attribute DOMString useMap; attribute boolean isMap; attribute unsigned long width; attribute unsigned long height;

readonly attribute unsigned long naturalWidth;readonly attribute unsigned long naturalHeight;readonly attribute boolean complete;

};

The DOMinterface of a image element.

Page 37: Frontend for developers

PracticesThe best of them

Page 38: Frontend for developers

<!doctype html><html>

<head><title>MercadoLibre</title>

</head><body>

<p>The basic content</p><!-- Comment -->

</body></html>

Commentthe code.

Page 39: Frontend for developers

<img width=”50” height=”90” alt=”Iphone Image” />

Attributesmust always be between quotes.

Page 40: Frontend for developers

<img width=”50” height=”90” alt=”Iphone Image” />

Attributesmust always be between quotes.

Page 41: Frontend for developers

<p onclick=”hideDiv();”></p>

JavaScriptfunctions should never go in event attributes.

Page 42: Frontend for developers

<p onclick=”hideDiv();”></p> not recommended

JavaScriptfunctions should never go in event attributes.

Page 43: Frontend for developers

<p onclick=”hideDiv();”></p>

<p id=”overview”></p>

not recommended

JavaScriptfunctions should never go in event attributes.

Page 44: Frontend for developers

JavaScriptnever goes in head element. <!doctype html><html>

<head><title>MercadoLibre</title><script>

function greet(){alert(“hello world!”);

}</script>

</head><body>

<p>The basic content</p><!-- Comment -->

</body></html>

Page 45: Frontend for developers

JavaScriptnever goes in head element. <!doctype html><html>

<head><title>MercadoLibre</title><script>

function greet(){alert(“hello world!”);

}</script>

</head><body>

<p>The basic content</p><!-- Comment -->

</body></html>

not recommended

Page 46: Frontend for developers

JavaScriptnever goes in head element. <!doctype html><html>

<head><title>MercadoLibre</title>

</head><body>

<p>The basic content</p><!-- Comment --><script>

function greet(){alert(“hello world!”);

}</script>

</body></html>

Page 47: Frontend for developers

<p style=”color:#ffffff;”></p>

CSSrules should never go inline.

Page 48: Frontend for developers

<p style=”color:#ffffff;”></p> not recommended

CSSrules should never go inline.

Page 49: Frontend for developers

<p style=”color:#ffffff;”></p>

<p class=”featured”></p>

not recommended

CSSrules should never go inline.

Page 50: Frontend for developers

MetadataInside the head

Page 51: Frontend for developers

<head>

</head>

The head elementthe place for metadata.

Page 52: Frontend for developers

• Required

• Unique

• ~ 64 characters

The title elementrepresents the document’s name and identifies it out of context.

Page 53: Frontend for developers

<head>

<title>MercadoLibre Argentina</title>

</head>

The title elementrepresents the document’s name and identifies it out of context.

Page 54: Frontend for developers

• rel

• href

• media

• type

The link elementallows you to link the current document to other resources.

<link />

Page 55: Frontend for developers

• alternate

• author

• bookmark

• help

• icon

• license

• next

• nofollow

• noreferrer

• prefetch

• prev

• search

• stylesheet

• tag

The rel attributeadds meaning to the external resources.

Page 56: Frontend for developers

<link rel=”stylesheet” type=”text/css” href=”/external.css” ... />

<link rel=”alternate” type=”application/rss+xml” ... />

<link rel=”prev” title=”Chapter 2” href=”/chapter-2” ... />

<link rel=”next” title=”Chapter 4” href=”/chapter-4” ... />

<link rel=”alternate stylesheet” title=”New Layout” ... />

The rel attributeexamples.

Page 57: Frontend for developers

• name

• charset

• http-equiv

• content

The meta elementrepresents various kinds of metadata.

<meta />

Page 58: Frontend for developers

<meta name=”author” content=”Hernan Mammana” />

<meta name=”copyright” content=”2011” />

<meta name=”description” content=”It’s the ... for HTML talk” />

<meta name=”generator” content=”gDocs” />

<meta name=”keywords” content=”html,talk,slideshow” />

<meta name=”robots” content=”all” />

The meta elementThe name attribute.

Page 59: Frontend for developers

<meta charset=”utf-8” />

The meta elementThe charset attribute.

Page 60: Frontend for developers

The ContentInside the body

Page 61: Frontend for developers

• Headings• h1, h2, h3, h4, h5, h6

• Paragraph• p

• Inside Headings, Paragraph and List• strong, em, cite, sup, sub, acronym, a

The elements for textare used to give meaning to the content.

Page 62: Frontend for developers

<h1>MercadoLibre</h1><h2>Clasificados</h2><h2>Categorías</h2><h2>Recomendados</h2><h2>Más vendidos de la ... </h2><h2>Destacados</h2><h2>Más Compartidos</h2><h2>Subastas desde $1</h2><h2>Historial</h2><h2>12 Cuotas sin interés</h2><h2>Imperdibles del día</h2>

HeadingsExamples from Home.

Page 63: Frontend for developers

<h1>Apple Ipod touch...</h1><h2>Reputación del vendedor</h2><h2>Medios de pago</h2><h2>Medios de envío</h2>

HeadingsExamples for VIP.

Page 64: Frontend for developers

<p>MercadoLibre no vende este artículo ... </p>

<p>Local Palermo Fscomputers Dist Autorizado ... </p>

Paragraphexamples.

Page 65: Frontend for developers

<p><strong>Elige el motivo de tu denuncia: </strong></p>

<p><strong>$ 1.899<sup>99</sup></strong></p>

Inside paragraphs ...Examples.

Page 66: Frontend for developers

ListsTo add meaning

Page 67: Frontend for developers

• Ordered ListTo show rankings, prioritize tasks and search results

• List ItemTo put anything inside the Ordered List

• Unordered ListTo list anything without priorities

• List ItemTo put anything inside the Unordered Lists

Ordered & Unordered ListsThe most used lists on the web.

Page 68: Frontend for developers

<ol><li>Apple Ipod Touch 8 Gb 4ta Generaci... </li><li>Apple Ipod Touch 32gb 4g 4ta Gener... </li><li>Apple Ipod Nano 8gb 6g 6ta Genera... </li>

</ol>

Ordered Listis used to show rankings, prioritize tasks and search results.

Page 69: Frontend for developers

<ul><li>Artículo nuevo </li><li>208 vendidos </li><li>Capital Federal </li>

</ul>

<ul><li>Efectivo </li><li>Visa American... </li><li>Tu compra esta...</li>

</ul>

Unordered Listis used to list anything without priorities.

Page 70: Frontend for developers

• It has three parts• Description List element

• Description Term element

• Description Definition element

Description Listis used to make dictionaries, screenplays and key-value pairs.

Page 71: Frontend for developers

<dl> <dt>Condición:</dt> <dd>Artículo nuevo</dd> <dt>Ubicación:</dt> <dd>capital federal</dd> <dt>Vendidos:</dt> <dd>193vendidos</dd> <dt>Finaliza en:</dt> <dd>Finaliza en 4d 2h</dd></dl>

Definition ListExample.

Page 72: Frontend for developers

TableTo organize the

data

Page 73: Frontend for developers

• The basic elementstable, tr, td, th

• The semantic elementscaption, thead, tbody, tfoot, colgroup, col

The table elementand all its semantic elements.

Page 74: Frontend for developers

The table elementExample.

Page 75: Frontend for developers

<table><tr>

<th>header</th> <th>header</th>

</tr><tr>

<td>data</td><td>data</td>

</tr></table>

The basic elementsThe semantic table elements.

Page 76: Frontend for developers

<table><tr>

<th>header</th> <th>header</th>

</tr><tr>

<td>data</td><td>data</td>

</tr></table>

The table elementThe global data container.

Page 77: Frontend for developers

<table><tr>

<th>header</th> <th>header</th>

</tr><tr>

<td>data</td><td>data</td>

</tr></table>

The tr elementThe row.

Page 78: Frontend for developers

<table><tr>

<th>header</th> <th>header</th>

</tr><tr>

<td>data</td><td>data</td>

</tr></table>

The th elementThe header data element.

Page 79: Frontend for developers

<table><tr>

<th>header</th> <th>header</th>

</tr><tr>

<td>data</td><td>data</td>

</tr></table>

The td elementThe content data element.

Page 80: Frontend for developers

<table><caption>It’s title of the table</caption><thead>

</thead><tfoot>

</tfoot><tbody>

</tbody></table>

The semantic elementsThe semantic table elements.

Page 81: Frontend for developers

<table><caption>It’s title of the table</caption><thead>

</thead><tfoot>

</tfoot><tbody>

</tbody></table>

The semantic elementsThe semantic table elements.

Page 82: Frontend for developers

<table><caption>It’s title of the table</caption><thead>

</thead><tfoot>

</tfoot><tbody>

</tbody></table>

The semantic elementsThe semantic table elements.

Page 83: Frontend for developers

<table><caption>It’s title of the table</caption><thead>

</thead><tfoot>

</tfoot><tbody>

</tbody></table>

The semantic elementsThe semantic table elements.

Page 84: Frontend for developers

<table><caption>It’s title of the table</caption><thead>

</thead><tfoot>

</tfoot><tbody>

</tbody></table>

The semantic elementsThe semantic table elements.

Page 85: Frontend for developers

<table><caption>It’s title of the table</caption><thead>

</thead><tfoot>

</tfoot><tbody>

</tbody></table>

The semantic elementsThe semantic table elements.

Page 86: Frontend for developers

table

first name last name age purchase

The semantic elementsThe semantic table elements.

Page 87: Frontend for developers

table

first name last name age purchase

The semantic elementsThe semantic table elements.

Page 88: Frontend for developers

first name last name age

purchase

table

personal data

The semantic elementsThe semantic table elements.

Page 89: Frontend for developers

first name last name age

purchase

table

personal data

The semantic elementsThe semantic table elements.

Page 90: Frontend for developers

<table><caption>Title of the table</caption><colgroup>

<col /><col /><col />

</colgroup><tfoot>...

</table>

The semantic elementsThe semantic table elements.

Page 91: Frontend for developers

first name last name

age purchase

table

personal data

The semantic elementsThe semantic table elements.

Page 92: Frontend for developers

<table><caption>Title of the table</caption><colgroup>

<col /><col />

</colgroup><col /><tfoot>...

</table>

The semantic elementsThe semantic table elements.

Page 93: Frontend for developers

<table><caption>Title of the table</caption><colgroup id=”personalData”>

<col class=”first-name” /><col class=”last-name” />

</colgroup><col class=”age” /><tfoot>...

</table>

The semantic elementsThe semantic table elements.

Page 94: Frontend for developers

Yes, we can use tables!

Only for data!

Page 95: Frontend for developers

LinksThe hypertext

Page 96: Frontend for developers

• href

• rel

• target

• title

• type

The a elementallows you to link current document to other resources.

Page 98: Frontend for developers

ImagesNon decorative

Page 99: Frontend for developers

• src

• alt

• title

• width

• height

The img elementallows you to insert an image.

Page 100: Frontend for developers

The img element

<img src=”/image.jpg” alt=”It has a book.” />

allows you to insert an image.

Page 101: Frontend for developers

FormsGetting the user’s

data

Page 102: Frontend for developers

The form elementestablishes a relationship between the user and the organization.

Page 103: Frontend for developers

The form elementestablishes a relationship between the user and the organization.

Page 104: Frontend for developers

The form elementestablishes a relationship between the user and the organization.

Page 105: Frontend for developers

The form elementestablishes a relationship between the user and the organization.

Page 106: Frontend for developers

The form elementestablishes a relationship between the user and the organization.

Page 107: Frontend for developers

The form elementestablishes a relationship between the user and the organization.

• Component of a web page

• They have form controls, like text fields & buttons

• The user can interact with them

• The user’s data can be sent to the server

• No client side scripting is needed

• An API is available. It augments the user experience

Page 108: Frontend for developers

<form method=”post” action=”/signup”> </form>

The form elementexample.

Page 109: Frontend for developers

<form method=”post” action=”/signup”> </form>

The form elementThe method attribute.

Page 110: Frontend for developers

<form method=”post” action=”/signup”> </form>

The form elementThe action attribute.

Page 111: Frontend for developers

• fieldset is the element to group similar meaning controls

• legendis the element to give a meaning to the fieldset

• label is the element to give meaning to a control

Semantic elementsfor the form.

Page 112: Frontend for developers

<form method=”post” action=”/signup”><fieldset>

<legend>Regístrate</legend><label>Nombre:</label>

</fieldset></form>

Semantic elementsfor the form.

Page 113: Frontend for developers

• input, It render very different control related to his type attribute.

• selectIt render two list of options, single and multiple.

• optgroupSemantic element to group similar options.

• optionIt’s a option in the select list.

• textareaIt render a control to multiline text.

• buttonIt render a common button. Could be user outside the form tag.

Form controlsThe elements inside the form.

Page 114: Frontend for developers

• hidden

• text

• search

• tel

• url

• email

• password

• datetime

• date

• month

• week

• time

• datetime-local

• number

• range

• color

• checkbox

• radio

• file

• submit

• image

• reset

• button

html5

html5

html5

html5

html5

html5

html5

html5

html5

html5

html5

html5

html5

<input type=”{VALUE}” />

The input elementIt has many types. Each type has a different display.

Page 115: Frontend for developers

<input type=”{TYPE}” name=”{NAME}” id=”{ID}” />

• accept

• autocomplete

• autofocus

• checked

• disabled

• list

• max

• maxlength

• min

• multiple

• pattern

• placeholder

• readonly

• required

• size

• src

• step

• value

The input elementIt has many types. Each type has a different display.

Page 116: Frontend for developers

<input type=”hidden” />

The type hiddenrepresents a value that isn’t intended to be manipulated.

• name

• value

Page 117: Frontend for developers

<input type=”text” />

• autocomplete

• autofocus

• disabled

• maxlength

• placeholder

• readonly

• required

• size

The type textrepresents a one line text edit control for the element’s value.

Page 118: Frontend for developers

<input type=”search” />

• autocomplete

• autofocus

• disabled

• maxlength

• placeholder

• readonly

• required

• size

The type textrepresents a one line text edit control for the element’s value.

Page 119: Frontend for developers

<input type=”tel” />

• autocomplete

• autofocus

• disabled

• maxlength

• placeholder

• readonly

• required

• size

The type telrepresents a control for editing a telephone number.

Page 120: Frontend for developers

<input type=”password” />

• autocomplete

• autofocus

• disabled

• maxlength

• placeholder

• readonly

• required

• size

The type passwordrepresents a one line text edit control for the element’s value.

Page 121: Frontend for developers

<input type=”email” />

• autocomplete

• autofocus

• disabled

• maxlength

• multiple

• placeholder

• readonly

• required

• size

The type emailrepresents a control for editing the e-mail addresses.

Page 122: Frontend for developers

<input type=”url” />

• autocomplete

• autofocus

• disabled

• maxlength

• multiple

• placeholder

• readonly

• required

• size

The type urlrepresents a control for editing a single absolute URL.

Page 123: Frontend for developers

<input type=”file” />

• accept

• autocomplete

• autofocus

• disabled

• multiple

• placeholder

• readonly

• required

• size

The type filerepresents a list of selected files.

Page 124: Frontend for developers

<input type=”date” />

• autocomplete

• autofocus

• disabled

• max

• min

• placeholder

• readonly

• required

• size

• step

The type daterepresents a control for setting a string representing a date.

Page 125: Frontend for developers

<input type=”datetime” />

• autocomplete

• autofocus

• disabled

• max

• min

• placeholder

• readonly

• required

• size

• step

The type datetimerepresents a control for setting a global date and time.

Page 126: Frontend for developers

<input type=”month” />

• autocomplete

• autofocus

• disabled

• max

• min

• placeholder

• readonly

• required

• size

• step

The type monthrepresents a control for setting a string representing a month.

Page 127: Frontend for developers

<input type=”week” />

• autocomplete

• autofocus

• disabled

• max

• min

• placeholder

• readonly

• required

• size

• step

The type weekrepresents a control for setting a string representing a week.

Page 128: Frontend for developers

<input type=”datetime-local” />

• autocomplete

• autofocus

• disabled

• max

• min

• placeholder

• readonly

• required

• size

• step

The type datetime-localrepresents a control for setting a local date and time.

Page 129: Frontend for developers

<input type=”number” />

• autocomplete

• autofocus

• disabled

• max

• min

• placeholder

• readonly

• required

• size

• step

The type numberrepresents a control for setting a string representing a number

Page 130: Frontend for developers

<input type=”range” />

• autofocus

• disabled

• max

• min

• readonly

• required

• size

• step

The type rangerepresents a number, but the exact value is not important.

Page 131: Frontend for developers

<input type=”color” />

• autocomplete

• autofocus

• disabled

• placeholder

• readonly

• required

• size

The type colorrepresents a control for setting a string simple color.

Page 132: Frontend for developers

<input type=”checkbox” />

The type checkboxrepresents a two-state control.

• checked

• disabled

• readonly

• required

• value

Page 133: Frontend for developers

<input type=”radio” />

The type radiorepresents a mutually exclusive options control.

• checked

• disabled

• readonly

• required

• value

Page 134: Frontend for developers

<input type=”image” />

• autofocus

• disabled

• readonly

• required

• src

The type imagerepresents an button from which we can add some behavior.

Page 135: Frontend for developers

<input type=”submit” />

• autofocus

• disabled

• required

• value

The type submitrepresents a button that, when activated, submits the form.

Page 136: Frontend for developers

<input type=”reset” />

• autofocus

• disabled

• required

• value

The type resetrepresents a button that, when activated, resets the form.

Page 137: Frontend for developers

<input type=”button” />

• autofocus

• disabled

• required

• value

The type buttonrepresents a button with no default behavior.

Page 138: Frontend for developers

<select><option>Otros (Debes completar el comentario).</option>

</select>

The select elementrepresents a control for selecting amongst a set of options.

Page 139: Frontend for developers

• autofocus

• multiple

• size

• required

• readonly

• disabled

• name

<select> ... </select>

html5

The select elementAttributes.

Page 140: Frontend for developers

<select><option value=”opt1”>value</option>

</select>

<select><optgroup label=”Group One”>

<option value=”opt1”>value</option></optgroup>

</select>

The select elementExamples.

Page 141: Frontend for developers

The textarea elementrepresents a multiline plain text edit control.

<textarea></textarea>

Page 142: Frontend for developers

• autofocus

• cols

• dirname

• disabled

• maxlength

• name

• placeholder

• readonly

• required

• rows

• wrap

<textarea></textarea>

html5

The textarea elementis used for long inputs of text.

Page 143: Frontend for developers

Thanks