10 New Features of HTML 5.1 & How to Use Them IRL
The HTML specification got a major overhaul a couple of weeks ago when W3C published its new HTML 5.1 recommendation in November 2016. In its recent blog post, W3C called the new major release the gold standard, as HTML 5.1 provide us with new ways of how we can use HTML to create more flexible web experiences.
In this article, we’re going to have a look at its new features you can make use of without touching JavaScript, however the improvements of the JavaScript background are also remarkable, as you can see it in the official change log.
Note that currently not all browsers support all of these features, so don’t forget to check browser support before you use them in production. If you are interested in the further development of the HTML standard, you can check out the working draft of HTML 5.2 as well.
1. Define multiple image resources for responsive design
In HTML 5.1, you can use<picture>
tag together with the srcset
attribute to make responsive image selection possible. The <picture>
tag represents an image container that allows developers to declare different image resourcesin order to adapt to the UA‘s viewport size, screen pixel density, screen type, and other parameters used in responsive design.The
<picture>
tag itself doesn’t display anything, it functions merely as context for the multiple image resources. You need to declare the default image resource as the value of the src
attribute of the <img>
tag, and the alternative image resources go within the srcset
attributes of the <img>
and <source>
elements.Code example:
<
picture
>
<
source
srcset
=
"mobile.jpg, mobile-hd.jpg 2x"
media
=
"(max-width: 360px)"
>
<
source
srcset
=
"large.jpg, large-hd.jpg 2x"
media
=
"(min-width: 1920px)"
>
<
img
src
=
"default.jpg"
srcset
=
"default-hd.jpg 2x"
alt
=
"your image"
>
</
picture
>
2. Show or hide extra information
With the<details>
and <summary>
tags, you can add extended information to a content piece. The extra information isn’t shown by default, but if users are interested, they have the option to take a look. In your code, you are supposed to place the <summary>
tag inside <details>
. After the <summary>
tag you can add the extra information you want to hide.Code example:
0Code ee
|
< section > < h2 >Error Message</ h2 > < details > < summary >We couldn't finish downloading this video.</ summary > < dl > < dt >File name:</ dt >< dd >yourfile.mp4</ dd > < dt >File size:</ dt >< dd >100 MB</ dd > < dt >Duration:</ dt >< dd >00:05:27</ dd > </ dl > </ details > </ section ></ section >
3. Add functionality to the browser’s context menu
With the
<menuitem> element and its type="context" attribute, you can add custom functionality to the context menu of the browser. You need to assign <menuitem> as the child element of the <menu> tag. The id of the <menu> element needs to carry the same value as the contextmenu attribute of the element to which we want to add the context menu to (which is the <button> element in the example below).Code example: < button contextmenu = "rightclickmenu" >Right click me</ button > < menu type = "context" id = "rightclickmenu" > < menuitem type = "checkbox" label = "I ♥ HTML5.1." > </ menu >
The
<menuitem> tag can have three different types, "checkbox" , "command" (to which you need to add an action with JavaScript), and radio . It’s possible to add more than one menu item to a context menu, however the browser support for this feature is not very good yet.
Chrome 54 doesn’t support it, and Firefox 50 only allows the presence
of one extra context menu. Below you can see how the code example works
in Firefox 50.4. Nest headers and footersHTML 5.1 allows you to nest headers and footers if each level is contained within sectioning content. The note below is a screenshot from the W3C docs, and advises developers about the right way of header and footer nesting.
This feature can be useful if you want to add elaborated headers to semantic sectioning elements, such as
|
1 comments:
Click here for commentsvery nice wepside kashifmalikzone
ConversionConversion EmoticonEmoticon