HTML5 and its Essentials: Explore New Features!

Exploring New Features in HTML5:

You’ve previously learned that HTML5 is the current major version of HTML. HTML5 and its Essentials add a number of new elements and properties to help you construct interactive websites. Some of these components and attributes are new additions, while others are refinements to existing ones. In the parts that follow, we will learn about HTML5’s upgrades and new features.

New Elements:

HTML5 introduces a number of new elements to improve the semantic structure of web documents and facilitate modern web development processes. For instance, the AUDIO and VIDEO elements are used to embed media files in a Web page. The HEADER and FOOTER elements are used to display the header and footer sections in a Web page. The following are some of the noteworthy new components included in HTML5:

ElementDescription
ARTICLEshows an independent entry of a blog or a magazine
ASIDEshows a note tip, a sidebar, a parenthetical mark, or the content other than the main content
AUDIOallows you to embed audio files in a web page
BDIallows you to specify the non-left-to-right direction for a span of text
CANVASprovides a canvas on a web page to draw graphics on it
COMMANDstores a command to perform a task
DATALISTshows a drop-down list
DETAILSshows the details of an item besides its default information
EMBEDdefines external interactive content or plug-in
FIGCAPTIONshows the caption of the FIGURE element
FIGUREshows a group of media elements, VIDEO and AUDIO, along with a caption
FOOTERshows the footer of a section or page
HEADERshows the header of a section or page
HGROUPrepresents a group of headings in a document
KEYGENspecifies an element that generates a pair of key (private and public keys) for forms, where private key is stored locally with the submission of a form and the public key is sent to the server
MARKshows highlighted text
MENUshows a menu bar on a web page
METERdisplays the measurement of a number in a predefined range
NAVshows a collection of links related to other web pages
OUTPUTspecifies an element that is used to display output
PROGRESSshows the progress of an ongoing process
RPdictates the browsers to show the content when they do not support the RUBY element
RTshows the details of ruby annotations
RUBYshows characters that define ruby annotations
SECTIONshows a section of a chapter or a part of a book
SOURCErepresents a media resource
SUMMARYshows the summary of a DETAILS element
TIMEshows the date and time on a web page
VIDEOallows you to embed videos in a web page
WBRdefines a possible line break that can be inserted into a text
Table 1 – New elements in HTML5

These new components, among many others, help to improve document organization, accessibility, and support for multimedia and interactive content. Developers can use these elements to construct more semantically relevant and feature-rich web pages. Keep in mind that browser support for these elements is generally broad, but it’s always a good idea to test for compatibility based on the intended audience.

New Attributes:

HTML5 included various new features to improve the functionality and flexibility of web programming. These properties extend HTML5’s capabilities, giving developers additional control and customization options for creating interactive and dynamic web applications. When utilizing newer characteristics, remember to consider sufficient browser support. Here are some important new attributes introduced in HTML5:

AttributeDescription
accesskeyrepresents a keyboard shortcut to access an element
contenteditablespecifies whether or not a user is allowed to edit the content
contextmenurepresents the context menu for an element
data-yourvaluerepresents user-defined attributes that must start with the data-text
draggablespecifies whether or not a user is able to drag an element
dropzonespecifies the drop target for a dragged element
hiddenhides a non-relevant element
spellcheckspecifies whether or not the spelling or grammar-checking feature is enabled for an element
Table 2 – New attributes in HTML5

Link Relations:

In HTML5, the rel attribute defines the relationship between the current content and an external resource, which is generally connected using the <a> (anchor) or <link> elements. The rel attribute describes the type or nature of the link, which frequently determines how the browser handles or interprets the linked resource. It is essential to supply more information to browsers, search engines, and other user agents regarding the relationship between the current document and other resources. The specific values and their meanings may differ, thus consult the HTML5 specification or associated documentation for accurate and up-to-date information.

Microdata:

Microdata is a feature in HTML5 that allows you to add machine-readable data in HTML texts. It defines a standardized syntax that adds semantic information to web content, helping search engines and other applications to understand better and interpret the data. Microdata is commonly used to provide context to web content, including product information, reviews, events, and more. It attaches name-value pairs to HTML elements using HTML attributes. The crucial aspects of microdata are itemscope, itemtype, and itemprop.

Microdata is frequently associated with popular schemas such as Schema.org, which offers diverse types and characteristics for representing entities such as persons, organizations, events, and items. While microdata is one method for providing semantic information, other options include RDFa and JSON-LD. The approach to be used is typically determined by the project’s specific requirements and personal taste. Using microdata can help search engines and other apps find and comprehend your material better.

AttributeDescription
itemidrepresents an id that specifies a vocabulary for a specific type of items
itempropspecifies a property of an item
itemrefprovides a reference of a specific type of items
itemscoperepresents a boolean attribute that shows the position and presence of microdata on an HTML document, which is read by a computer
itemtyperepresents a valid URL to define a specific type of items
Table 3 – Microdata Attributes

An example of using the microdata in an HTML document is given in the following code snippet:

In the preceding code snippet, an item gives the information of a particular book.

ARIA Accessibility:

Accessible Rich Internet Applications is a set of features developed by the W3C to improve the accessibility of web content, particularly dynamic and interactive components, for people with impairments. ARIA properties can be added to HTML elements to help assistive devices, such as screen readers, understand and convey the purpose and status of user interface elements. Using ARIA features in conjunction with proper HTML semantics allows developers to design more accessible and useable online applications. It is critical to remember that ARIA should be utilized sparingly and in conjunction with native HTML elements whenever possible to guarantee a strong and consistent user experience. Furthermore, regular testing with assistive technologies is essential for assessing the effectiveness of ARIA implementations.

Web Forms 2.0:

As of my most recent knowledge update in January 2022, there is no distinct HTML version known as “Web Forms 2.0” in the official HTML specifications. However, HTML5 brings substantial changes and enhancements to the way forms are developed and managed on the web. The HTML5 specification included additional form elements, properties, and APIs that help to improve the user experience and functionality of web forms.

It is important to note that HTML and web technology capabilities and specifications are subject to change. Always consult the most recent HTML specifications and browser documentation for the most up-to-date information on HTML and its features.

Newly added attributes of the FORM element: Here are some commonly used form-related attributes that have been part of HTML5:

  • autocomplete Attribute: The autocomplete feature lets developers specify whether the browser should automatically finish input values based on the user’s input history.
  • formnovalidate Attribute: The formnovalidate attribute overrides the form’s validation and allows form submission even when the form is invalid.

Newly added attributes of the INPUT element: Here are some of the attributes that were introduced or enhanced for the element in HTML5:

AttributeDescription
autocompletespecifies that an input field automatically fills the content
autofocusspecifies that an input field automatically gets focus when a page is loaded
formspecifies that an input field belongs to one or more forms
formactionspecifies an attribute that overrides the form action attribute
formenctypespecifies an attribute that overrides the form enctype attribute
formmethodspecifies an attribute that overrides the form method attribute
formnovalidatespecifies an attribute that overrides the form novalidate attribute
formtargetspecifies an attribute that overrides the form target attribute
heightspecifies the height of an image used as an input
widthspecifies the width of an image used as an input
listspecifies a datalist for an input field
minspecifies the minimum value that is allowed for the input field
maxspecifies the maximum value that is allowed for the input field
stepspecifies an increment number for the input field that takes a range of numbers
multiplespecifies that multiple values can be selected for an input field
patternspecifies a pattern used to validate an input field
placeholderspecifies a default text in the input field until you focus the field for entering your text
requiredspecifies that an input field must be filled with data before submitting the form containing it
Table 4 – List of newly added attributes for the INPUT element

Newly added attributes for the type attribute: The HTML standards for the element did not introduce any new values for the type attribute. The type attribute specifies the type of input control that will be shown, and the allowed values are well-known. While these are the most common and extensively used varieties, it is important to note that HTML requirements might change. New features and characteristics may be included in subsequent HTML versions or updates. Always consult the most recent HTML specifications and browser documentation for the most up-to-date information on HTML characteristics.

TypeDescription
datetimedisplays date and time on the basis of ISO 8601 with the time zone set to Universal Time Coordinated(UTC)
datetime-localdisplayed date and time on the basis of ISO 8601 without the time zone information
datedisplays date on the basis of ISO 8601
monthdisplays date, consisting of a year and a month, on the basis of ISO 8601
weekdisplays date, consisting of a year and the number of the current week of the year, on the basis of ISO 8601
timedisplays time on the basis of ISO 8601
numberallows a field to accept only numerical value and takes 1 as the default number
rangeallows a field to accept a value from a range of numbers
emailallows a field to accept only an email format value, for instance htmllearning5@abc.com
urlallows a field to accept only the URL format value, for instance html@abc.com
Table 5 – List of Newly added values of the type attribute

Multimedia:

HTML5 added native support for multimedia components, allowing users to incorporate music and video material directly into web pages without relying on third-party plugins such as Flash. HTML5 introduces two main multimedia elements:

Audio Element: The <audio> element embeds audio material in a web page. It supports a variety of audio file types, and you may specify several source components to ensure compatibility across browsers.

  • The controls attribute provides playback controls (play, pause, volume, etc.).
  • Multiple <source> components with various file formats offer fallback alternatives for browser compatibility.

Video Element: The <video> element embeds video information in a web page. Similar to <audio>, it accepts numerous video file formats and allows multiple sources for compatibility.

  • The controls attribute specifies playback controls.
  • The width and height properties determine the proportions of the video player.
  • Multiple <source> elements offer backup alternatives.

These elements and characteristics help to integrate multimedia material more seamlessly on the web, and most recent web browsers support them. Always provide numerous source options to ensure compatibility with various browsers and devices.

2D and 3D drawings support HTML5:

HTML5’s <canvas> element enables developers to create dynamic graphics, charts, animations, and more right on a web page. While HTML5 does not have native support for 3D drawing, newer browsers frequently include APIs and technologies that enable 3D graphics.

2D Drawing with Canvas: The <canvas> element and 2D drawing environment enable developers to create shapes, paths, text, and images on a two-dimensional plane. JavaScript is frequently used to interact with the canvas and generate dynamic visualizations. Example of a simple two-dimensional drawing on a canvas:

3D Drawing with WebGL: For 3D graphics, HTML5 itself does not contain a native 3D drawing context. However, WebGL, a JavaScript API based on OpenGL ES, allows for high-performance 3D visuals within the HTML5 canvas element. Most contemporary browsers support WebGL. An example of a simple 3D drawing with WebGL:

To work with 3D visuals in WebGL, developers often need extra libraries and frameworks such as Three.js, Babylon.js, or A-Frames. These libraries streamline the process of creating and interacting with 3D sceneries in the browser.

Keep in mind that WebGL requires a strong understanding of computer graphics and may have a steeper learning curve than 2D canvas sketching. When deciding between 2D and 3D graphics, always consider browser compatibility and your project’s specific requirements.

Offline Web Applications and Caching:

Offline web apps employ HTML5 cache technologies to improve the user experience when there is no internet connection. Key features include:

  • Service Workers: Service workers, a type of JavaScript worker, allow background script execution. They can intercept and process network requests, enabling offline access.
  • Application Cache (appCache): HTML5 AppCache allows developers to specify files for offline caching, ensuring that critical resources are accessible even without an internet connection.
  • Offline web apps use IndexedDB and Web Storage (e.g., localStorage) to store data on the client side, enabling offline interaction.
  • AppCache and Progressive Web Apps (PWAs) use manifest files to cache resources for offline access.

The Cache API enables developers to programmatically manage caches, providing precise control over resource caching and retrieval.

Using these HTML5 technologies, developers may construct online applications that are functional and responsive in offline settings, increasing user engagement and pleasure. Always evaluate your application’s specific requirements and consult the most recent documentation for the most up-to-date information.

CSS enhancements:

CSS (Cascading Style Sheets) is a different technology from HTML, yet it works in tandem with HTML to style and format web pages. HTML provides a webpage’s structure and information, whereas CSS is responsible for display and styling. Here are some CSS enhancements and features that contribute to better styling and design in HTML.

CSS Selectors: CSS selectors let you target and style certain HTML components. They can be based on element names, classes, IDs, properties, and so on.

New Fonts: Google Fonts: Use Google Fonts by including a link in your HTML file. Example:

Font Family: Apply the new font to an element in your CSS. Example:

Text Wrapping: Text wrapping describes how text flows around an element, such as an image or a floating container. It ensures that the text does not overrun the given element. In CSS, the float property is often used for text wrapping.

In this example, the float: left; property causes the image to float to the left, and the text wraps around it.

Text Stroke: Text stroke involves adding an outline or border to the text letters, resulting in a visual effect comparable to a stroke in graphics software. The text-stroke feature is not widely supported, thus text-shadow is frequently used instead.

In this example, -webkit-text-stroke is utilised for Webkit browsers, with text-shadow serving as a fallback for other browsers. The text-shadow property produces a similar visual effect by casting a shadow on the text.

Multi-column Layout: The column-count and column-width properties allow you to create multi-column layouts for text content.

Opacity: Opacity refers to an element’s transparency. In CSS, the opacity property is used to manage the transparency of an element, where a value of 0 implies totally transparent, and 1 means wholly opaque.

In this example, the .transparent-box class is used to make an element semi-transparent with an opacity of 0.5.

Hue/Saturation/Luminance (HSL) Color Model: The HSL color model divides colors into three components: hue, saturation, and luminance. It offers a more natural approach to specify colors than other models, such as RGB. Hue (0–360 degrees): Represents the color itself. Saturation (0–100%): Indicates the strength or purity of the color. Luminance (0% to 100%): Indicates the brightness of a color.

In this example, the .colorful-text class is applied to text, setting its color to a green shade using the HSL color model. The values (120, 100%, 50%) represent a green hue with full saturation and 50% brightness. You can experiment with different values for hue, saturation, and brightness to achieve a wide spectrum of colors using the HSL color model.

Rounded Corners: Rounded edges provide a gentle and visually attractive touch to items. CSS’s border-radius attribute controls the curvature of an element’s corners.

In this example, the .rounded-box class is applied to an element, resulting in rounded corners with a radius of 10 pixels.

Color Gradients: Colour gradients enable you to make smooth transitions between different colours. CSS’s linear-gradient feature is widely used to apply colour gradients.

In this example, the .gradient-background class is applied to an element to create a horizontal color gradient background ranging from yellow (#ffcc00) to red (#ff6666). The linear gradient property allows you to change the colors, direction, and placements to create a variety of gradient effects.

Shadows: Shadows provide depth and substance to things on a webpage. CSS has attributes for producing box shadows and text shadows.

In this example, the .box-with-shadow class is applied to an element, resulting in a box shadow with a horizontal offset of 5 pixels, a vertical offset of 5 pixels, a blur radius of 10 pixels, and a semi-transparent black color.

In this example, the .text-with-shadow class is applied to text, resulting in a text shadow with a horizontal offset of 2 pixels, a vertical offset of 2 pixels, a blur radius of 4 pixels, and a semi-transparent black color.

Background Enhancements: Enhancing backgrounds entails using characteristics such as gradients, graphics, and other aspects to increase the visual attractiveness of the background.

In this example, the .gradient-background class is used as an element to create a horizontal gradient background ranging from yellow (#ffcc00) to red (#ff6666).

In this example, the .background-with-image class is applied to an element, which creates a backdrop picture with additional parameters like size and position.

Enhanced Box Model: Box Sizing: Use box-sizing property for a more predictable box model.

Margins and padding: Use the margin and padding properties to adjust the spacing.

Transitions and Animations: CSS transitions and animations make it possible to create dynamic, interactive animations as well as smooth transitions between states.

Transforms: CSS transforms (transform, rotate, scale, and translate) allow you to apply 2D and 3D transformations to elements.

These CSS enhancements improve web developers’ styling powers, allowing them to construct more responsive, dynamic, and visually appealing designs. They supplement the structural features introduced in HTML5, resulting in a more contemporary and adaptable web development experience.

Client Side Storage:

Client-side storage in HTML5 refers to web browsers’ ability to save data locally on the user’s device. HTML5 has two key techniques for client-side storage: localStorage and sessionStorage.

localStorage:

  • Persistent Storage: Data is saved between browser sessions and even when closed and reopened.
  • Storage Limit: Browsers often enable several megabytes of storage per domain.
  • Scope: Applied to all windows/tabs with the same origin.

sessionStorage:

  • Session-based storage means data is only available for the duration of a page session. It is cleared when the session ends (when the browser or tab is closed).
  • Storage Limit: Like localStorage, but limited to the current session.
  • Scope: Applies to a certain window/tab.

These storage techniques provide a simple key-value storage system on the client side, allowing web applications to store and retrieve data without requiring server-side databases for every interaction. Always be mindful of the data you store and the security consequences, particularly when working with sensitive information. Additionally, ensure that these functionalities are compatible with your browser.

WebSockets:

WebSockets provide full-duplex communication via a single, long-lived connection. They provide real-time communication between a web browser and a server, allowing data to be delivered and received in both directions without the need for further HTTP requests. Key Features:

  • Real-time communication allows for real-time data sharing between clients and servers.
  • Efficiency: Lower latency and overhead than typical HTTP polling.
  • Bi-directional communication allows for data transfer from the client to the server and vice versa.
  • Use the WebSocket API in JavaScript to create and manage WebSocket connections.

Web Workers:

Web Workers enable developers to run scripts in the background, independent of the main thread of the web page. This allows for parallel task execution while maintaining the responsiveness of the user interface. Key Features:

  • Concurrent execution allows tasks to run concurrently without stopping the main thread.
  • Background processing is useful for long-running, computationally heavy processes.
  • Web Workers cannot access the DOM or the main thread’s JavaScript as they run in a different thread.
  • There are two types of workers: dedicated and shared. Dedicated workers belong to the script that created them, while shared workers can be used by various scripts.

In the example above, worker.js is a separate JavaScript file containing the code that will be run by the Web Worker.

Notifications:

Notifications enable web applications to display system-level notifications to users, giving a means of communicating vital information or events even when the programme is not in focus. Key Features:

  • Modern web browsers provide cross-browser support.
  • Notifications can have customisable content, including a title, body, and icon.
  • Permission-Based: Before displaying notifications, the user must first grant authorization.
  • Event Handling: Enables event handlers for user interaction with notifications.

Drag and Drop API:

The Drag and Drop API enables users to drag and drop components on a web page. It facilitates the implementation of drag-and-drop capability in interactive user interfaces. Key Features:

  • The event-based approach relies on drag-and-drop events such as dragstart, dragenter, dragover, and drop.
  • Customisable Data Transfer: Enables data customisation during drag-and-drop operations.
  • Visual feedback is provided during drag operations, including a draggable ghost picture.

In this example, the .draggable element is made draggable, and the dragStart function is invoked when the drag action begins. The event.dataTransfer object is used to modify the data being sent.

Geolocation API:

The Geolocation API in HTML5 enables web applications to obtain the user’s geographical location. It gives latitude, longitude, altitude, and precision, allowing developers to create location-aware apps. Key Features:

  • To get location information, users must provide their consent.
  • Asynchronous operation involves providing location data via callback routines.
  • High Accuracy: Provides precise location information when available.

Modernizr:

Modernizr is not an HTML5 feature, but rather a JavaScript package that recognises HTML5 and CSS3 elements in a user’s browser. It enables developers to include conditional statements in their code based on the existence or absence of specific features, resulting in improved cross-browser compatibility. Key Features:

  • Detects available HTML5 and CSS3 features.
  • Conditional Loading enables script or stylesheet loading based on detected features.
  • Cross-browser compatibility provides a uniform experience across several browsers.

In this example, Modernizr is used to check if the browser supports the Geolocation API before attempting to utilize it.

Scroll to Top