SlideShare a Scribd company logo
HTML5
Data Attributes

     Lennart Schoors
The problem
. improper/impractical/invalid use of
 HTML attributes
  . rel="ajax" or rel="dialog"
  . class="ignore-proxy"
  . custom attributes with custom DTD
The solution: data-* attributes
  . “Custom data attributes are intended to
      store custom data private to the page or
      application, for which there are no more
      appropriate attributes or elements”
  . at least one character after the hyphen
  <span data-age="29">lensco</span>
  <a href="/foo" data-target="dialog">bar</a>



http://dev.w3.org/html5/spec/elements.html#embedding-custom-non-visible-data-with-the-data-attributes
. private in the sense that the end user
 can't see it - it doesn't affect layout or
 presentation
. intended for use by the site's own scripts,
 not a generic extension mechanism for
 publicly-usable metadata
Support?
. any browser that supports HTML5
 doctypes (= all browsers we support)
. JavaScript API
JavaScript API
. dataset property
. very similar to the the attributes property
. but: not implemented yet, so ...
. use getAttribute & setAttribute
<span data-city="Gent">lensco</span>




var user = document.getElementsByTagName("span")[0];

user.dataset["city"]; // not supported yet!
user.getAttribute("data-city"); // fallback
jQuery
. As of jQuery 1.4.3 HTML5 data-* attributes
  will be automatically pulled in to
  jQuery's data object

user.data("city");
Examples
. store parameters for a Flash movie that’s
 loaded via JavaScript
. store the initial height or opacity of an
 element which might be required in later
 JavaScript animation calculations
. tracking traffic

          http://html5doctor.com/html5-custom-data-attributes
   http://jasonkarns.com/blog/2010/03/10/google-analytics-tagging
Example: lazy image loading
. Flickr: data-defer-src
. "any image that doesn’t need to be loaded
  straight away, including avatars and map
  tiles"
. but: "It’s worth noting that on Flickr we’ve
  disabled this type of image deferral for
  IE6, 7 and 8."

       http://24ways.org/2010/speed-up-your-site-with-delayed-content
 http://24ways.org/2010/speed-up-your-site-with-delayed-content#c007948
When not to use it
. not intended to compete with
  microformats (public data)
. not if there is an existing attribute or
  element which is more appropriate
. don't use as a CSS hook for styling
That’s all folks!
Questions?




Read on at http://lensco.be

More Related Content

PDF
Component-based Front-End architecture
PPTX
Nasdanika HTML - Fluent Java API for building Web UI
PDF
Web Programming - 10 JavaScript
PDF
Life of html5 (osaka)
PPTX
Microsoft Graph community call-December 2018
PDF
Angular.js - An introduction for the unitiated
PPTX
GDMS Application Platform (1)
DOCX
Online job support Qlikview Online Training
Component-based Front-End architecture
Nasdanika HTML - Fluent Java API for building Web UI
Web Programming - 10 JavaScript
Life of html5 (osaka)
Microsoft Graph community call-December 2018
Angular.js - An introduction for the unitiated
GDMS Application Platform (1)
Online job support Qlikview Online Training

What's hot (9)

PDF
Fast mobile web apps
PPTX
Data Binding - Android by Harin Trivedi
PPTX
Trivento Summercamp : Reactive with AngularJS & TypeSafe
PPT
01 Ajax Intro
PDF
Data Collection and Consumption
ODP
JS libraries and frameworks - Quick Tips on Coffee@DBG
PDF
Web Programming - 8 Database, Model and Eloquent
PPTX
Opening up: bibliographic data sharing & interoperability
PDF
Web Programming - 9 Create, Read, Update and Delete
Fast mobile web apps
Data Binding - Android by Harin Trivedi
Trivento Summercamp : Reactive with AngularJS & TypeSafe
01 Ajax Intro
Data Collection and Consumption
JS libraries and frameworks - Quick Tips on Coffee@DBG
Web Programming - 8 Database, Model and Eloquent
Opening up: bibliographic data sharing & interoperability
Web Programming - 9 Create, Read, Update and Delete
Ad

Similar to HTML5 data attributes (20)

PPTX
PPTX
Single page applications mit asp.net mvc und der asp.net web api
ODP
Html5
PPTX
Harness jQuery Templates and Data Link
PDF
Web components are the future of the web - Take advantage of new web technolo...
ODP
IBM Connections Activity Stream 3rd Party Integration - Social Connect VI - P...
PDF
PPTX
Creating Great Applications in SharePoint 2010 with Silverlight 4
PDF
Web Apps and more
PDF
Web app and more
PDF
HTML5 Refresher
DOCX
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
PDF
Web Components mit Polymer und AngularJS 1.x
PDF
Web Components mit Polymer und AngularJS 1.x
PDF
Web Components v1
PDF
Speak the Web 15.02.2010
PPTX
Html5 on Mobile(For Developer)
PDF
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
PPTX
JavaScript Basics
PDF
HTML5 & CSS3 refresher for mobile apps
Single page applications mit asp.net mvc und der asp.net web api
Html5
Harness jQuery Templates and Data Link
Web components are the future of the web - Take advantage of new web technolo...
IBM Connections Activity Stream 3rd Party Integration - Social Connect VI - P...
Creating Great Applications in SharePoint 2010 with Silverlight 4
Web Apps and more
Web app and more
HTML5 Refresher
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
Web Components mit Polymer und AngularJS 1.x
Web Components mit Polymer und AngularJS 1.x
Web Components v1
Speak the Web 15.02.2010
Html5 on Mobile(For Developer)
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
JavaScript Basics
HTML5 & CSS3 refresher for mobile apps
Ad

More from Lennart Schoors (6)

PDF
Data, taste & confidence
PDF
Look ma! No images!
PDF
Web design for right-to-left languages
PDF
Managing CSS for a big ass website - at Netlog
PDF
To Hell with Web Safe Fonts
PDF
Html 5 in a big nutshell
Data, taste & confidence
Look ma! No images!
Web design for right-to-left languages
Managing CSS for a big ass website - at Netlog
To Hell with Web Safe Fonts
Html 5 in a big nutshell

Recently uploaded (20)

PDF
project resource management chapter-09.pdf
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Tartificialntelligence_presentation.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
A Presentation on Touch Screen Technology
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Mushroom cultivation and it's methods.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
August Patch Tuesday
project resource management chapter-09.pdf
A novel scalable deep ensemble learning framework for big data classification...
Zenith AI: Advanced Artificial Intelligence
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Tartificialntelligence_presentation.pptx
Approach and Philosophy of On baking technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
WOOl fibre morphology and structure.pdf for textiles
Chapter 5: Probability Theory and Statistics
A Presentation on Touch Screen Technology
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Assigned Numbers - 2025 - Bluetooth® Document
A comparative analysis of optical character recognition models for extracting...
Mushroom cultivation and it's methods.pdf
A comparative study of natural language inference in Swahili using monolingua...
Heart disease approach using modified random forest and particle swarm optimi...
August Patch Tuesday

HTML5 data attributes

  • 1. HTML5 Data Attributes Lennart Schoors
  • 2. The problem . improper/impractical/invalid use of HTML attributes . rel="ajax" or rel="dialog" . class="ignore-proxy" . custom attributes with custom DTD
  • 3. The solution: data-* attributes . “Custom data attributes are intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements” . at least one character after the hyphen <span data-age="29">lensco</span> <a href="/foo" data-target="dialog">bar</a> http://dev.w3.org/html5/spec/elements.html#embedding-custom-non-visible-data-with-the-data-attributes
  • 4. . private in the sense that the end user can't see it - it doesn't affect layout or presentation . intended for use by the site's own scripts, not a generic extension mechanism for publicly-usable metadata
  • 5. Support? . any browser that supports HTML5 doctypes (= all browsers we support) . JavaScript API
  • 6. JavaScript API . dataset property . very similar to the the attributes property . but: not implemented yet, so ... . use getAttribute & setAttribute
  • 7. <span data-city="Gent">lensco</span> var user = document.getElementsByTagName("span")[0]; user.dataset["city"]; // not supported yet! user.getAttribute("data-city"); // fallback
  • 8. jQuery . As of jQuery 1.4.3 HTML5 data-* attributes will be automatically pulled in to jQuery's data object user.data("city");
  • 9. Examples . store parameters for a Flash movie that’s loaded via JavaScript . store the initial height or opacity of an element which might be required in later JavaScript animation calculations . tracking traffic http://html5doctor.com/html5-custom-data-attributes http://jasonkarns.com/blog/2010/03/10/google-analytics-tagging
  • 10. Example: lazy image loading . Flickr: data-defer-src . "any image that doesn’t need to be loaded straight away, including avatars and map tiles" . but: "It’s worth noting that on Flickr we’ve disabled this type of image deferral for IE6, 7 and 8." http://24ways.org/2010/speed-up-your-site-with-delayed-content http://24ways.org/2010/speed-up-your-site-with-delayed-content#c007948
  • 11. When not to use it . not intended to compete with microformats (public data) . not if there is an existing attribute or element which is more appropriate . don't use as a CSS hook for styling
  • 12. That’s all folks! Questions? Read on at http://lensco.be