Discover essential HTML interview questions for freshers, intermediates, and experienced professionals to prepare and excel in your web development career.
OVERVIEW
HTML is the core of web development, using various tags and elements. These tags and properties can be combined to create visually appealing and engaging web pages. HTML is the foundation for adding styling and website functionality through CSS and JavaScript.
This guide provides a collection of the top 90+ HTML interview questions and answers, covering topics from basic HTML concepts to advanced topics.
Download HTML Interview Questions
Note : We have compiled all HTML Interview Question for you in a template format. Feel free to comment on it. Check it out now!!
This section covers HTML interview questions for freshers, such as basic tags, the structure of an HTML document, and creating links and lists.
HTML stands for Hypertext Markup Language and is used to create web pages. It combines Hypertext, which defines links between web pages, and Markup language, which defines the structure of text documents within tags.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<h2>Learning Hub</h2>
<p>Top 90+ HTML Interview Questions and Answers in 2024 </p>
</body>
</html>
HTML and XHTML are markup languages designed for web page creation and display. HTML offers a more lenient syntax, whereas XHTML follows a stricter syntax that complies with XML rules.
HTML document is built using a combination of these three building blocks:
The !DOCTYPE is an instruction used by web browsers to determine the version of HTML the website is written in. This helps browsers understand how the document should be interpreted, simplifying the rendering process. The !DOCTYPE is neither an element nor a tag. It should be placed at the very top of the document, contain no content, and do not require a closing tag.
HTML tags are the building blocks of any web page, which are keywords that structure web pages in different formats. These tags are paired with opening and closing tags, although some are standalone and do not require closing.
The basic structure of an HTML tag is as follows:
<tagname> Content... </tagname>
HTML attributes provide additional information about elements within an HTML document. Every HTML element can have attributes, which are always defined in the start tag. Attributes use a name/value pair format, where the attribute name defines the property and the value provides specific details. These attributes affect how content is displayed and interacted with on web pages.
Here are the difference between <strong>, and <b> tags and <em> and <i> tags:
<strong> and <b> tags:
<em> and <i> tags:
We can use an HTML tag called <img> to add an image to a web page. This tag tells the browser that you want to display a picture.
Inside the <img> tag, you need to provide the source or location of the image file. You do this by using the src attribute.
Syntax:
<img src="image.jpg" alt="Description of the image">
The alt attribute is used to specify alternate text for an image. This is helpful when the image cannot be displayed and provides alternative information for the image.
In HTML, you can add comments between <!-- ... --> tags. The start tag includes an exclamation mark (!), but the end tag does not.
There are two types of comments in HTML:
<!-- Single-line comment -->
<!--
Multi-line
comment
-->
HTML headings are defined using the <h1> to <h6> tags.
Example:
<h1>Learning Hub</h1>
<h2>Learning Hub</h2>
<h3>Learning Hub</h3>
<h4>Learning Hub</h4>
<h5>Learning Hub</h5>
<h6>Learning Hub</h6>
To create a basic table in HTML:
Example:
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Jim</td>
<td>3</td>
</tr>
<tr>
<td>Jam</td>
<td>2</td>
</tr>
</table>
This structure creates a 2x2 table with headers for Name and Age, followed by two rows of data.
HTML lists are used to organize information into a structured format. They can contain various types of content, such as paragraphs or images. There are three main types of lists:
Example:
<!-- Unordered list -->
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<!-- Ordered list -->
<ol>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
</ol>
<!-- Description list -->
<dl>
<dt>HTML</dt>
<dd>Hypertext Markup Language</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets</dd>
</dl>
In HTML, links are used to connect web pages or HTML documents. To create a link, you can use the anchor tag (<a>) with the href attribute specifying the URL or destination.
<a href="https://www.lambdatest.com/learning-hub/">Learning Hub</a>
The target attribute in the <a> tag specifies where the linked document should open. Some common values are:
HTML elements can be displayed in various ways, including block, inline, inline-block, and none. The display property is used to specify how an element should be rendered on the page.
Here are the primary differences between block elements and inline elements:
Characteristics | Block-level Elements | Inline-level Elements |
---|---|---|
New Line | Starts on a new line. | Does not start on a new line. |
Width | Takes up the full available width. | Takes up the width of its content only. |
Height | Can have a height set. | Height is determined by its content. |
Margins/Padding | Can have margins/padding on all sides. | Can have left/right margins/padding, but not top/bottom. |
Alignment | Can be aligned using text-align and margin properties. | Can be aligned using the vertical-align property. |
Yes, it is possible to change the display behavior of an HTML element using CSS. You can use the display property to change an inline element into a block-level element or vice versa.
/* Change an inline element to block-level */
span {
display: block;
}
/* Change a block-level element to inline */
div {
display: inline;
}
Text alignment in HTML is achieved using CSS. The text-align property is used to horizontally align text within an element.
/* Align text to the left */
p {
text-align: left;
}
/* Align text to the right */
h1 {
text-align: right;
}
/* Align text in the center */
div {
text-align: center;
}
You can use the color property in CSS to change the color of text in HTML.
/* Change text color to blue*/
p {
color:blue;
}
Changing the font color in HTML is the same as changing the text color, which is done using the color property in CSS.
/* Change font color to green */
body {
color: green;
}
To change the background color of an HTML element, you can use the background-color property in CSS.
/* Change body background color to gray */
body {
background-color: gray;
}
/* Change div background color to white*/
div {
background-color: white;
}
To change the font style in HTML, you can use various CSS properties:
Example:
/* Change font family, size, and style */
h1 {
font-family: sans-serif;
font-size: 24px;
font-style: italic;
font-weight: bold;
}
The DOM, or Document Object Model, is a programming interface that represents structured documents such as HTML and XML as a tree of objects. It defines how to access, manipulate, and modify document elements using scripting languages like JavaScript.
The Document Object Model provides a tree-like representation of HTML documents. JavaScript allows for accessing and modifying the DOM, facilitating alterations to the structure or content within an HTML document.
One common issue is the slowness of DOM updates, which occur every time the page loads and can consume substantial time and processing resources. Another common issue is the complexity of working with the DOM, which is particularly challenging for those who lack proficiency in HTML and CSS. This complexity can hinder the effective manipulation of the DOM to achieve desired results.
To create a form in HTML, you can use the <form> element. Inside the <form> element, you can include various form controls like input fields, dropdowns, checkboxes, radio buttons, and more.
Example:
<form action="/submit-form" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="message">Message:</label>
<textarea id="message" name="message" required></textarea>
<button type="submit">Send</button>
</form>
The action attribute in the <form> tag specifies the URL or server-side script where the form data will be submitted.
The method attribute specifies the HTTP method used to submit the form data.
There are three ways to link CSS to an HTML document:
<p style="color: pink; font-weight: bold;">This text is pink and bold.</p>
<!DOCTYPE html>
<html>
<head>
<style>
p {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<p>This text is red and bold.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
Below are the benefits of collapsing white space:
The <div> (division) tag is a block-level element in HTML commonly used to divide a web page into sections or create layout structures. It acts as a container for other HTML elements and can be styled using CSS.
Here's an example of how to use <div> tags to divide a page:
<!DOCTYPE html>
<html>
<head>
<title>Page Layout</title>
<style>
.header, .nav, .content{
padding: 20px;
border: 1px solid black;
}
</style>
</head>
<body>
<div class="header">
<h1>Website Header</h1>
</div>
<div class="nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
<div class="content">
<h2>Content Section</h2>
</div>
</body>
</html>
To add a scroll bar in HTML, you can use CSS to control the overflow behavior of an element. When the content inside an element exceeds its specified height or width, a scroll bar will automatically appear.
The tags used to separate sections of text in HTML are:
Yes, including one CSS file in another is possible, and this process can be repeated multiple times. Additionally, you can import multiple CSS files into the main HTML file or the primary CSS file using the @import keyword.
To add a footer in HTML, you can use a <footer> element or a <div> element with an appropriate class or ID. The footer is placed at the bottom of the web page and can contain various elements like copyright information, navigation links, or other relevant content.
Example of how to add a footer using a <footer> element:
<!DOCTYPE html>
<html>
<head>
<title>Website with Footer</title>
<style>
footer {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
</style>
</head>
<body>
<!-- Your website content goes here -->
<footer>
<p>© 2024 Your Website. All rights reserved.</p>
<nav>
<ul>
<li><a href="#">Privacy Policy</a></li>
<li><a href="#">Terms of Use</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
</footer>
</body>
</html>
Download HTML Interview Questions
Note : We have compiled all HTML Interview Question for you in a template format. Feel free to comment on it. Check it out now!!
Here are the HTML interview questions for intermediate professionals that delve into more complex topics like semantic HTML, forms, multimedia elements, and the differences between block-level and inline elements.
XML parsing is the conversion of an XML document into a format that is understandable by computers. It involves creating a tree or graph structure for computational processing.
Below are the various kinds of nodes present in the DOM:
To add an element to the Document Object Model, you must first create the element. After creation, you can append it to the desired location within the DOM. To remove an element from the DOM, you first locate the element you want to remove and then execute its remove() method.
The best approach for dynamically creating a new HTML page is to use the document.createElement() method. This method enables you to generate any desired element, including an entire HTML page. Once the element is created, it can be attached to the current document using the appendChild() method.
Semantic HTML refers to coding practices that use HTML tags to convey the meaning of content on a web page rather than focusing solely on its visual presentation. This approach makes it easier for search engines and other software to interpret and process the page effectively.
To create a form in HTML, use the <form> element. Inside this element, add various input fields using different HTML elements such as <input>, <textarea>, <select>, and more.
Example of a basic form with a text input field and a submit button:
<form>
Name: <input type="text"><br>
<input type="submit" value="Submit">
</form>
The <div> and <span> tags are both HTML elements used for grouping and structuring content, but they have different objectives.
<div> is a block-level element, which starts on a new line and takes up the full width available by default. It is commonly used for creating larger groupings or sections of content, such as headers, footers, sidebars, and layout containers.
<span>, on the other hand, is an inline-level element, which means it does not start on a new line and only takes up as much width as its content requires. It is used for styling or grouping smaller pieces of text within a line, such as highlighting a word or phrase or applying specific formatting to a part of a sentence.
Below are some differences between <div> and <span>:
Both classes and IDs are used in HTML to identify and target elements for styling and manipulation with CSS and JavaScript. However, they have some differences:
Classes:
IDs:
Here are some differences between classes and IDs:
Aspects | Classes | IDs |
---|---|---|
Usage frequency | Can be used multiple times | Should be unique per page |
Specificity | Lower specificity | Higher specificity |
Purpose | Grouping similar elements | Identifying unique elements |
Multiple values | Can have multiple classes | Can only have one ID |
Performance | Slightly slower | Slightly faster |
Best for | Reusable styles | Unique styles or JavaScript hooks |
To add a video to an HTML document, use the <video> element. It allows for the inclusion of one or more video sources using the <source> tag. It supports MP4, WebM, and Ogg formats across all modern browsers except for Safari, which does not support the Ogg video format.
Syntax:
<video>
<source src=”file_name” type=”video_file_type”>
</video>
Let’s understand this with an example:
<!DOCTYPE html>
<html>
<body style="text-align: center">
<h2>How to add video in HTML</h2>
<video width="600px"
height="500px"
controls="controls">
<source src= "https://www.lambdatest.com/resources/videos/lambdatest-smart-ui-testing.mp4" type="video/mp4" />
</video>
</body>
</html>
To embed audio in an HTML document, use the <audio> element. Before HTML5, audio could not be added directly to web pages during the Internet Explorer era, so web plugins like Flash were used to play audio. With the release of HTML5, this became possible.
The <audio> tag in HTML5 supports three audio formats—MP3, WAV, and Ogg—across major browsers like Chrome, Firefox, Safari, Opera, and Edge. However, the Safari browser does not support the Ogg audio format.
Syntax:
<video>
<source src=”file_name” type=”audio_file_type”>
</video>
Let’s understand this with an example:
<!DOCTYPE html>
<html>
<body>
<h2>Listen to Audio</h2>
<audio controls>
<source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>
Scalable Vector Graphics (SVG) is an XML-based vector image format for creating two-dimensional graphics. SVG images can be embedded directly into HTML documents using the <svg> element.
There are three methods to create responsive images in HTML:
A nested web page refers to embedding one web page's content within another from a different domain. This technique allows you to display external content directly within your web page.
There are two primary methods to achieve this in HTML:
Syntax:
<iframe src=”URL”></iframe>
Here's an example:
<iframe src="https://www.lambdatest.com/learning-hub/"
height="400px" width="900px">
</iframe>
Syntax:
<embed src=”URL” type=”text/html” />
Here's an example:
<embed src="https://www.lambdatest.com/learning-hub/"
type="text/html" />
The <head> element in an HTML document contains metadata, scripts, and links that are not rendered on the page but provide important information about the document.
Here are some common tags that can be used inside the <head> tag:
The HTML layout refers to how a website's content is arranged and structured, making it easy to navigate.
There are several HTML layout elements, including:
Semantic elements in HTML are named to describe content in a way that is both human-readable and machine-readable.
Elements like <main>, <header>, <footer>, and <section> are examples of semantic elements because they precisely describe the primary purpose and type of content contained within these tags.
HTML entities are special characters or symbols represented by a specific code or sequence, usually starting with an ampersand (&) and ending with a semicolon (;). They display characters that cannot be easily typed or are reserved for specific purposes in HTML.
Some common HTML entities:
<
represents the less-than symbol (<) used for opening tags. >
represents the greater-than symbol (>) used for closing tags. &
represents the ampersand symbol (&) used for HTML entities. "
represents the double quote symbol ("). '
represents the single quote symbol (').
represents a non-breaking space. ©
represents the copyright symbol (©). ®
represents the registered trademark symbol (®). A
represents the character code for "A" (use &#code; for any character code). HTML uses certain characters as part of its syntax, giving them special significance. To display these characters as regular text or symbols without triggering their special functions, we use HTML entities. These entities allow us to safely include reserved characters and symbols in our web pages.
Some common special symbols and their corresponding HTML entities:
HTML encoding refers to converting special characters in HTML into their respective character entities. For example, consider the double quotation mark (").
In HTML, double quotes are used to define attribute values in tags. If you want to display a double quotation mark as part of your visible text, you must encode it. The HTML entity for a double quote is "
.
HTML encoding is essential for preserving the intended appearance of your content while maintaining valid HTML syntax. It's particularly important when displaying text that includes characters with special HTML meanings, such as direct quotes, code samples, or technical documentation.
There are three main ways to add CSS styling to an HTML document:
<h1 style="color: blue; font-size: 24px;">Learning Hub</h1>
<head>
<style>
h1 {
color: blue;
font-size: 24px;
}
</style>
</head>
<head>
<link rel="stylesheet" href="styles.css">
</head>
In the styles.css file:
h1 {
color: blue;
font-size: 24px;
}
Using an external CSS file is generally considered the best practice as it separates the HTML from the CSS, making the code more maintainable and reusable across multiple HTML pages.
There are three main ways to add JavaScript to an HTML web page:
JavaScript inside <head> tag
This method places JavaScript code within <script> tags in the <head> of your HTML document. It's useful for scripts that need to load before the page content.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript in Head</title>
<script>
function changeContent() {
document.getElementById("demo").innerHTML = "Top 90+ HTML Interview Questions and Answers in 2024";
}
</script>
</head>
<body>
<h1>JavaScript in Head Example</h1>
<p id="demo">Learning Hub</p>
<button onclick="changeContent()">Change Content</button>
</body>
</html>
JavaScript inside <body> tag
This method places the <script> tags just before the closing </body> tag. It's beneficial for scripts interacting with page elements, ensuring the DOM is fully loaded before the script runs.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript in Body</title>
</head>
<body>
<h1>JavaScript in Body Example</h1>
<p id="demo">Learning Hub</p>
<button id="changeButton">Change Content</button>
<script>
document.getElementById("changeButton").addEventListener("click", function() {
document.getElementById("demo").innerHTML = "Top 90+ HTML Interview Questions and Answers in 2024";
});
</script>
</body>
</html>
External JavaScript
This method involves creating a separate .js file and linking it to your HTML document. It's ideal for larger scripts and promotes better organization and reusability.
HTML file (index.html):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>External JavaScript</title>
<script src="script.js" defer></script>
</head>
<body>
<h1>External JavaScript Example</h1>
<p id="demo">Learning Hub</p>
<button id="changeButton">Change Content</button>
</body>
</html>
JavaScript File (script.js):
document.addEventListener('DOMContentLoaded', function() {
document.getElementById("changeButton").addEventListener("click", function() {
document.getElementById("demo").innerHTML = "Top 90+ HTML Interview Questions and Answers in 2024";
});
});
Forms in HTML are used to collect user input data and send it to a server for processing. They allow users to enter information such as names, email addresses, passwords, comments, and other data types.
The <form> element is used to create a form, and it can contain various form control elements such as:
Example of a simple form:
<form action="/submit-form" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="phone">Phone Number:</label>
<input type="tel" id="phone" name="phone" pattern="[0-9]{10}" required>
<button type="submit">Submit</button>
</form>
In HTML tables, cellpadding and cell spacing are properties that control the appearance of table cells, but they have different objectives.
Parameters | Cellpadding | Cellspacing |
---|---|---|
Purpose | Defines the space between a table cell's border and its content | Defines the space between adjacent cells |
Creation | Created using the HTML <table> tag with cellpadding attribute | Created using the HTML <table> tag with cellspacing attribute |
Scope | Applies to a single cell | Applies to multiple cells simultaneously |
Default Value | 1 | 2 |
Effectiveness | More effective and widely used | Comparatively less effective than cellpadding |
Applets are small applications or programs written in the Java programming language that can be embedded into a web page. They were designed to run within a web browser and provide interactive and dynamic content to the user.
Applets were primarily used in the early days of the Internet to create interactive graphics, games, and other multimedia applications that could run within a web browser. They were embedded into a web page using the <applet> HTML tag, which specified the location of the Java applet code.
However, due to security concerns and the widespread adoption of alternative technologies like JavaScript, Flash (now obsolete), and HTML5, applets have fallen out of favor. They are no longer widely used in modern web development.
When the border attribute is set to zero, default cell borders and thickness are applied. However, adding a rule attribute to a tag replaces the border attribute, showing a default one-pixel border instead.
HTML APIs, known as Application Programming Interfaces, include definitions and protocols designed specifically for HTML. Tools associated with HTML APIs are utilized for direct configuration within HTML code.
Here are some common HTML5 APIs and their uses:
Optimize the load time of an HTML page by scaling down image and media sizes, compressing CSS and JavaScript files, merging files to decrease HTTP requests, and using lazy loading for non-urgent scripts and images.
To create a navigation bar using HTML and CSS, follow these steps:
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
nav {
background-color: #333;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
overflow: hidden;
}
nav li {
float: left;
}
nav li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
nav li a:hover {
background-color: #111;
}
The following are the differences between <blockquote> and <q> tags:
Parameters | <blockquote> | <q> |
---|---|---|
Purpose | Long quotations. | Short, inline quotations. |
Display | Block-level element. | Inline element. |
Default styling | Indented on both sides. | Adds quotation marks. |
Length | Multiple lines. | Usually, within a sentence. |
Line breaks | Preserves line breaks. | Do not add line breaks. |
Citation | Can use cite attributes. | Can use cite attributes. |
Nesting | Can contain other block elements. | Cannot contain block elements. |
To structure a multi-page website using HTML, create distinct HTML files for each page with consistent naming conventions. Use <a> tags to link these pages and ensure a coherent layout by organizing content semantically with HTML5 elements.
When using headings in HTML, it's important to follow best practices to ensure proper structure, accessibility, and semantics.
HTML provides the <figure> and <figcaption> elements for associating images, diagrams, or illustrations with descriptive captions. The <figure> element wraps the content, while the <figcaption> element links the content with its caption.
The method attribute specifies how form data should be submitted to the server in HTML forms. The two most common values for this attribute are GET and POST, representing different data transmission methods.
Here's the difference between the GET and POST methods in form submission:
Aspects | GET | POST |
---|---|---|
Data Visibility | Data visible in URL. | Data is not visible in the URL. |
Data Length | Limited by URL length (typically 2048 characters). | No practical length limit. |
Security | Less secure, not for sensitive data. | More secure and suitable for sensitive data. |
Caching | Can be cached. | Not typically cached. |
Bookmarking | Can be bookmarked with parameters. | Cannot be bookmarked with full data. |
Use Case | Retrieving data and search queries. | Submitting data and file uploads. |
Idempotency | Idempotent (repeated requests have the same effect). | Not idempotent (repeated requests may have different effects). |
Encoding | URL encoded. | Can use various encodings (e.g., multipart/form-data). |
Performance | Slightly faster for small amounts of data. | Better for large amounts of data. |
WebSockets are a communication protocol that facilitates full-duplex communication channels over a single TCP connection. They enable real-time, event-driven connections between clients and servers.
Unlike traditional HTTP, which operates on a request-response model, WebSockets support bi-directional communication. This allows clients and servers to send data to each other asynchronously, eliminating the need for continuous polling.
WebSockets are commonly used in scenarios where real-time, bidirectional communication is required, such as:
Subscribe to the LambdaTest YouTube Channel and get detailed tutorials around automation testing, Selenium, and more.
Following are the HTML interview questions for experienced professionals covering advanced topics, including HTML5 APIs, accessibility standards, and performance optimization.
Void elements are a special category of HTML elements that only have start tags and do not contain any content within them. Void elements in HTML do not have closing tags and cannot contain any content; they can only include attributes. Adding a slash before the end of the start tag is optional.
Some examples of void elements in HTML include:
A box element in HTML can be created by a <div> tag with CSS styling.
Following is the most basic example:
<div style="width: 300px; height: 200px; border: 1px solid black;">
A rectangular box
</div>
This creates a simple rectangular box with a width of 200 pixels, a height of 100 pixels, and a thin black border.
Container tags and empty tags are different types of tags used in HTML. Here are the differences between them:
Aspects | Container Tags | Empty Tags |
---|---|---|
Structure | Have opening and closing tags. | Single self-closing tag. |
Content | Can contain other elements or text. | Cannot contain content. |
Example | <div>...</div>, <p>...</p> | <br>, <img> |
Closing | Require a separate closing tag. | Close within the same tag (e.g., <img />). |
Purpose | Used to wrap and structure content. | Used for singular elements or actions. |
Nesting | Can be nested within other elements. | Cannot be nested. |
Common Uses | Paragraphs, divisions, lists. | Line breaks, images, input fields. |
HTML uses physical and logical tags to improve users' readability and understanding of text, although these tags have distinct functions, as their names suggest.
Tags | Uses |
---|---|
<header> | Defines a header for a document or section |
<nav> | Defines navigation links |
<article> | Defines independent, self-contained content |
<section> | Defines a section in a document |
<side> | Defines content aside from the page content |
<footer> | Defines a footer for a document or section |
<strong> | Indicates strong importance |
<em> | Emphasizes text |
<cite> | Defines the title of a work |
<time> | Defines a date/time |
Tags | Uses |
---|---|
<b> | Bold text |
<i> | Italic text |
<u> | Underlined text |
<font> | Specifies font face, size, and color (deprecated) |
<center> | Centers text (deprecated) |
<big> | Increases text size (deprecated) |
<small> | Decreases text size |
MathML (Mathematics Markup Language) has been part of HTML5 since its third version, launched in 2015, allowing web browsers to display mathematical equations and expressions like other HTML elements. The first version of MathML was initially introduced in 1998, followed by subsequent updates leading to the current version.
MathML provides an accessible means to visually represent complex mathematical formulas and equations. Its integration into HTML5 mandates that all MathML tags be nested within <math> and </math< tags. Designed for machine-to-machine communication, MathML is primarily utilized by specialized authoring tools, including equation editors, and holds relevance across various applications.
Note: It's important to note that MathML is not a calculator or a programming language. It cannot solve equations but rather displays them in a standardized format.
To use MathML in HTML5, the structure of content is like this:
<!DOCTYPE html>
<html>
<head>
<title>HTML5 MathML Example</title>
</head>
<body>
<math>
<!-- MathML content goes here -->
</math>
</body>
</html>
Some of the most common MathML tags include:
MathML Tags | Uses |
---|---|
<mrow> | Creates a row containing mathematical expressions. |
<mi> | Represents identifiers (variables, function names). |
<mn> | Displays numeric characters. |
<mo> | Shows mathematical operators. |
<mfrac> | Creates fractions. |
<msqrt> and <mroot> | Display square roots and nth roots. |
<msub> <msub> and <msub> | Handle subscripts and superscripts. |
<mtable> <mtr> and <mtd> | Create tables or matrices. |
A manifest is a text file that directs the browser to cache particular files or web pages, allowing them to remain accessible even offline. The <html> tag in HTML5 includes a manifest attribute to specify which web pages should be cached. When a web page has this attribute or is listed in the manifest file, it will be stored for offline access upon user visits.
Manifest files, which use the .appcache extension, always start with CACHE MANIFEST. These files are divided into three sections: CACHE, NETWORK, and FALLBACK.
For example:
<!DOCTYPE html>
<html manifest="offline.appcache">
<body>
<h1>LambdaTest Learning Hub</h1>
</body>
</html>
This file, when listed in the CACHE section of offline.appcache, will be available offline.
For example:
<!DOCTYPE html>
<html>
<body>
<h1>LambdaTest Learning Hub</h1>
<p>Only available in online mode!</p>
</body>
</html>
When listed in the NETWORK section, this file will only be accessible online.
Online version (offline.html):
<!DOCTYPE html>
<html>
<body>
<h1>LambdaTest Learning Hub</h1>
<p>Working in online mode</p>
</body>
</html>
Offline fallback (fallback.html):
<!DOCTYPE html>
<html>
<body>
<h1>LambdaTest Learning Hub</h1>
<p>You are working in offline mode.</p>
</body>
</html>
A sample manifest file (offline.appcache) might look like this:
CACHE MANIFEST
CACHE:
cache.html
NETWORK:
network.html
FALLBACK:
offline.html fallback.html
To implement this, create an index.html file linking all the above files:
<!DOCTYPE html>
<html manifest="offline.appcache">
<body>
<h1>LambdaTest Learning Hub</h1>
<a href="cache.html">Cached File</a>
<a href="network.html">Network File</a>
<a href="offline.html">Fallback File</a>
</body>
</html>
It's common in web design to open hyperlinks in new windows or tabs to enhance user experience, allowing them to view additional content without navigating away from the current page.
In HTML, this functionality is easily implemented using the target attribute of the anchor (<a>) tag with "_blank" as the value, directing the browser to open the linked document in a new tab or window.
Syntax:
<a href="URL" target="_blank">Link Text</a>
Web Workers are JavaScript-based multithreaded objects designed to run scripts in the background, ensuring that application or web page performance remains unaffected.
Web Workers allow for the execution of lengthy scripts without interruption from user interaction scripts, ensuring that CPU-intensive operations can be performed without impacting the responsiveness of the web page. They are commonly used for handling substantial computational tasks.
There are two main types of Web Workers:
To handle events in HTML, add a function to an HTML tag that executes JavaScript when any associated event is triggered. HTML provides multiple event attributes, including keyboard events, mouse events, and form events, each serving specific roles.
The syntax for handling events in HTML:
<element eventAttribute="myScript">
HTML offers various event attributes, categorized into different types such as keyboard events, mouse events, and form events. Let's explore some common form events:
<element onblur="myScript">
<element onchange="myScript">
<element onfocus="myScript">
An event handler is a function that triggers automatically in response to an event, while an event listener is an object that receives notifications when the event occurs. The listener can then respond by invoking an event handler.
The onblur() method specifies actions to take when an element loses focus. This frequently validates input fields before users move to the next field.
It's generally best practice to avoid using inline functions for event handlers in web development. This is because inline functions can generate anonymous functions that are difficult to debug and may lead to unexpected closures. Instead, external functions are preferred as they are easier to debug and manage.
When an event handler returns false, it stops the event from progressing further. This behavior is frequently used to prevent actions such as form submissions.
In HTML, the datetime attribute defines the date and time connected with the content, making it machine-readable. It is used with elements like <time> to present structured time-related data.
Syntax:
<element datetime="YYYY-MM-DDThh:mm:ssTZD">
This attribute uses a single value string that encodes date and time information. The components of this string are:
The datetime attribute is particularly useful with these HTML elements:
The <a> tag in HTML defines a hyperlink, allowing navigation from one page to another. Its primary attribute, href, specifies the destination URL. Clicking the link directs the user to this specified location.
Syntax:
<a href="link">Link Name</a>
Common usage examples:
<a href="https://www.lambdatest.com/learning-hub/">Visit Learning Hub</a>
<a href="https://www.lambdatest.com/learning-hub/" target="_blank">Visit Learning Hub</a>
<a href="mailto:example@xyz.com">Send email</a>
<a href="tel:+910000000">+910000000</a>
<a href="#sectionA">Go to Section A</a>
Server-sent events (SSE) is a standard protocol in HTML5 that allows servers to push data to clients over a persistent connection. This feature enables real-time updates and communication between the server and the client without the client having to poll the server for new data constantly.
With server-sent events, the server can initiate and send data to the client whenever new information becomes available. This makes it suitable for applications that require real-time updates, such as live news feeds, stock tickers, chat applications, or live scoring updates.
HTML5 introduced several input types for forms, allowing for better data validation and user experience. Below are some of the input types:
Note : Test your HTML forms across 3000+ real desktop browsers. Try LambdaTest Now!
HTML geolocation is used to retrieve a user's geographical coordinates, subject to user consent due to privacy considerations. It allows web applications to request and utilize location data, providing a more contextual and tailored experience. This feature finds extensive use in various scenarios, such as:
The geolocation API leverages JavaScript to communicate location data in latitude and longitude coordinates to the web application's backend server.
Syntax:
var loc = navigator.geolocation;
Here's an example of how to use the geolocation API in HTML5:
<!DOCTYPE html>
<html>
<head>
<title>Geolocation Example</title>
</head>
<body>
<h1>Geolocation Distance Tracker</h1>
<button onclick="startTracking()">Start Tracking</button>
<button onclick="stopTracking()">Stop Tracking</button>
<div id="status"></div>
<div id="distance"></div>
<script>
let watchId, startPos;
function startTracking() {
if (navigator.geolocation) {
document.getElementById('status').textContent = 'Tracking started...';
watchId = navigator.geolocation.watchPosition(updatePosition, handleError);
} else {
document.getElementById('status').textContent = 'Geolocation not supported';
}
}
function stopTracking() {
if (watchId) {
navigator.geolocation.clearWatch(watchId);
document.getElementById('status').textContent = 'Tracking stopped';
}
}
function updatePosition(position) {
if (!startPos) {
startPos = position.coords;
return;
}
let distance = calculateDistance(startPos, position.coords);
document.getElementById('distance').textContent = `Distance moved: ${distance.toFixed(2)} meters`;
}
function calculateDistance(start, end) {
const R = 6371e3; // Earth's radius in meters
const φ1 = start.latitude * Math.PI/180;
const φ2 = end.latitude * Math.PI/180;
const Δφ = (end.latitude - start.latitude) * Math.PI/180;
const Δλ = (end.longitude - start.longitude) * Math.PI/180;
const a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
Math.cos(φ1) * Math.cos(φ2) *
Math.sin(Δλ/2) * Math.sin(Δλ/2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return R * c;
}
function handleError(error) {
document.getElementById('status').textContent = `Error: ${error.message}`;
}
</script>
</body>
</html>
The provided code illustrates the use of the HTML5 geolocation API to track a user's movement. It uses the watchPosition() method to continuously monitor location changes. When tracking starts, it records the initial position and then calculates the distance moved from this starting point using the Haversine formula. The script includes functions to start and stop tracking, update the position, calculate distance, and handle errors.
Web components are modular pieces of code that package the essential structure of HTML elements, along with CSS and JavaScript, allowing them to be utilized universally across websites and web applications. Web Components consist of four main building blocks:
Web components offer several benefits, including:
To add Scalable Vector Graphics to your web page, you can embed the SVG code directly into your HTML document or include it as an external file.
Embedding SVG code directly:
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>
In this example, the SVG code is written directly inside the <svg> element, which defines the dimensions and the vector graphics content (in this case, a circle).
Including an external SVG file:
<img src="example.svg" alt="Example SVG">
You can include an external SVG file in your HTML document using the <img> tag, just like a raster image like PNG or JPEG. The browser will render the SVG file as an image.
Other than these HTML interview questions and answers, you can also refer to the HTML Cheat Sheet to get started.
To conclude, developers must be well-prepared for various HTML interview questions during recruitment. Interviews involve multiple stages, and the questions and answers provided in this article are designed to address each of these stages, with a particular focus on the technical interview.
This comprehensive list serves as a valuable resource for both interviewers and candidates. For interviewers, it offers diverse questions to assess a candidate's HTML proficiency across various skill levels. For candidates, it provides an opportunity to review and reinforce their knowledge, ensuring they're ready to demonstrate their expertise.
Download HTML Interview Questions
Note : We have compiled all HTML Interview Question for you in a template format. Feel free to comment on it. Check it out now!!
Did you find this page helpful?
Try LambdaTest Now !!
Get 100 minutes of automation test minutes FREE!!