search
HomeWeb Front-endH5 TutorialIntroducing the new content in HTML5.1

HTML 5.1 Overview

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 a draft of HTML5.2, 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 selecting or deselecting an option;


  • command – Allows an action to be performed when the mouse is clicked;


  • radio – allows selection of one from a set of options.

Here is a basic usage example that can be run in Firefox 49, but not Chrome 54 currently.

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

On a supported browser, this context menu example 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 something you often do when using JavaScript, and now you can use the
element and the element to do it for you. Click on the element to show and hide the rest of the details element.

The following example can be tested in Firefox and Chrome.

Please see SitePoint (@SitePoint)’s 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 Firefox.

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

HTML 5.1 includes several new features for implementing 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="/static/imghwm/default1.png" data-src="images/low-res.jpg" class="lazy" alt="Introducing the new content in HTML5.1" >

In this example, if the pixel ratio of the user's 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 will be displayed.

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

<img  src="/static/imghwm/default1.png" data-src="images/low-res.jpg" class="lazy" alt="Introducing the new content in HTML5.1" >

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

sizes attribute

You may want to display images differently 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. Here is an example:

<img  src="/static/imghwm/default1.png" data-src="images/low-res.jpg" class="lazy" alt="Introducing the new content in HTML5.1" >

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 equal to 40em, the size attribute defines the image width 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>
  <source>

  <img  src="/static/imghwm/default1.png" data-src="images/large/low-res.jpg" class="lazy" alt="Introducing the new content in HTML5.1" >
</source></source></picture>

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

Use form.reportValidity() to verify the form

The form.checkValidity() method defined in HTML5 can check whether the form complies with 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's 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 goes as expected, it will look like this:

Working form validation with a message

Allowfullscreen property of frames

The new Boolean attribute allowfullscreen of frames can control whether the content can be displayed in full screen through the requestFullscreen() method.

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 written into HTML5.1

Some features were defined in the first draft but were eventually removed, mostly due to lack of interest from browser vendors. Here are some 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, and it even has a convenient form collection - using the method attribute on the prevents the form from being submitted to the server and instead closes the popup and returns the results to the popup. the founder of.

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:

See the CodePen example of SitePoint (@SitePoint) HTML dialog element.

More articles from the author

  • Up and Running with ESLint — the Pluggable JavaScript Linter


  • Visual Regression Testing with PhantomCSS

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

Statement
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
H5: How It Enhances User Experience on the WebH5: How It Enhances User Experience on the WebApr 19, 2025 am 12:08 AM

H5 improves web user experience with multimedia support, offline storage and performance optimization. 1) Multimedia support: H5 and elements simplify development and improve user experience. 2) Offline storage: WebStorage and IndexedDB allow offline use to improve the experience. 3) Performance optimization: WebWorkers and elements optimize performance to reduce bandwidth consumption.

Deconstructing H5 Code: Tags, Elements, and AttributesDeconstructing H5 Code: Tags, Elements, and AttributesApr 18, 2025 am 12:06 AM

HTML5 code consists of tags, elements and attributes: 1. The tag defines the content type and is surrounded by angle brackets, such as. 2. Elements are composed of start tags, contents and end tags, such as contents. 3. Attributes define key-value pairs in the start tag, enhance functions, such as. These are the basic units for building web structure.

Understanding H5 Code: The Fundamentals of HTML5Understanding H5 Code: The Fundamentals of HTML5Apr 17, 2025 am 12:08 AM

HTML5 is a key technology for building modern web pages, providing many new elements and features. 1. HTML5 introduces semantic elements such as, , etc., which enhances web page structure and SEO. 2. Support multimedia elements and embed media without plug-ins. 3. Forms enhance new input types and verification properties, simplifying the verification process. 4. Offer offline and local storage functions to improve web page performance and user experience.

H5 Code: Best Practices for Web DevelopersH5 Code: Best Practices for Web DevelopersApr 16, 2025 am 12:14 AM

Best practices for H5 code include: 1. Use correct DOCTYPE declarations and character encoding; 2. Use semantic tags; 3. Reduce HTTP requests; 4. Use asynchronous loading; 5. Optimize images. These practices can improve the efficiency, maintainability and user experience of web pages.

H5: The Evolution of Web Standards and TechnologiesH5: The Evolution of Web Standards and TechnologiesApr 15, 2025 am 12:12 AM

Web standards and technologies have evolved from HTML4, CSS2 and simple JavaScript to date and have undergone significant developments. 1) HTML5 introduces APIs such as Canvas and WebStorage, which enhances the complexity and interactivity of web applications. 2) CSS3 adds animation and transition functions to make the page more effective. 3) JavaScript improves development efficiency and code readability through modern syntax of Node.js and ES6, such as arrow functions and classes. These changes have promoted the development of performance optimization and best practices of web applications.

Is H5 a Shorthand for HTML5? Exploring the DetailsIs H5 a Shorthand for HTML5? Exploring the DetailsApr 14, 2025 am 12:05 AM

H5 is not just the abbreviation of HTML5, it represents a wider modern web development technology ecosystem: 1. H5 includes HTML5, CSS3, JavaScript and related APIs and technologies; 2. It provides a richer, interactive and smooth user experience, and can run seamlessly on multiple devices; 3. Using the H5 technology stack, you can create responsive web pages and complex interactive functions.

H5 and HTML5: Commonly Used Terms in Web DevelopmentH5 and HTML5: Commonly Used Terms in Web DevelopmentApr 13, 2025 am 12:01 AM

H5 and HTML5 refer to the same thing, namely HTML5. HTML5 is the fifth version of HTML, bringing new features such as semantic tags, multimedia support, canvas and graphics, offline storage and local storage, improving the expressiveness and interactivity of web pages.

What Does H5 Refer To? Exploring the ContextWhat Does H5 Refer To? Exploring the ContextApr 12, 2025 am 12:03 AM

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.