HTML - Interview
HTML - Interview
HTML stands for Hypertext Markup Language, the language of the Internet. It is the standard
text formatting language used for creating and displaying pages on the Internet.
HTML documents comprise the elements and the tags that format it for proper page display.
16. How do you create links to different sections within the same HTML web page?
We use the <a> tag and referencing through the # symbol to create several links to different
sections within the same web page.
19. What would happen without text between the HTML tags?
There would be nothing to format if there is no text present between the tags. Therefore, nothing
will appear on the screen.
Some tags, such as those without a closing tag like the <img> tag, do not require any text
between them.
20. What is the alt attribute in HTML?
The alt attribute displays text in place of an image whenever the image cannot be loaded due to
technical issues.
<img src="tulip.jpeg" alt="Tulip Garden" />
● Internal Style Sheet: It is used when a single HTML document has a unique style, and
several elements must be styled to follow the format. Internal styles sheet is added in the
head section of an HTML page by using the <style> tag:
23. How do you add JavaScript to an HTML webpage?
JavaScript is used to make HTML web pages more interactive and user-friendly. It is a scripting
language that allows you to interact with some aspects of the page based on user input. As with
CSS, there are three significant ways of including JavaScript:
JS file also be connected in head tag.
● Inline:
You can add JavaScript to your HTML elements directly whenever a certain event occurs. We
can add the JavaScript code using attributes of the HTML tags that support it. Here is an example
that shows an alert with a message when the user clicks on it:
● Script block:
You can define a script block anywhere on the HTML code, which will get executed as soon as
the browser reaches that part of the document. This is why script blocks are usually added at the
bottom of HTML documents.
● External JavaScript file:
You can also import the JavaScript code from a separate file and keep your HTML code clutter-
free. This is especially useful if a large amount of scripting is added to an HTML webpage.
25. What is the difference between the ‘id' and ‘class' attributes of HTML elements?
The ‘id' attribute defines a unique identifier for an HTML element, while the ‘class' attribute
defines a class for a group of elements. An ‘id' can only be used once on a page, while a ‘class'
can be used multiple times.
33. What are the different types of form input fields in HTML?
Several form input fields in HTML include text fields, checkboxes, radio buttons, select menus,
and text areas. Each input field type is used to collect different types of data from users.
34. What is the role of the action attribute in HTML forms?
The action attribute is used to specify the URL of the script or program that will process the data
submitted by the form. When the user clicks the submit button, the form data is sent to the
specified URL for processing.
37. What is the difference between “display: none” and “visibility: hidden” when used as
attributes to the HTML element?
The main difference between “display: none” and “visibility: hidden” is that the former removes
the element from the document flow, while the latter simply hides it. Elements with “display:
none” are not visible and do not take up any space on the page, while elements with “visibility:
hidden” are not visible but still take up space.
38. In how many ways can we specify the CSS styles for the HTML element?
CSS styles can be specified in several ways, including inline, internal, and external
stylesheets. Inline styles are applied directly to the HTML element using the style attribute.
Internal styles are defined within the <head> section of the HTML document using the <style>
tag. External stylesheets are defined in a separate CSS file and linked to the HTML document
using the <link> tag.
39. What is the difference between link tag <link> and anchor tag <a>?
The <link> tag links external resources, such as CSS stylesheets, to an HTML document. The
<a> tag creates links to other pages or resources within the same document.
40. When to use scripts in the head and when to use scripts in the body?
Scripts can be placed in the <head> section of the HTML document or in the <body> section.
Scripts that must be executed before the page is displayed, such as scripts that define variables or
functions, should be placed in the <head> section. Scripts that must be executed after the page is
displayed, such as scripts that manipulate the DOM, should be placed in the <body> section.
42. What are some advantages of HTML5 over its previous versions?
HTML5 includes several new features and improvements over previous versions, including
better multimedia support, semantic elements, and mobile device support. It also includes new
APIs for working with web applications, such as the Geolocation API and the Canvas API.
43.