HTML5 Advanced Topics
HTML5 Advanced Topics Interview with follow-up questions
1. What are some of the new elements introduced in HTML5?
HTML5 introduced a large set of new elements aimed at improving semantic meaning, multimedia support, and interactive capabilities. Key additions include:
Semantic structural elements:
- `` — introductory content or navigational aids for a page or section
- `` — a block of navigation links; screen readers use this as a landmark
- `` — the primary content of the document; there should only be one per page
- `` — self-contained content that could stand alone (blog post, news article, forum post)
- `` — a thematic grouping of content, typically with its own heading
- `` — content tangentially related to the surrounding content (sidebars, pull quotes, ads)
- `` — footer for its nearest sectioning content or the page itself
and— self-contained media (images, diagrams) with an optional caption<address>— contact information for the nearestor<time>— represents a specific time or date, with an optional machine-readabledatetimeattribute<mark>— text highlighted for reference (search result highlighting)
Multimedia elements:
- `` — embeds audio with built-in browser controls; no Flash required
- `` — embeds video with controls, autoplay, loop, and poster image support
— specifies multiple media sources forand `` to handle format compatibility— provides text tracks (captions, subtitles, chapters) for- `
— art-direction wrapper for`, allowing different image sources for different conditions
Interactive / scripting elements:
- `` — scriptable bitmap drawing surface (2D and WebGL)
- `` — inline scalable vector graphics (not new to HTML5 but newly inline-embeddable)
and— a native disclosure widget (accordion-like); no JavaScript needed- `` — a native modal/non-modal dialog element with built-in accessibility roles
Form elements (new input types and elements):
,,,— covered separately- New `
types:email,url,tel,number,range,date,time,color,search`
Common interview follow-ups:
- What is the difference between
and? Anis independently redistributable; ais just a thematic grouping that requires surrounding context. - Why do semantics matter? They improve accessibility (screen reader landmarks), SEO (content hierarchy), and code readability.
<b>vs<strong>,<i>vs<em>— presentational vs semantic emphasis;<strong>and<em>carry meaning for screen readers and search engines.
Follow-up 1
How does the <article> element differ from the <section> element in HTML5?
The element and the element in HTML5 have different purposes and meanings.
``: Represents a self-contained composition in a document, such as a blog post or a news story. It should make sense on its own and be able to be independently distributed or syndicated.
``: Represents a standalone section of a document, such as a chapter or a tabbed content area. It is a thematic grouping of content and does not necessarily have to make sense on its own.
In summary, is used for standalone content, while is used for grouping related content.
Follow-up 2
Can you explain the use of the <nav> element in HTML5?
The `` element in HTML5 is used to define a section of a page that contains navigation links. It is typically used to create a navigation menu or a list of links that allow users to navigate between different pages or sections within a website.
Here's an example of how the `` element can be used:
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
Follow-up 3
What is the purpose of the <header> and <footer> elements in HTML5?
The and elements in HTML5 are used to define the header and footer sections of a document or a section.
``: Represents a container for introductory content or a set of navigational links. It is typically placed at the top of a document or a section.
``: Represents a footer for a document or a section. It is typically placed at the bottom of a document or a section.
These elements are useful for structuring the content of a webpage and providing additional information or navigation options to the users.
2. How does HTML5 handle multimedia content?
HTML5 introduced native multimedia elements that eliminated the need for third-party plugins like Flash or Silverlight.
`` element:
<p>Your browser doesn't support video. <a href="video.mp4">Download it</a>.</p>
Key attributes: controls, autoplay, muted, loop, poster, preload (none, metadata, auto), playsinline (important on iOS).
`` element:
Multiple `` elements: The browser picks the first format it supports. Common format considerations:
- Video: MP4/H.264 has universal support; WebM/VP9 or AV1 for better compression
- Audio: MP3 is universal; OGG/Vorbis and AAC are alternatives
`` element: Provides WebVTT text tracks for captions, subtitles, descriptions, chapters, and metadata. This is essential for accessibility (WCAG 1.2 requires captions for video).
`` element: For responsive images with art direction:
<img src="small.jpg" alt="Description">
The <img> inside `is the fallback and the element that carries thealt` text.
Key JavaScript Media API: The HTMLMediaElement API exposes .play(), .pause(), .currentTime, .duration, .volume, .muted, .playbackRate, and events like play, pause, ended, timeupdate. This is how custom video players are built.
Common gotchas interviewers ask:
autoplayis blocked by most browsers unlessmutedis also set. Autoplay with sound requires a prior user gesture.playsinlinemust be set on iOS to prevent the video from entering fullscreen automatically.- Omitting
alton the<img>inside `` is a common accessibility miss. preload="metadata"is the sensible default — it fetches duration and dimensions without downloading the whole file.- For accessible video, captions (``) differ from subtitles: captions also include non-speech audio information (e.g., "[door slams]") and are intended for deaf viewers.
Follow-up 1
What are the <audio> and <video> elements in HTML5?
The and elements in HTML5 are used to embed audio and video files, respectively, into web pages. These elements provide a way to play media files directly in the browser without requiring any external plugins. You can specify the source file using the 'src' attribute and control the playback using various attributes and methods.
Follow-up 2
How can you add subtitles to a video in HTML5?
To add subtitles to a video in HTML5, you can use the element. The element is used to specify timed text tracks, such as subtitles or captions, for media elements like . You can define the subtitles in a separate file, typically in WebVTT format (.vtt), and reference it using the 'src' attribute of the element. The 'kind' attribute can be set to 'subtitles' or 'captions' to indicate the type of text track.
Follow-up 3
What formats are supported by the <audio> and <video> elements in HTML5?
The and elements in HTML5 support a variety of audio and video formats. The specific formats supported depend on the browser and platform. However, the most widely supported formats include MP3 for audio and MP4 for video. Other supported formats may include Ogg, WebM, and WAV for audio, and WebM, Ogg, and MP4 for video. To ensure cross-browser compatibility, it is recommended to provide multiple sources with different formats using the element within the or element.
3. What is the viewport meta tag in HTML5?
The viewport meta tag is placed in the `` and controls how a browser renders a page on a mobile device.
Without it, mobile browsers use a virtual viewport (typically 980px wide) to render desktop-sized pages and then scale them down, making text tiny and layouts broken.
Common attribute values in content:
width=device-width— sets the viewport width to the actual device screen width in CSS pixels, not physical pixelsinitial-scale=1— no zoom applied on page load; 1:1 ratio between CSS pixels and device-independent pixelsminimum-scale/maximum-scale— limits how far users can zoom in or outuser-scalable=no— disables user zoom entirely
CSS pixels vs physical pixels: The width=device-width value uses CSS pixels (also called logical pixels), not physical pixels. A device with a 1080px physical screen and a 3x device pixel ratio (window.devicePixelRatio === 3) reports a CSS width of 360px. This is why you use @media (max-width: 768px) in CSS and it works predictably across high-density screens.
Why this matters for media queries: Media query width values match the CSS viewport width set by the viewport meta tag, not the physical screen resolution. Without the tag, @media (max-width: 600px) may never trigger on a mobile device that defaults to a 980px virtual viewport.
Accessibility concern with user-scalable=no: Preventing zoom violates WCAG 1.4.4 (Resize Text) and is harmful to users with low vision. Avoid user-scalable=no and maximum-scale=1 in production. Safari on iOS has partially ignored these restrictions since iOS 10 anyway.
interactive-widget (newer attribute): Controls how virtual keyboards affect the viewport layout on mobile. The value resizes-content (the default on most browsers) shrinks the viewport when the on-screen keyboard appears; overlays-content keeps the viewport full size. This matters for sticky bottom UI (e.g., fixed footers, chat inputs).
Common interview follow-up: What happens if you omit the viewport meta tag on a responsive site? The browser defaults to a wide virtual viewport, your min-width media queries never fire for small screens, and the page appears zoomed out. The meta tag is a prerequisite for responsive design to work correctly.
Follow-up 1
How does the viewport meta tag improve mobile browsing?
The viewport meta tag is essential for improving mobile browsing because it allows web developers to create responsive and mobile-friendly websites. By setting the viewport's width and initial scale, developers can ensure that the webpage is displayed correctly on mobile devices, preventing the need for users to zoom in or scroll horizontally to view the content.
Follow-up 2
What are the different values that can be used with the content attribute in the viewport meta tag?
The content attribute in the viewport meta tag can accept various values to control the viewport's behavior. Some commonly used values include:
width=device-width: Sets the width of the viewport to the device's width.initial-scale=1.0: Sets the initial zoom level of the webpage to 1.0.user-scalable=no: Disables user scaling, preventing users from zooming in or out.minimum-scale=1.0andmaximum-scale=1.0: Sets the minimum and maximum zoom levels to 1.0, preventing users from zooming in or out.
Follow-up 3
Why is it important to include the viewport meta tag in an HTML5 document?
Including the viewport meta tag in an HTML5 document is important because it ensures that the webpage is displayed correctly on different devices and screen sizes. Without the viewport meta tag, the webpage may appear zoomed out or require horizontal scrolling on mobile devices, resulting in a poor user experience. By using the viewport meta tag, web developers can create responsive and mobile-friendly websites that adapt to the user's device, improving usability and accessibility.
4. What is the Canvas element in HTML5?
The `` element provides a resolution-dependent bitmap surface that you draw on programmatically with JavaScript. It is a rectangular pixel grid with no built-in accessibility tree — everything rendered on it is invisible to screen readers unless you provide fallback content inside the tags.
Your browser does not support canvas.
The 2D rendering context:
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#3498db';
ctx.fillRect(10, 10, 150, 100);
ctx.beginPath();
ctx.arc(200, 200, 50, 0, Math.PI * 2);
ctx.strokeStyle = 'red';
ctx.stroke();
ctx.font = '24px sans-serif';
ctx.fillStyle = 'black';
ctx.fillText('Hello Canvas', 50, 50);
Key 2D context capabilities:
- Shapes:
fillRect,strokeRect,clearRect,arc,bezierCurveTo,quadraticCurveTo - Text:
fillText,strokeText,measureText - Images:
drawImage(can draw<img>,, another,ImageBitmap) - Transformations:
translate,rotate,scale,setTransform - Compositing:
globalAlpha,globalCompositeOperation - Pixel manipulation:
getImageData,putImageData— raw access to individual RGBA pixels - Gradients and patterns:
createLinearGradient,createRadialGradient,createPattern
WebGL context:
canvas.getContext('webgl') or 'webgl2' gives access to the GPU-accelerated 3D graphics API. Used directly or through libraries like Three.js, Babylon.js, or PixiJS for games and data visualizations.
vs:
- Canvas is a raster (pixel-based) surface. It is stateless — once you draw something, the canvas has no memory of individual shapes. Suitable for pixel manipulation, particle systems, games, real-time visualizations.
- SVG is a vector-based, retained-mode DOM. Individual shapes are DOM nodes, are accessible, are styleable with CSS, and can respond to events. Suitable for charts, icons, interactive diagrams.
Common gotchas:
- Canvas
widthandheightattributes set the drawing buffer size in CSS pixels. Setting size via CSS alone stretches/blurs the content — always set both the HTML attributes and optionally scale for high-DPI screens usingwindow.devicePixelRatio. - High-DPI (Retina) rendering: multiply the canvas width/height by
devicePixelRatioand scale the context withctx.scale(dpr, dpr)to avoid blurry rendering on high-density screens. - Canvas content is not accessible by default. Provide a text description or manage an ARIA live region outside the canvas to describe dynamic content.
- Canvas is not indexed by search engines — do not place text-only content exclusively on a canvas.
Follow-up 1
How do you draw shapes using the Canvas element?
To draw shapes using the Canvas element, you can use JavaScript and the Canvas API. The Canvas API provides several methods for drawing shapes, such as rectangles, circles, lines, and paths. Here is an example of drawing a rectangle on a Canvas:
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'red';
ctx.fillRect(50, 50, 100, 100);
Follow-up 2
What is the difference between SVG and Canvas in HTML5?
SVG (Scalable Vector Graphics) and Canvas are both HTML5 elements used for drawing graphics, but they have some key differences:
SVG is based on XML and uses vector graphics, which means that the shapes and images are defined by mathematical equations. Canvas, on the other hand, is a bitmap-based drawing API, which means that the shapes and images are made up of individual pixels.
SVG is resolution-independent, which means that the graphics will look the same regardless of the screen size or resolution. Canvas, on the other hand, is resolution-dependent, which means that the graphics will look different on different screens.
SVG is better suited for static images and graphics that require interactivity, such as clickable buttons or maps. Canvas is better suited for dynamic and interactive graphics, such as animations or games.
It's important to choose the right tool (SVG or Canvas) based on your specific needs and requirements.
Follow-up 3
How can you animate objects in the Canvas element?
To animate objects in the Canvas element, you can use JavaScript and the requestAnimationFrame method. The requestAnimationFrame method is a built-in function that tells the browser to call a specified function to update an animation before the next repaint. Here is an example of animating a rectangle on a Canvas:
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
let x = 0;
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = 'red';
ctx.fillRect(x, 50, 100, 100);
x += 1;
requestAnimationFrame(animate);
}
animate();
5. What are the new form elements introduced in HTML5?
HTML5 expanded the form toolkit significantly with new input types, helper elements, and built-in validation, reducing reliance on JavaScript and improving accessibility.
New `` types:
email— validates email format; shows email keyboard on mobileurl— validates URL formattel— shows numeric/dial keyboard on mobile; no format validation (phone formats vary globally)number— numeric spinner withmin,max, andstepattributesrange— slider input withmin,max,stepdate,time,datetime-local,month,week— date/time pickers; browser UI variescolor— color picker widgetsearch— search field with platform-specific styling and a clear button
New form elements:
— associates a list of suggested options with anvia itsid; the user can still type freely: ```html
- `` — displays the result of a calculation; semantically linked to form inputs via the `for` attribute:
```html
50
— represents task completion; `value` and `max` attributes define the completion ratio. Without `value`, it shows an indeterminate animation:html 70%``— represents a scalar measurement within a known range (not for progress). Supports `min`, `max`, `low`, `high`, `optimum` to give semantic meaning to where the value falls:html 60%``
New attributes on existing elements:
placeholder— hint text shown when the field is emptyrequired— field must be filled before submissionpattern— regex validationautofocus— automatically focuses the element on page loadautocomplete— hints to the browser's autofill featurenovalidate(on ``) — disables built-in browser validationmultiple— allows multiple values onemailandfileinputsform— associates an input with a `byid`, even if the input is outside the form in the DOM
Common interview gotchas:
is a suggestion list, not a; users can still enter arbitrary text. For constrained choices, use ``.is for ongoing tasks (file upload, loading);is for static measurements (disk usage, score). Using them interchangeably is a common mistake.- Built-in HTML5 validation (
:valid/:invalidpseudo-classes,required,pattern) is useful but limited. Complex validation or custom error messages still require JavaScript using the Constraint Validation API.
Follow-up 1
How does the <datalist> element work in HTML5?
The element in HTML5 provides a list of predefined options for an element. It works by associating the element with an element using the list attribute. The options are defined using elements within the element.
When the user interacts with the associated `` element, a dropdown list of options is displayed. The user can select an option from the list or enter a custom value.
Here's an example of how to use the `` element:
Choose a fruit:
Follow-up 2
What is the purpose of the <output> element in HTML5?
The `` element in HTML5 is used to display the result of a calculation or the output of a script. It can be used to show the result of a form submission or any other dynamic content.
The element can be associated with other form elements using the `for` attribute. When the associated form element's value changes, the content of the element is automatically updated.
Here's an example of how to use the `` element:
Enter a number:
Enter another number:
Follow-up 3
How can you use the <progress> and <meter> elements in HTML5?
The and elements in HTML5 are used to display visual representations of progress or measurements.
The `element represents the progress of a task. It can be used to show the completion status of a form submission, file upload, or any other process. The progress value is specified using thevalueattribute, and the maximum value is specified using themax` attribute.
Here's an example of how to use the `` element:
The `element is used to represent a scalar measurement within a known range. It can be used to display values such as disk usage, completion percentage, or any other measurable quantity. The value and range are specified using thevalue,min, andmax` attributes.
Here's an example of how to use the `` element:
75%
Live mock interview
Mock interview: HTML5 Advanced Topics
- Read your scene and goals
- Talk it out; goals tick off live
- Get a score and stronger lines
Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.