HTML5
Building Web apps with HTML, CSS and Javascript
Agenda
Agenda
Agenda
Agenda
Agenda
Agenda
Agenda
Agenda
Agenda
Agenda
Agenda
Agenda
Agenda
1. Introduction
This course covers HTML5 from the ground up, trying to avoid all the padding ;-)
Example-oriented course
We'll provide you with the tools you need to become an Web ninja :-O
Ongoing work... just as the specifications ;-)
2. What is HTML5?
- HTML5 is a family of technologies and specifications:
- Javascript : programming language (interactivity, content manipulation, data consumption, etc.)
- CSS : style or appearance of the pages
- HTML : structure of the pages
- The Web platform:
- Current status:
- Just check it out yourself:
- http://caniuse.com/
- http://mobilehtml5.org/ (mobile is a must!)
- Just check it out yourself:
2. What is HTML5?
3. Getting started with HTML
- HTML is a mark-up language
- Anatomy of a HTML element:
- Tag
- Content
- Attributes
3. Getting started with HTML
- HTML is a mark-up language
- Anatomy of a HTML element:
- Tag
- Content
- Attributes
3. Getting started with HTML
- HTML is a mark-up language
- Anatomy of a HTML element:
- Tag
- Content
- Attributes
3. Getting started with HTML
- HTML is a mark-up language
- Anatomy of a HTML element:
- Tag
- Content
- Attributes
3. Getting started with HTML
- HTML is a mark-up language
- Anatomy of a HTML element:
- Tag
- Content
- Attributes
3. Getting started with HTML
- HTML document:
- Text file
- .html (convention)
- Anatomy of an HTML document (outer structure):
3. Getting started with HTML
- HTML document:
- Text file
- .html (convention)
- Anatomy of an HTML document (metadata):
3. Getting started with HTML
- HTML document:
- Text file
- .html (convention)
- Anatomy of an HTML document (content):
3. Getting started with HTML
- Element relationships:
- Parent
- Child
- Descendants
- Siblings
- Document tree ( http://livedom.validator.nu/)
- Element types:
3. Getting started with HTML
-
HTML entities:
- Allow using reserved characters in texts
- Formatting:
- &entity_name;
- &#entity_number;
3. Getting started with HTML
- Global attributes:
-
accesskey:
- Keyboard shortcut to select elements on the page
- Set focus using Control + Alt + Key
-
accesskey:
3. Getting started with HTML
- Global attributes:
-
class:
- Categorize elements
- Multiple classes
- Does nothing per se
-
class:
3. Getting started with HTML
- Global attributes:
-
contenteditable:
- Let the visitor change the content of the page
- Values: "true" or "false"
- No value: inherits it from parent
-
contenteditable:
3. Getting started with HTML
- Global attributes:
-
contextmenu:
- The menu pops up when the user triggers it
- Supported by Firefox
-
contextmenu:
3. Getting started with HTML
- Global attributes:
-
dir:
- Direction of the text
-
dir:
3. Getting started with HTML
- Global attributes:
-
draggable:
- Specifies if an element is draggable or not
-
draggable:
3. Getting started with HTML
- Global attributes:
-
dropzone:
- Whether the dragged data is copied, moved or linked, when it is dropped on the element
- Not currently supported by major browsers
-
dropzone:
3. Getting started with HTML
- Global attributes:
-
hidden:
- The element is not yet, or is no longer, relevant
- The element should not be shown
- Space not reserved
-
hidden:
3. Getting started with HTML
- Global attributes:
-
id:
- Assigns a unique identifier to the element
- Must be unique within the HTML document
- Navigation to the element via adding #id to the URL
-
id:
3. Getting started with HTML
- Global attributes:
-
lang:
- Specifies the language of the element's content
- Must be a valid ISO value
- Let the browser adjust the display of the content
-
lang:
3. Getting started with HTML
- Global attributes:
-
spellcheck:
- Specifies if the browser should check the spelling of the element's content
-
spellcheck:
3. Getting started with HTML
- Global attributes:
-
style:
- Allows to define CSS styles directly on an element
-
style:
3. Getting started with HTML
- Global attributes:
- tabindex :
- Order in which the Tab key moves the focus through the elements
3. Getting started with HTML
- Global attributes:
- title :
- Provides additional information about an element
- Commonly used to show tool tip information
4. Getting started with CSS
- Cascading Style Sheets (CSS)
- Specifies the appearance and formatting of an HTML document
- No monolithic CSS specification but modules about concrete features which can evolve independently
- Browser-specific prefixes for features under development:
- Firefox: -moz-
- Internet Explorer: -ms-
- Opera: -o-
- Webkit (Chrome, Safari): -webkit-
4. Getting started with CSS
- Anatomy of a CSS style:
4. Getting started with CSS
- Applying a style (style attribute):
4. Getting started with CSS
- Applying a style (style element):
4. Getting started with CSS
-
Applying a style (external stylesheet):
- Style file loading order is important (the latest will be applied)
4. Getting started with CSS
-
Applying a style (browser styles or user agent styles):
- Default values applied by the browser
4. Getting started with CSS
- Applying a style (user styles):
- Proprietary mechanism by browser
- In Firefox:
- File in user's profile:
- \chrome\userContent.css
- File in user's profile:
- In Chrome: file in user's profile:
- \Default\User StyleSheets\Custom.css
- In Firefox:
- It will be applied to any site the user visits
- It overrides the default browser or user agent styles
- Proprietary mechanism by browser
4. Getting started with CSS
- Importing style files (@import):
- Not widely known
- Generally, worse performance in browsers than <link>
4. Getting started with CSS
-
Character encoding:
- Only information which can come before @import
- If not specified, the one in the HTML document applies
- If not specified in the HTML document, UTF-8 by default
4. Getting started with CSS
-
Styles cascading:
- Inline styles (author styles)
- Embed styles (author styles)
- External styles (author styles)
- User styles
- Browser styles
4. Getting started with CSS
-
Adjusting the default styles cascading:
- Prioritize important styles no matter where they have been defined
- Important user styles applied over author styles
4. Getting started with CSS
-
Tie breaking:
- More than 1 style defined at the same level that can be applied to the same element
-
Specificity breaks the tie break (a-b-c):
- Number of id values (a)
- Number of other attributes and pseudo-classes (b)
- Number of element names and pseudo-elements (c)
- If same specificity, then order of appearance (latest apply)
4. Getting started with CSS
-
Style inheritance:
- If no style for a property of an element, the parent element's property style applies
- This rule applies to appearance styles
- This rule does NOT apply to layout styles
- Can be forced with the inherit value
4. Getting started with CSS
- Colors:
- Name
- rgb(red, green, blue): Decimal values separated by ,
- #redgreenblue: Hexadecimal values starting with #
- http://www.w3.org/TR/css3-color/
4. Getting started with CSS
- Color functions:
4. Getting started with CSS
- Lengths:
- number_of_units+unit (no spaces in between)
- Absolute : in, cm, mm, pt (1/72 of an inch), pc (pica, 12 pt)
- Relative : em (font size of element), ex ('x-height' of element's font), rem (font size of root element), px (96dpi displays, 1/96 of an inch), % (another concrete property), and others ( gd, vw, vh, vm, ch) not widely supported
4. Getting started with CSS
-
Unit calculations:
- Mixing other units and perform basic arithmetic
4. Getting started with CSS
-
Angles:
- Useful when using transforms
- deg (0 - 360), grad (0 - 400), rad (0 - 6.28), turn (1 = 360deg)
4. Getting started with CSS
-
Time:
- Useful for transitions and animations
- s, ms
5. Getting started with Javascript
- A little bit of history:
- 1995: Brendan Eich: Mocha → LiveScript, for Netscape 2
-
1997:
- JavaScript 1.1 submitted to the ECMA (ECMA-262 → ECMAScript)
- JavaScript = ECMAScript (core) + Extensions (DOM, BOM, etc.)
- 1998: ISO standard: ISO/IEC 16262
- 1998 - 2008: Browsers war (version support, JScript, etc.)
- 2009 - ... : Programming language of the Web (stable support in browsers)
5. Getting started with Javascript
- Case sensitive
- Including scripts in an HTML document (inline script):
5. Getting started with Javascript
- Case sensitive
- Including scripts in an HTML document (external script):
5. Getting started with Javascript
- Strict mode:
- Introduced in ECMAScript 5
- Different parsing and execution model for JavaScript
- Erratic behavior of ECMAScript 3 is addressed
- Errors are thrown for unsafe activities
- Distinct set of reserved words (more restrictive)
5. Getting started with Javascript
- Variables and Types:
- Javascript is a loosely typed language:
- Assigning different types to the same variable
5. Getting started with Javascript
- Types:
- Primitive types: Boolean , Number , Null, String , Undefined
5. Getting started with Javascript
- Types:
- Primitive types: Boolean, Number, Null , String, Undefined
5. Getting started with Javascript
-
Objects:
- Object instantiation (new keyword)
- Adding properties
- Deleting properties
5. Getting started with Javascript
-
Objects:
- Object literal format
5. Getting started with Javascript
-
Objects:
- Built-in properties and methods (most common ones)
5. Getting started with Javascript
- in expression:
5. Getting started with Javascript
- Numbers:
5. Getting started with Javascript
-
Numbers:
- Number literals
5. Getting started with Javascript
-
Numbers:
- Built-in properties and methods (most common ones)
5. Getting started with Javascript
-
Strings:
- Strings are immutable in ECMAScript
5. Getting started with Javascript
-
Strings:
- String literals
5. Getting started with Javascript
-
Strings:
- Built-in properties and methods (most common ones)
5. Getting started with Javascript
- Dates:
5. Getting started with Javascript
- Regular expressions (RegExp):
5. Getting started with Javascript
- Arrays:
5. Getting started with Javascript
-
Arrays:
- Array literals
5. Getting started with Javascript
-
Arrays:
- Built-in properties and methods (most common ones)
5. Getting started with Javascript
-
Functions:
- Declaration and invocation
5. Getting started with Javascript
- Functions:
5. Getting started with Javascript
-
Functions:
- Closures
5. Getting started with Javascript
-
Math object:
- Global object just as Global (aka. window in browsers)
5. Getting started with Javascript
- typeof operator:
5. Getting started with Javascript
- Operators (most useful ones):
- Arithmetic operators
5. Getting started with Javascript
- Operators (most useful ones):
- Bitwise operators
5. Getting started with Javascript
- Operators (most useful ones):
- Assignment operators
5. Getting started with Javascript
- Operators (most useful ones):
- Comparison operators
- Primitives types are compared by value
- Objects are compared by reference
- Comparison operators
5. Getting started with Javascript
- Operators (most useful ones):
- Concatenation operator (precedence over the arithmetic one)
5. Getting started with Javascript
- Operators (most useful ones):
- Conditional operator (ternary)
5. Getting started with Javascript
- Operators (most useful ones):
- Logical operators
5. Getting started with Javascript
- Flow control:
- if statement
5. Getting started with Javascript
- Flow control:
- switch statement
5. Getting started with Javascript
- Loops:
- for loop
5. Getting started with Javascript
- Loops:
- for ... in
5. Getting started with Javascript
- Loops:
- do / while loop
5. Getting started with Javascript
- Loops:
- while loop
5. Getting started with Javascript
- Handling errors:
5. Getting started with Javascript
- Scopes:
- global scope
- function scope
- with statement
- catch block
- Garbage collection (mark-and-sweep)
5. Getting started with Javascript
- Timers:
5. Getting started with Javascript
- Object Oriented Programming (OOP):
5. Getting started with Javascript
- Custom Events:
6. HTML elements in-depth
- The most important change in HTML5 is a philosophical one:
- Semantics of elements vs. presentation
- Ex.: <b> no longer states text in bold (backwards compatibility, preferably avoid them using CSS)
"The b element represents a span of text to which attention is being drawn for utilitarian purposes without conveying any extra importance and with no implication of an alternate voice or mood, such as key words in a document abstract, product names in a review, actionable words in interactive text-driven software, or an article lede."
6. HTML elements in-depth
- Some preliminary recommendations:
- Add only the needed markup to give semantic significance to your content
- Avoid using private semantics (use generic elements instead: <div>, <span>) and/or classes
- Be as specific as possible (don't abuse of generic elements)
- It's not all about presentation (programatic access to HTML content, adapted presentation, etc.)
6. HTML elements in-depth
6. HTML elements in-depth
- Document and metadata elements:
- Creates the superstructure of the HTML document
- Provides information to the browser
6. HTML elements in-depth
- Metadata elements:
6. HTML elements in-depth
- Metadata elements:
6. HTML elements in-depth
- Metadata elements:
6. HTML elements in-depth
- Metadata elements:
6. HTML elements in-depth
- Metadata elements:
6. HTML elements in-depth
- Metadata elements:
6. HTML elements in-depth
6. HTML elements in-depth
- Section elements:
6. HTML elements in-depth
- Section elements:
- Basic headings
6. HTML elements in-depth
6. HTML elements in-depth
6. HTML elements in-depth
6. HTML elements in-depth
6. HTML elements in-depth
6. HTML elements in-depth
6. HTML elements in-depth
6. HTML elements in-depth
6. HTML elements in-depth
6. HTML elements in-depth
- Text-level elements:
- Hyperlinks
6. HTML elements in-depth
- Text-level elements:
- Importance
6. HTML elements in-depth
- Text-level elements:
- Break elements
6. HTML elements in-depth
- Text-level elements:
- Input and output elements
6. HTML elements in-depth
- Text-level elements:
- Abbreviations, citations, definitions and quotations
6. HTML elements in-depth
- Text-level elements:
- Language elements
6. HTML elements in-depth
- Text-level elements:
- Other elements
6. HTML elements in-depth
- Grouping elements:
- Browsers collapse whitespace characters in 1 space
- blockquote, div, hr, p, pre
6. HTML elements in-depth
- Grouping elements:
- Lists
6. HTML elements in-depth
- Grouping elements:
- Description lists
6. HTML elements in-depth
- Grouping elements:
- Figure
6. HTML elements in-depth
6. HTML elements in-depth
- Embedding content:
- HTML content: iframe
6. HTML elements in-depth
- Embedding content using plugins:
6. HTML elements in-depth
- Embedding content using plugins:
6. HTML elements in-depth
- Embedding media:
6. HTML elements in-depth
- Embedding media:
6. HTML elements in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
7. CSS styling in-depth
-
Media queries:
- Limits the style sheets scope by using media features, such as width, height, and color
- Separated by commas
- Composed of:
- Logical operators
- Media types
- Media expressions: feature and value
7. CSS styling in-depth
8. Javascript in-depth
- Javascript is much more than ECMA-262 (not tied to browsers)
- Extensions:
- Additional functionality more specific to the environment
-
Browser Object Model (BOM):
- API to interact with the browser
-
Document Object Model (DOM):
- API to interact with an HTML document
- Levels (versions of the specification)
- Distinct support by browsers
- Other DOMs: SVG, MathML, SMIL, Mozilla's XUL
8. Javascript in-depth
8. Javascript in-depth
8. Javascript in-depth
- document metadata properties:
8. Javascript in-depth
- document location properties:
8. Javascript in-depth
- Accessing HTML elements via document's properties:
8. Javascript in-depth
- Searching for HTML elements:
8. Javascript in-depth
- Navigating the DOM:
8. Javascript in-depth
- Getting information about the window:
8. Javascript in-depth
- Interacting with the window:
8. Javascript in-depth
- Prompting the user:
8. Javascript in-depth
- Browser history:
8. Javascript in-depth
- Using timers:
8. Javascript in-depth
- Accessing windows:
8. Javascript in-depth
- Cross-document messaging (sender):
8. Javascript in-depth
- Cross-document messaging (listener):
8. Javascript in-depth
- Working with DOM elements:
- Element data properties:
8. Javascript in-depth
- Working with DOM elements:
- Working with classes:
8. Javascript in-depth
- Working with DOM elements:
- Element attribute properties:
8. Javascript in-depth
- Working with Text elements:
8. Javascript in-depth
- Modifying the model:
- Basic functions and properties:
8. Javascript in-depth
- Working with events:
- An event is a change in the state of something
- Element event flow:
- Capture:
- Checks if elements between the <body> and the target have event listeners to be notified of events of their descendants. Disabled by default
- Target:
- Checks the target added events listeners
- Bubbling:
- Checks the ascendants added events listeners
- Capture:
8. Javascript in-depth
- Working with events:
-
Inline event handler:
-
Inline event handler:
8. Javascript in-depth
- Working with events:
- Using the DOM and the Event object:
8. Javascript in-depth
- Working with events:
- document and window events:
8. Javascript in-depth
- Working with events:
- Mouse events:
8. Javascript in-depth
- Working with events:
- Focus related events:
8. Javascript in-depth
- Working with events:
- Keyboard events:
8. Javascript in-depth
- Working with events:
- form events:
8. Javascript in-depth
- Using element specific objects:
- base element (HTMLBaseElement):
8. Javascript in-depth
- Using element specific objects:
- body element (HTMLBodyElement):
8. Javascript in-depth
- Using element specific objects:
- link element (HTMLLinkElement):
8. Javascript in-depth
- Using element specific objects:
- meta element (HTMLMetaElement):
9. HTML5 APIs
- HTML5 APIs extend the capabilities of the browsers and consequently of the web applications built upon:
- Nowadays, it is possible to build native-like web applications which run in browsers
- There are even web-oriented operating systems:
- Web OS: https://www.openwebosproject.org/
- Chromium OS: http://www.chromium.org/chromium-os
- EyeOS: http://www.eyeos.com/
- Firefox OS: http://www.mozilla.org/en-US/firefox/os/
- Tizen: https://www.tizen.org/
9. HTML5 APIs
- Let's back up a little bit...
- AJAX:
- Asynchronous JavaScript and XML (getting data)
9. HTML5 APIs
- Let's back up a little bit...
- AJAX:
- Asynchronous JavaScript and XML (sending data)
9. HTML5 APIs
- Let's back up a little bit...
- AJAX:
- Asynchronous JavaScript and XML (sending files)
9. HTML5 APIs
- AJAX:
- Exercise: HTML5Rocks tutorials widget
9. HTML5 APIs
- Working with multimedia (audio and video):
- Getting info
9. HTML5 APIs
- Working with multimedia (audio and video):
- Controlling the media playback:
9. HTML5 APIs
- Using the canvas:
- The so-called "Adobe Flash killer"
9. HTML5 APIs
- Using the canvas:
- Drawing "images":
9. HTML5 APIs
- Using the canvas:
- Drawing using paths:
9. HTML5 APIs
- Using the canvas:
- Clipping regions:
9. HTML5 APIs
- Using the canvas:
- Drawing text:
9. HTML5 APIs
- Using the canvas:
- Using shadows and transparency:
9. HTML5 APIs
- Using the canvas:
- Using transformations:
9. HTML5 APIs
- Using the canvas:
- Exercise: Drawing area
9. HTML5 APIs
- Drag and drop:
- The basics
9. HTML5 APIs
- Drag and drop:
- Exercise: Shopping cart
9. HTML5 APIs
- Drag and drop:
- Exercise: Shopping cart (using DataTransfer)
9. HTML5 APIs
- Geolocation:
- Not part of the HTML5 specification
9. HTML5 APIs
- Geolocation:
- Google Maps example
9. HTML5 APIs
- Web storage:
- localStorage
9. HTML5 APIs
- Web storage:
- sessionStorage
9. HTML5 APIs
- Web storage:
- Exercise: Saving drafts
9. HTML5 APIs
- IndexedDB:
- Basic concepts:
- IndexedDB databases store key-value pairs:
- Values can be complex structured objects
- Transactional database model (auto-commit)
- Mostly asynchronous (synchronous version not very supported)
- Same origin policy
- IndexedDB databases store key-value pairs:
- Basic concepts:
9. HTML5 APIs
- Open a database and start a transaction
- Create an object store
- Make a request to do some database operation, like adding or retrieving data
- Wait for the operation to complete by listening to the right kind of DOM event
- Do something with the results (which can be found on the request object)
9. HTML5 APIs
- IndexedDB:
- General usage
9. HTML5 APIs
- IndexedDB:
- Exercise: To-Do app
9. HTML5 APIs
- WebSockets:
- Socket-oriented connections between the web browser and a server
- Single TCP connection:
- Not HTTP (avoiding HTTP overhead)
- Low latency
- Real-time communications
- Persistent connections
- Both parties can start sending data at any time (bidirectional)
9. HTML5 APIs
- WebSockets:
- Basic usage
9. HTML5 APIs
- Web Workers:
- Running scripts in background threads
- Once created, a worker can send messages to the spawning task by posting messages to an event handler specified by the creator
- They work within a global context different from the current window (using the window shortcut instead of self in order to get the current global scope within a worker will return, in fact, an error)
9. HTML5 APIs
- Web Workers:
- Basic usage
9. HTML5 APIs
- Web Workers:
- Exercise: Calculate prime numbers when animating
HTML5 Course
By Germán Toro del Valle
HTML5 Course
A course about HTML5 and all the technologies it encompasses.
- 10,838