Home / Technology / What’s New In HTML 5.1 — 14 Added Features and How To Use Them

What’s New In HTML 5.1 — 14 Added Features and How To Use Them

HTML5 is owned by the World Wide Web Consortium (W3C), which provides standards across the web so that the protocols from all over the world are inter accessible. In November 2016, W3C updated the long running HTML 5, which is the first minor update in 2 years. Many initial HTML 5.1 features were dropped due to faulty design and lack of browser vendor support.

Although, there are few elements and improvements brought over to HTML 5.1, it is still a minor update. Some of the new elements contain combo tags, which now include <dialog>, <details>, <summary> and <picture>, providing developers even more room for expression.

W3C has already started working on a draft of HTML 5.2 which is expected to be released near the end of 2017. In the meantime, we are presenting some interesting new features and improvements introduced in version 5.1. You can make use of these features without touching JavaScript. Not all browsers support these features, so it’s better you check browser support before you use them in production. 

14. Prevent Phishing Attack

Most of the people using target=’_blank’ have no idea about a curious fact – the newly opened tab can alter the window.opener.location to some phishing page. It will execute some malicious JavaScript code on the opener-page on your behalf. Because users trust the page that is already opened, they won’t get suspicious.

In order to completely eliminate this issue, HTML 5.1 has standardized the usage of the rel=”noopener” attribute which separates browser contexts. The rel=”noopener” can be used within <a> and <area> tags.

Read: 24 CSS3 and HTML5 Animation Tools for Designers

 

13. Handle Figure Caption Flexibly

The <figcaption> tag represents a caption or legend associated with <figure> element, which act as a container for visuals like pictures, diagrams, illustration etc.  In early HTML versions, <figcaption> could be used only as the first or last child tag of the <figure> element.
HTML5.1 has loosened this restriction, and now you can use <figcaption> anywhere within its <figure> container.

 

12. Spell Checking

The spellcheck is an enumerated attribute whose keywords are the empty string, true and false. The true state indicates that the element is to have its spelling and grammar checked.
The element.forceSpellCheck() forces the user agent to report spelling and grammar error on the text element, even if the user have never focused the element.

11. The Empty Option

The new version of HTML allows you to create an empty <option> element. It can be a child element of <optgroup>, <datalist> or <select> elements. You will find this feature helpful while designing user-friendly form.

 

10. Allow Full Screen for Frames

The boolean allowfullscreen attribute, developed for frames, lets you control whether the content can present itself on full screen by using requestFullscreen() method. For example, lets take an iframe that embeds a player from YouTube. The allowfullscreen attribute is required to enable the player to show its video fullscreen.

 

9. Nested Header and Footer

HTML 5.1 allows you to nest header and footer within another header. You can add a header or footer to the header element if they are themselves contained within sectioning content.
The feature can be pretty useful if you want to add elaborated headers to semantic sectioning elements, like <section> and <article>.

In the code given below, the <article> contains a <header> which has an <aside> tag which itself contains a <header> tag.

 

8. Zero Width Images

The new HTML version allows you to add image of zero size. This feature is used when image is not intended for user. If an img element is being used for purposes other than displaying an image, example, as part of a service to count number of page views, use width and height attribute with 0 value. For zero width images, it is recommended to use empty attributes.

 

7. Validating Form

The new reportValidity() method allows you to validate a form and retrieve the results, and reports the errors to the users right in the browser. User agents may report more than one constraint violation, if the element suffers from multiple problems at the same time. As in this case, the “password” input should be marked with error since it is mandatory but empty.

 

6. The Browser’s Context Menu

In HTML 5.1, you can use the <menu> tag to define menu consisting of one or more than one <menuitem> elements, and then bind it to any element using the contextmenu attribute. The id of the <menu> element should have the same value as the contextmenu attribute of the element to which we want to add the context menu to.

Each <menuitem> can have one of the three forms:

  • radio – Select option from a group
  • checkbox – Select or deselect an option
  • command – Execute an action on click
 

5. Use Cryptographic Nonces with scripts and styles

A cryptographic nonce is a randomly  generated number which can be used only one, and it has to be regenerated for every page request. This nonce attribute can be used within the <script> and the <style> elements.

It is generally used by the Content Security Policy of a website to decide if a certain style or script should be implemented on the page. In the given code, the value is hard-coded, but in real world scenario, its value is generated randomly.

 

4. Reverse Link Relationship

The rev attribute was defined in HTML 4, however it wasn’t included in HTML5. The W3C decided to include rev attribute again for the <a> and <link> elements. The rev attribute specifies the relationship of the current and the linked document in the reverse direction. It has been included to support widely used structured data markup format, RDFa.

Let’s take an example of two documents, each containing a lesson, the link between them can be defined with rel and rev attributes as shown…

 

3. Show/Hide Information

The new <details> and <summary> elements allows you to add extended information to a piece of content. You can show or hide a block of additional information by clicking on the element. The additional information is hidden by default.

In your code, you are supposed to put the <summary> tag inside <details> tag as shown. After <summary> tag you can add the rest of the content that you want to hide.

 

2. More Input Types

The HTML input elements has been extended with three more input types – week, month and datetime-local.
As the name suggests, the first two allows the users to select a week or a month. Depending on the browser support, both of them are rendered as a dropdown calendar that lets you select either a particular week or month of a year.

The datatime-local specifies a date and time input field, with no time zone. The data can be selected in a similar way to the month or week input, and the time can be typed in separately.

 

1. Responsive Images

W3C has introduced some new features for implementing responsive images without the use of CSS. These are…

The srcset Image Attribute

The srcset attribute allows you to define multiple alternative image sources which vary in pixel density. It will allow the browser to select an image of suitable quality according to user’s device. For example, it would be nice to display a lower resolution image for users with mobile devices on slower network.

You can use srcset attribute with its own x modifier that describes the pixel ratio for each image. As the example shown, if the user’s pixel is equal to 3, high-res image will be displayed.

Instead of different pixel ratio, you can select to display images of different size using the w modifier. In this case high-res image is defined to be 1600px.

The sizes Image Attribute

Most of the time authors like to display different images for different screen size. This can be done using sizes attribute. It lets you transform the width of the screen into space assigned for an image, and then pick the suitable image using the scrset attribute. For example…

In this case, the sizes attribute defines the width of the image as 100% of the width of the viewport when the width of the viewport is greater than 25em, or 60% of the width when it’s lower or equal to 25em.

The picture Element

The picture element allows you to declare images with several sources for different screen size. This is can be done by wrapping <img> with <picture> element and describing multiple child <source> elements.

Read: 35+ Useful HTML and CSS Frameworks For Web Designers

The <picture> tag alone won’t display anything. You are supposed to declare the default image source as the value of src attribute, and the alternative image source go within scrset attribute as shown…