Table of Contents
Context menu uses menu and menuitems elements
Details and Summary elements
More input types - month, week and datetime-local
Responsive images
Use form.reportValidity() to validate the form
Allowfullscreen property of frames Allowfullscreen property of frames
Use element.forceSpellCheck() for spell checking
Features not included in HTML 5.1
 Supplement
Home Web Front-end H5 Tutorial What are the new features in HTML5.1?

What are the new features in HTML5.1?

May 31, 2017 pm 03:47 PM

 HTML 5.1Overview

The release of the HTML5 standard two years ago was a big event for the web development community . Not only because it contains an impressive series of new features, but also because it is the first major version update to HTML since the HTML 4.01 standard was released in 1999. You can still see some websites boasting that they use the "modern" HTML5 standard.

Fortunately we don’t have to wait that long for the next update to the HTML standard. In October 2015, W3C began working on the HTML5.1 draft, with the goal of fixing some of the remaining problems of HTML5. After multiple iterations, the draft reached the "Candidate Recommendation" stage in June 2016, the "Proposed Recommendation" stage in September 2016, and finally the W3C recommendation was released in November 2016. Those paying attention to the new standard may have noticed that it has been a winding road. Many HTML5.1 features that were initially proposed were abandoned due to poor design or lack of browser vendor support.

Although HTML5.1 is still in development, the W3C has begun working on the HTML5.2 draft, which is expected to be released in late 2017. This article is an overview of some interesting new features and improvements in HTML5.1. Browser support for these features is still lacking, but at least we'll show you a few browsers that support these features to test each example against.

Context menu uses menu and menuitems elements

The HTML5.1 draft introduces two different menu elements: context and toolbar. The former is used to extend the local context menu, usually activated by right-clicking the mouse on the page; the latter is used to define a common menu component. During the development process, the toolbar was abandoned, but the context menu survived.

You can use the

tag to define a menu containing one or several elements, and then bind it to any element using the contextmenu attribute.

Each can be one of the following three types:

  • checkbox – allows to select or deselect an option;

  • command – Allows an action to be performed on a mouse click;

  • radio – Allows one to be selected from a set of options.

Here is a basic usage example, which can be run in Firefox49, but it is not currently available in Chrome54.

See the SitePoint (@SitePoint) HTML5.1 menu example on CodePen.

On a supported browser, this example context menu should look like this:

A HTML 5.1 context menu

There are custom items in the context menu.

Details and Summary elements

The new

and elements can display and hide additional information through mouse clicks. This is what is often done when using JavaScript, and now you can use the
element and the element to do it for you. Clicking on the element can show and hide the rest of the details element.

The following example can be tested in Firefox and Chrome.

Please see the SitePoint (@SitePoint) HTML5.1 demo on CodePen for details and summary.

This demo should look like this on supported browsers:

Details and summary elements

More input types - month, week and datetime-local

 Input extends three types: month, week and datetime-local.

The first two types allow you to choose weeks or months. In Chrome, both are rendered as drop-down calendars, and you can select a certain week or month. When you get their values ​​using JavaScript, you will get a string roughly like this: "2016-W43" (week input); "2016-10" (month input).

Initially, the HTML5.1 draft introduced two date type inputs — datetime and datetime-local. The difference is that datetime-local uses the user's time zone, while datetime allows you to choose the time zone. During development, datetime was abandoned and now only datetime-local exists. The datetime-local input consists of two parts - the date, which can be selected like week and month; and the time, which can be entered separately.

The following is an example of all new types of input. It can be displayed normally in chrome, but not in firfox.

See SitePoint (@SitePoint) HTML 5.1 week, month and datetime inputs on CodePen.

This demo should look like this on supported browsers:

Week, month and datetime-local inputs

Responsive images

HTML5.1 includes several new features that enable responsive images without using CSS. Each feature has its own separate usage scenario.

  srcset attribute

The srcset image attribute allows listing of multiple alternative image data sources with different pixel densities. This allows the browser to select an image of appropriate quality for the user's device (determined by the device's pixel density, scaling, or network speed). For example, in the case of low-speed mobile networks and small-screen phones, users should be provided with low-resolution images.

The srcset attribute accepts a comma-separated list of URLs, each with a modified x that represents the closest pixel ratio (the number of physical pixels represented by one CSS pixel) to the requested image. Here is a simple example:

<img src="images/low-res.jpg" srcset="
  images/low-res.jpg 1x, 
  images/high-res.jpg 2x, 
  images/ultra-high-res.jpg 3x"
>
Copy after login

In this example, if the pixel ratio of the user device is 1, the image low-res will be displayed; if it is 2, the image high-res will be displayed; If it is 3 or greater, the image ultra-high-res will be displayed.

Alternatively, you can choose to display the image in different sizes. This requires using w:

<img src="images/low-res.jpg" srcset="
  images/low-res.jpg 600w, 
  images/high-res.jpg 1000w, 
  images/ultra-high-res.jpg 1400w"
>
Copy after login

In this example, the image low-res is defined to be 600px wide, the image high-res is defined to be 1000px wide, and the ultra-high-res is 1400px wide.

 sizes attribute

You may want to display images in different ways depending on the user's screen size. For example, you might want to display an image in two columns on a wide screen and one column on a narrower screen. This can be achieved using the sizes attribute. It allows you to assign the width of the screen to an image and then select the appropriate image via the srcset attribute. The following is an example:

<img src="images/low-res.jpg" sizes="(max-width: 40em) 100vw, 50vw" 
  srcset="images/low-res.jpg 600w, 
  images/high-res.jpg 1000w, 
  images/ultra-high-res.jpg 1400w"
>
Copy after login

When the viewport width is greater than 40em, the sizes attribute defines the width of the image as 50% of the viewport width; when the viewport (viewport) width is less than or When equal to 40em, the image width is defined as 100% of the viewport width.

 picture element

If changing the size of the picture according to different screens still cannot meet the needs, and you want to display different pictures according to different screens, you need to use the picture element. It allows you to define pictures with different resources for different screen sizes by specifying multiple different elements with . The element serves as the source of the image loaded by the URL.

<picture>
  <source media="(max-width: 20em)" srcset="
    images/small/low-res.jpg 1x,
    images/small/high-res.jpg 2x, 
    images/small/ultra-high-res.jpg 3x
  ">
  <source media="(max-width: 40em)" srcset="
    images/large/low-res.jpg 1x,
    images/large/high-res.jpg 2x, 
    images/large/ultra-high-res.jpg 3x
  ">

  <img src="images/large/low-res.jpg">
</picture>
Copy after login

If you want to know more about responsive images, please click How to Build Responsive Images with srcset.

Use form.reportValidity() to validate the form

The form.checkValidity() method defined in HTML5 can check whether the form conforms to a predefined validator and return a Boolean value. The new reportValidity() method is similar — it also validates a form and returns the results, but it can also report errors to the user. Here is an example (please test in Firefox or Chrome):

Please see the SitePoint (@SitePoint) example HTML 5.1 report validity demo on CodePen.

 The "First name" input box is required to be non-empty, if not filled in it will be marked with an error. If it works as expected, it will look like this:

Working form validation with a message

Allowfullscreen property of frames Allowfullscreen property of frames

The new boolean property allowfullscreen of frames can control whether content can be accessed via requestFullscreen( ) method to display content in full screen.

Use element.forceSpellCheck() for spell checking

The new element.forceSpellCheck() method allows you to trigger spell checking on text elements. This is also the first feature listed in this article that is not yet supported by any browser. Perhaps, this could be used to inspect elements that have not been directly edited by the user.

Features not included in HTML 5.1

Some features were defined in the first draft but were ultimately removed, mostly due to lack of interest from browser vendors. Here are some of the interesting methods:

  inert attribute

The inert attribute can disable user interaction for all child elements, just like adding the disabled attribute to all child elements .

Dialog element

The

element provides a native popup box, and it even has a convenient collection of forms - use the method attribute on the You can prevent the form from being submitted to the server and instead close the popup and return the results to the popup's creator.

This feature seems to be still supported in firfox, so you can take a look at the following example (Translator's Note: firfox V49.0.2 does not support:

Please take a look at the example of SitePoint (@SitePoint) in CodePen HTML dialog element.

 Supplement

This is not an article about all the new features of HTML5.1. There are many small new features and changes that have been removed from the current standard, and some features that were never used have also been removed.

【Related recommendations】

1. HTML5 mobile application development-detailed introduction to the role of viewport (pictures and texts)

2. 20 Understand html5 in minutes and see what new features H5 has.

3. H5 learning journey-H5’s new features (1)

The above is the detailed content of What are the new features in HTML5.1?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Introduction to the differences between win7 home version and win7 ultimate version Introduction to the differences between win7 home version and win7 ultimate version Jul 12, 2023 pm 08:41 PM

Everyone knows that there are many versions of win7 system, such as win7 ultimate version, win7 professional version, win7 home version, etc. Many users are entangled between the home version and the ultimate version, and don’t know which version to choose, so today I will Let me tell you about the differences between Win7 Family Meal and Win7 Ultimate. Let’s take a look. 1. Experience Different Home Basic Edition makes your daily operations faster and simpler, and allows you to access your most frequently used programs and documents faster and more conveniently. Home Premium gives you the best entertainment experience, making it easy to enjoy and share your favorite TV shows, photos, videos, and music. The Ultimate Edition integrates all the functions of each edition and has all the entertainment functions and professional features of Windows 7 Home Premium.

Master the key concepts of Spring MVC: Understand these important features Master the key concepts of Spring MVC: Understand these important features Dec 29, 2023 am 09:14 AM

Understand the key features of SpringMVC: To master these important concepts, specific code examples are required. SpringMVC is a Java-based web application development framework that helps developers build flexible and scalable structures through the Model-View-Controller (MVC) architectural pattern. web application. Understanding and mastering the key features of SpringMVC will enable us to develop and manage our web applications more efficiently. This article will introduce some important concepts of SpringMVC

What are the three characteristics of 5g What are the three characteristics of 5g Dec 09, 2020 am 10:55 AM

The three characteristics of 5g are: 1. High speed; in practical applications, the speed of 5G network is more than 10 times that of 4G network. 2. Low latency; the latency of 5G network is about tens of milliseconds, which is faster than human reaction speed. 3. Broad connection; the emergence of 5G network, combined with other technologies, will create a new scene of the Internet of Everything.

Choose the applicable Go version, based on needs and features Choose the applicable Go version, based on needs and features Jan 20, 2024 am 09:28 AM

With the rapid development of the Internet, programming languages ​​are constantly evolving and updating. Among them, Go language, as an open source programming language, has attracted much attention in recent years. The Go language is designed to be simple, efficient, safe, and easy to develop and deploy. It has the characteristics of high concurrency, fast compilation and memory safety, making it widely used in fields such as web development, cloud computing and big data. However, there are currently different versions of the Go language available. When choosing a suitable Go language version, we need to consider both requirements and features. head

Are there any class-like object-oriented features in Golang? Are there any class-like object-oriented features in Golang? Mar 19, 2024 pm 02:51 PM

There is no concept of a class in the traditional sense in Golang (Go language), but it provides a data type called a structure, through which object-oriented features similar to classes can be achieved. In this article, we'll explain how to use structures to implement object-oriented features and provide concrete code examples. Definition and use of structures First, let's take a look at the definition and use of structures. In Golang, structures can be defined through the type keyword and then used where needed. Structures can contain attributes

C++ function types and characteristics C++ function types and characteristics Apr 11, 2024 pm 03:30 PM

C++ functions have the following types: simple functions, const functions, static functions, and virtual functions; features include: inline functions, default parameters, reference returns, and overloaded functions. For example, the calculateArea function uses π to calculate the area of ​​a circle of a given radius and returns it as output.

What are the characteristics of java What are the characteristics of java Aug 09, 2023 pm 03:05 PM

The characteristics of Java are: 1. Simple and easy to learn; 2. Object-oriented, making the code more reusable and maintainable; 3. Platform-independent, able to run on different operating systems; 4. Memory management, through automatic garbage collection mechanism Manage memory; 5. Strong type checking, variables must declare their type before use; 6. Security, which can prevent unauthorized access and execution of malicious code; 7. Multi-threading support, which can improve the performance and responsiveness of the program ; 8. Exception handling can avoid program crashes; 9. A large number of development libraries and frameworks; 10. Open source ecosystem.

Master the key features and application scenarios of Golang middleware Master the key features and application scenarios of Golang middleware Mar 20, 2024 pm 06:33 PM

As a fast and efficient programming language, Golang is also widely used in the field of web development. Among them, middleware, as an important design pattern, can help developers better organize and manage code, and improve the reusability and maintainability of code. This article will introduce the key features and application scenarios of middleware in Golang, and illustrate its usage through specific code examples. 1. The concept and function of middleware. As a plug-in component, middleware is located in the request-response processing chain of the application. It is used

See all articles