HTML Advanced Topics
HTML Advanced Topics Interview with follow-up questions
1. Can you explain how to use images in HTML?
Images in HTML are embedded with the <img> element. The minimum viable usage requires src and alt:
<img src="photo.jpg" alt="A red fox sitting in autumn leaves">
Core attributes:
src— the image URL or relative path. Required.alt— alternative text for accessibility and fallback. Required on meaningful images; usealt=""(empty string, not omitted) for decorative images that add no information.widthandheight— declare the intrinsic dimensions in pixels (no units). The browser reserves space before the image loads, preventing cumulative layout shift (CLS). Always include both.loading="lazy"— defers loading until the image is near the viewport. Use for below-the-fold images. The browser will automatically useloading="eager"(the default) for images with high fetch priority.decoding="async"— decodes the image off the main thread, avoiding jank during page load.fetchpriority="high"— tells the browser to prioritize fetching this image. Use on the LCP (Largest Contentful Paint) image to improve Core Web Vitals.
Responsive images with srcset and sizes:
<img src="photo-800.jpg" alt="A red fox sitting in autumn leaves" width="800" height="533">
The browser selects the best source based on the viewport width and device pixel ratio, saving bandwidth on mobile.
`` for format selection and art direction:
<img src="photo.jpg" alt="A red fox sitting in autumn leaves" width="800" height="533">
This serves AVIF (best compression), falls back to WebP, then JPEG. The <img> element inside `` is always required and acts as the fallback.
Common gotchas: omitting alt is an accessibility failure. Omitting width/height causes layout shift. Lazy-loading the above-the-fold hero image delays LCP.
Follow-up 1
What is the significance of the 'alt' attribute in an image tag?
The 'alt' attribute in an image tag is used to provide alternative text for the image. It is important for accessibility purposes, as it is displayed if the image cannot be loaded or if the user is using a screen reader. The alternative text should describe the content or purpose of the image. It is also used by search engines to understand the content of the image.
Follow-up 2
How can you specify the dimensions of an image?
You can specify the dimensions of an image using the 'width' and 'height' attributes in the <img> tag. The 'width' attribute specifies the width of the image in pixels or as a percentage of the parent element, while the 'height' attribute specifies the height of the image in pixels or as a percentage of the parent element.
Here is an example of how to specify the dimensions of an image:
<img src="image.jpg" alt="Description of the image" width="300" height="200">
Follow-up 3
What is the difference between SVG and raster images in HTML?
SVG (Scalable Vector Graphics) and raster images are two different types of image formats used in HTML.
SVG images are vector-based, which means they are composed of mathematical equations that define the shapes and colors of the image. This allows SVG images to be scaled without losing quality, making them ideal for logos, icons, and other graphics that need to be resized.
On the other hand, raster images are made up of a grid of pixels and are resolution-dependent. They have a fixed size and can lose quality when scaled up. Common raster image formats include JPEG, PNG, and GIF.
In summary, SVG images are scalable and resolution-independent, while raster images have a fixed size and resolution.
2. How do you create tables in HTML?
HTML tables are created with a set of nested elements: wraps the entire table;, , and organize rows into logical sections; defines each row; defines header cells; `` defines data cells.
Name
Role
Department
Alice
Engineer
Platform
Bob
Designer
Product
Key elements and attributes:
— a header cell. Browsers bold and center it by default, but more importantly, screen readers use it to identify column and row headers. Always usefor headers, not ``.scope="col"/scope="row"— on `` elements, explicitly associates the header with its column or row for assistive technologies. Critical for accessibility.colspanandrowspan— merge cells across multiple columns or rows.— a title for the table, placed immediately after. Screen readers read it first. Use it instead of a heading above the table for semantic association.,,— these are optional but recommended.and `` repeat on printed pages and help browsers render large tables incrementally.
When to use tables: only for tabular data — data where the relationships between cells across rows and columns carry meaning. Do not use tables for layout. CSS Grid and Flexbox handle layout; using a table for a two-column page design is a serious anti-pattern and breaks accessibility.
Responsive tables — wide tables overflow on small screens. Common solutions: horizontal scroll on a wrapper (overflow-x: auto), or transforming the table to a card layout at narrow viewports using CSS and data-label attributes.
Follow-up 1
What are the key tags used in creating a table?
The key tags used in creating a table in HTML are:
- ``: Defines a table
- ``: Defines a row in a table
- ``: Defines a cell in a table
- ``: Defines a header cell in a table
- ``: Groups the header content in a table
- ``: Groups the body content in a table
- ``: Groups the footer content in a table
Here's an example of how these tags can be used to create a table:
Header 1
Header 2
Row 1, Column 1
Row 1, Column 2
Row 2, Column 1
Row 2, Column 2
Footer 1
Footer 2
Follow-up 2
How can you merge cells in a table?
To merge cells in a table, you can use the colspan attribute for or elements. The colspan attribute specifies the number of columns a cell should span. Here's an example of how to merge two cells in the first row of a table:
Merged Cell
Row 2, Column 1
Row 2, Column 2
Follow-up 3
What is the purpose of 'thead', 'tbody' and 'tfoot' in a table?
The purpose of 'thead', 'tbody', and 'tfoot' in a table is to group the content of the table into different sections:
- ``: Groups the header content of the table. It is used to define the header section of a table, which typically contains the column headings.
- ``: Groups the body content of the table. It is used to define the main content section of a table, which contains the rows and cells.
- ``: Groups the footer content of the table. It is used to define the footer section of a table, which typically contains summary information or additional details.
Using these tags can help improve the structure and accessibility of the table. Here's an example of how they can be used:
Header 1
Header 2
Row 1, Column 1
Row 1, Column 2
Row 2, Column 1
Row 2, Column 2
Footer 1
Footer 2
3. Can you describe how to create links in HTML?
Links in HTML are created with the <a> (anchor) element. The href attribute specifies where the link goes:
</a><a href="https://www.example.com">Visit Example</a>
Types of link destinations:
- Absolute URL — full URL including scheme and domain:
href="https://example.com/page" - Relative URL — path relative to the current document:
href="/about"orhref="../images/photo.jpg" - Fragment identifier — jumps to an element with a matching
idon the current page:href="#contact-form" - Email — opens the user's mail client:
href="mailto:[email protected]" - Phone — initiates a call on mobile:
href="tel:+15551234567" - File download — triggers a download rather than navigation when combined with the
downloadattribute:<a href="report.pdf">Download report</a>
Important attributes:
target="_blank"— opens the link in a new tab or window. Must be paired withrel="noopener noreferrer"to prevent the new page from accessingwindow.opener(a reverse tabnapping security risk) and to avoid passing theRefererheader.rel— describes the relationship:nofollowtells search engines not to pass link equity;noopenerandnoreferrerare security attributes;canonicalindicates the preferred URL for duplicate content.aria-label— provides a descriptive accessible name when the visible text alone is ambiguous.<a href="/report">Download</a>is better than unlabeled "Download" links when multiple similar links exist on the page.aria-current="page"— marks the current page in a navigation list for screen readers.
Accessibility gotcha: link text should describe the destination on its own — "Click here" and "Read more" are poor link labels because screen reader users often navigate by listing all links on the page. Descriptive text like "Read our accessibility guide" is correct.
`vs.`: use </a><a> for navigation (changing the URL or downloading a file); use `` for actions that don't navigate (submitting a form, toggling a modal, triggering JavaScript). Misusing one for the other breaks keyboard accessibility and screen reader expectations.
Follow-up 1
What is the difference between absolute and relative URLs?
An absolute URL is a complete URL that includes the protocol (e.g., http:// or https://), domain name, and path to the resource. It specifies the exact location of the resource on the internet. For example, https://www.example.com/page.html is an absolute URL.
On the other hand, a relative URL is a URL that is relative to the current page's URL. It specifies the location of the resource relative to the current page. For example, if the current page's URL is https://www.example.com, a relative URL like /page.html would refer to https://www.example.com/page.html.
The choice between absolute and relative URLs depends on the specific use case and requirements of your website.
Follow-up 2
What does the 'target' attribute do in a link?
The target attribute in a link specifies where to open the linked document when the user clicks on the link. It can take several values:
_blank: Opens the linked document in a new browser window or tab._self: Opens the linked document in the same frame or window as the link._parent: Opens the linked document in the parent frame._top: Opens the linked document in the full body of the window.
Here's an example:
<a href="https://www.example.com">Click here</a>
Follow-up 3
How can you link to a specific part of a page?
To link to a specific part of a page, you can use anchor tags with the id attribute. Here's how:
- Add an
idattribute to the element you want to link to. For example:
<h2>Section 1</h2>
- Create a link to the element using the
hrefattribute and the#symbol followed by theidvalue. For example:
<a href="#section1">Go to Section 1</a>
When the link is clicked, the browser will scroll to the element with the specified id on the same page.
4. What is the importance of document structure in HTML?
HTML document structure matters for several interconnected reasons: browser rendering, accessibility, SEO, and maintainability.
Correct structural skeleton:
Page Title
...
...
...
...
...
Why structure matters:
Rendering — the browser parses HTML top-to-bottom to build the DOM. Structure determines parse order, which affects when stylesheets and scripts are discovered and applied. A blocking `in<head>withoutdeferdelays rendering; placing<meta charset>` first prevents potential character encoding issues.
Accessibility — screen readers use landmark elements (<header>, <nav>, <main>, <footer>, <aside>) to let users jump between page sections. The heading hierarchy (<h1> through <h6>) creates an outline that screen reader users navigate with keyboard shortcuts. Broken heading order (jumping from <h1> to <h4>) or missing landmarks make pages difficult to navigate without a mouse.
SEO — search engines use semantic structure to understand page content. A single <h1> identifying the page topic, followed by a logical heading outline, helps crawlers index content correctly. <main> signals the primary content area. <article> signals self-contained content.
Maintainability — a clear, semantic structure is easier to style, debug, and hand off to other developers. Deeply nested <div> soup with no semantic meaning requires reading the CSS classes to understand what each block represents; semantic HTML communicates intent in the markup itself.
The lang attribute on <html> is often overlooked: it tells screen readers which language pronunciation rules to use and enables browser spell-checking. It's required for WCAG compliance.
Follow-up 1
What are semantic HTML elements?
Semantic HTML elements are tags that convey meaning about the content they enclose. They provide a way to describe the structure and purpose of the content, making it more accessible and understandable for both humans and machines. Examples of semantic HTML elements include , , , , , , etc.
Follow-up 2
How does a well-structured document assist with SEO?
A well-structured document can assist with SEO (Search Engine Optimization) by providing search engines with clear and meaningful information about the content of a web page. Search engines use the structure of the HTML document to understand the relevance and context of the content. Proper use of semantic HTML elements, headings, and other structural elements can improve the visibility and ranking of a website in search engine results.
Follow-up 3
How does proper HTML structure benefit accessibility?
Proper HTML structure benefits accessibility by providing a logical and organized way to present content to users with disabilities. Screen readers and other assistive technologies rely on the structure of the HTML document to navigate and understand the content. By using semantic HTML elements and following accessibility best practices, developers can ensure that the content is properly labeled and structured, making it easier for users with disabilities to access and understand the information on a web page.
5. What are some of the key differences between HTML4 and HTML5?
HTML4 (1997) and HTML5 (standardized 2014, now the living standard) differ across nearly every dimension. Key differences interviewers focus on:
1. DOCTYPE
- HTML4: ``
- HTML5: ``
2. Semantic elements
HTML4 had no semantic structural elements beyond headings. Layouts used <div>, <div>, etc. HTML5 introduced ,, ,, ,, ,, , `<time>`, `<mark>`,, ``.
3. Multimedia
HTML4 required plugins (Flash, QuickTime) for audio and video. HTML5 introduced ,, and for native browser playback, and for captions.
4. Forms
HTML4 had text, password, checkbox, radio, file, submit, and a few others. HTML5 added email, url, tel, date, time, datetime-local, month, week, number, range, color, search — plus placeholder, required, pattern, autofocus, autocomplete, and built-in constraint validation.
5. Graphics HTML5 introduced `` for JavaScript-driven 2D/WebGL rendering and formalized SVG embedding inline in HTML documents.
6. Storage
HTML4 had only cookies for client-side storage. HTML5 introduced localStorage, sessionStorage, and the platform for IndexedDB.
7. Deprecated elements
Presentational elements from HTML4 — ,, , `<big>`,, <u> (for underlining), <b> used purely for styling — are obsolete in HTML5. Their presentation is handled by CSS.
8. Character encoding
HTML4: . HTML5:.
9. Specification model HTML4 was a fixed W3C recommendation. HTML5 is a living standard maintained by WHATWG; it evolves continuously. There will not be an "HTML6."
10. Application Cache vs. Service Workers HTML5 shipped AppCache for offline support, which was widely criticized and later deprecated. It was replaced by Service Workers, which are now the standard.
Follow-up 1
What new elements were introduced in HTML5?
HTML5 introduced several new elements, including:
``: Represents the header of a document or a section.
``: Represents a section of a page that contains navigation links.
``: Represents a standalone section of a document.
``: Represents a self-contained composition in a document, such as a blog post or a news article.
``: Represents the footer of a document or a section.
``: Represents a section of a page that contains content that is tangentially related to the main content.
``: Represents a self-contained content, such as an image, illustration, diagram, or code snippet, that is referenced in the main content.
: Represents the caption or description of aelement.
These new elements provide a more semantic structure to web pages, making them easier to understand and navigate.
Follow-up 2
How has form handling changed in HTML5?
Form handling in HTML5 has been improved with the introduction of new input types, attributes, and form validation features. Some of the changes include:
New Input Types: HTML5 introduced new input types like
email,url,number,date,time,color, etc., which provide better input validation and user experience.New Attributes: HTML5 introduced new attributes like
placeholder,required,pattern,min,max, etc., which allow developers to specify input constraints and provide better user guidance.Form Validation: HTML5 introduced built-in form validation using the
pattern,required, and other attributes. This allows browsers to validate form inputs without the need for JavaScript.Date and Time Input: HTML5 introduced new input types for handling dates and times, making it easier for users to enter date and time values.
These changes make form handling in HTML5 more powerful, user-friendly, and accessible.
Follow-up 3
What are the multimedia enhancements in HTML5?
HTML5 introduced several multimedia enhancements, including:
Audio and Video Support: HTML5 added native support for embedding audio and video content using the
andelements. This eliminates the need for third-party plugins like Flash.Canvas: HTML5 introduced the `` element, which allows dynamic rendering of graphics and animations using JavaScript. This enables the creation of interactive multimedia content.
WebRTC: HTML5 introduced the Web Real-Time Communication (WebRTC) API, which enables real-time communication between web browsers. This allows for features like video conferencing and peer-to-peer file sharing.
Geolocation: HTML5 introduced the Geolocation API, which allows web applications to access the user's location information. This enables location-based services and applications.
These multimedia enhancements in HTML5 provide developers with more powerful tools for creating rich and interactive multimedia content.
Live mock interview
Mock interview: HTML 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.