Skip to content
Related Articles

Related Articles

Improve Article

HTML Interview Questions Set – 1

  • Last Updated : 15 Jul, 2021
Geek Week

1. What is HTML?

HTML stands for HyperText Markup Language. It is used to design web pages using markup language. HTML is the combination of Hypertext and Markup language. Hypertext defines the link between the web pages. Markup language is used to define the text document within tag which defines the structure of web pages. HTML is used to structure the website and therefore used for Web Development.

2. Difference between HTML and XHTML.

KeywordHTMLXHTML
Full FormHypertext Markup Language.Extensible Hypertext Markup Language
Filename extension.html, .htm.xhtml, .xht, .xml
Developed byTim Berners-LeeW3C i.e World Wide Web Consortium
Extended fromSGMLXML and HTML
Release yearDeveloped in 1991Released in 2000

3.What are the various markup languages, and what are the differences between them?

  • HTML — Hypertext Markup Language
  • KML — Key whole Markup Language
  • MathML — Mathematical Markup Language
  • SGML — Standard Generalized Markup Language
  • XHTML — eXtensible Hypertext Markup Language
  • XML — eXtensible Markup Language

 



4. What is the difference between HTML  and HTML 5?

HTML

HTML5

It didn’t support audio and video without the use of flash player support.It supports audio and video controls with the use of <audio> and <video> tags.
It uses cookies to store temporary data.It uses SQL databases and application cache to store offline data.
Does not allow JavaScript to run in browser.Allows JavaScript to run in background. This is possible due to JS Web worker API in HTML5.
Vector graphics is possible in HTML with the help of various technologies such as VML, Silver-light, Flash, etc.Vector graphics is additionally an integral a part of HTML5 like SVG and canvas.
It does not allow drag and drop effects.It allows drag and drop effects.
Not possible to draw shapes like circle, rectangle, triangle etc.HTML5 allows to draw shapes like circle, rectangle, triangle etc.
It works with all old browsers.It supported by all new browser like Firefox, Mozilla, Chrome, Safari, etc.
Older version of HTML are less mobile-friendly.HTML5 language is more mobile-friendly.
Doctype declaration is too long and complicated.Doctype declaration is quite simple and easy.
Elements like nav, header were not present.New element for web structure like nav, header, footer etc.
Character encoding is long and complicated.Character encoding is simple and easy.
It is almost impossible to get true GeoLocation of user with the help of browser.One can track the GeoLocation of a user easily by using JS GeoLocation API.
It can not handle inaccurate syntax.It is capable of handling inaccurate syntax.
Attributes like charset, async and ping are absent in HTML.Attributes of charset, async and ping are a part of HTML 5.

5. What is the current version of HTML?

HTML 5 is the fifth and current version of HTML.

6. What is !DOCTYPE?

A doctype or document type declaration is an instruction that tells the web browser about the markup language in which the current page is written. The doctype is not an element or tag, it lets the browser know about the version of or standard of HTML or any other markup language that is being used in the document.
The DOCTYPE for HTML5 is case-insensitive and can be written as shown below:

<!DOCTYPE html>

 



7. What are elements and tags, and add the differences between both?

  • HTML Tags: Tags are the starting and ending parts of an HTML element. They begin with < symbol and end with > symbol. Whatever written inside < and > are called tags.

    Example:

    <b> </b>  
  • HTML elements: Elements enclose the contents in between the tags. They consist of some kind of structure or expression. It generally consists of a start tag, content and an end tag.

    Example:

    <b>This is the content.</b>
HTML TagHTML Element
Either opening or closing , used to mark the start or end of an elementCollection of start tag , end tag and its attributes
Used to hold the HTML elementHolds the content
Starts with < and ends with >Whatever written within an HTML tag are HTML elements

8. State the various heading tags, do they hold any importance?

There are six levels of headings defined by HTML. These six heading elements are H1, H2, H3, H4, H5, and H6; with H1 being the highest level and H6 the least.

Importance of Heading :

  1. Search Engines use headings for indexing the structure and content of the webpage.
  2. Headings are used for highlighting important topics.
  3. They provide valuable information and tell us about the structure of the document.

9. How to redirect to a particular section of a page using HTML?

One can use the anchor tag to redirect to a particular section on the same page. You need to add “id attribute” to the section that you want to show and use the same id in href attribute with “#” in the anchor tag. So that On click a particular link, you will be redirected to the section that has the same id mention in the anchor tag.



Syntax:

// Anchor tag
<a href="#home_section">home</a>

<section id="home_section">Information About Page</section>

Example: When user click on “Contact Us” link, he will be redirected to “Contact Us section” on the same page.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        div {
            width: 100%;
            height: 400px;
            border: 1px solid black;
        }
    </style>
</head>
  
<body>
    <h2>Welcome to GeeksforGeeks</h2>
    <p>This is the example of
        <i>Redirect to a particular section 
            using HTML on same page</i>
    </p>
  
    <a href="#contactUs"> Contact Us </a>
    <br/></br>
    <div>
        <h2>Home section</h2>
        </h>
    </div>
    <div>
        <h2>About Us section</h2>
    </div>
  
    <div id="contactUs">
        <h2>Contact Us section </h2>
    </div>
    <div>
        <h2>Team Section</h2>
    </div>
</body>
  
</html>

Output:

10. What are attributes ?

An attribute is used to provide extra or additional information about an element.

  • All HTML elements can have attributes. Attributes provide additional information about an element.
  • It takes two parameters : name and value. These define the properties of the element and are placed inside the opening tag of the element. The name parameter takes the name of the property we would like to assign to the element and the value takes the properties value or extent of the property names that can be aligned over the element.
  • Every name has some value that must be written within quotes.

Syntax:

<element attribute_name="attribute_value">

11. Are <b> and <strong> tag same? If not, then why?

  • HTML strong tag: The strong tag is one of the element of HTML used in formatting HTML texts. It is used to show importance of the text by making it bold or highlighting it semantically.

     



    Syntax:

    <strong> Contents... </strong>
  • HTML bold tag: The bold tag or <b> is also one of the formatting elements of HTML. The text written under <b> tag makes the text bold presentationally to draw attention.

    Syntax:

    <b> Contents... </b>

The main difference between these two tag is that the strong tag semantically emphasizes on the important word or section of words while the bold tag is just offset text conventionally styled in bold.

12. What is the difference between <em> and <i> tag?

  • <i> tag: It is one of the element of HTML which is used in formatting HTML texts. It is used to define a text in technical term, alternative mood or voice, a thought, etc.

    Syntax:

    <i> Content... </i>
  • <em> tag: It is also one of the element of HTML used in formatting texts. It is used to define emphasized text or statements.

    Syntax:

    <em> Content... </em>

    By default, the visual result is the same but the main difference between these two tags is that the <em> tag semantically emphasizes the important word or section of words while <i> tag is just offset text conventionally styled in italic to show alternative mood or voice.



    13. How are comments added in HTML?

    The comment tag (<!– Comment –>) is used to insert comments in the HTML code.

    Types of HTML Comments: There are three types of comments in HTML which are:

    • Single-line comment
       <!--This is single line comment -->
    • Multi-lines comment
      <!-- This is
      multi-line
      comment -->
    • Using <comment> tag
      <comment>This is multi-line
          comment
      </comment>

    14. What are the different formats in which colors in HTML can be declared?

    Color of an element can be defined in the following ways:

    • Built-In Color
    • RGB Format
    • RGBA Format
    • Hexadecimal Notation
    • HSL
    • HSLA

    Built-In Color: These are a set of predefined colors which are used by its name. For example: red, blue, green etc.
    Syntax:

    h1 {
        color: color-name;
    }

    RGB Format: The RGB(Red, Green, Blue) format is used to define the color of an HTML element by specifying the R, G, B values range between 0 and 255. For example: RGB value of Red color is (255, 0, 0), Green color is (0, 255, 0), Blue color is (0, 0, 255) etc.
    Syntax:

    h1 {
        color: rgb(R, G, B);
    }

    RGBA Format: The RGBA format is similar to the RGB, but the difference is RGBA contains A (Alpha) which specify the transparency of elements. The value of alpha lies between 0.0 to 1.0 where 0.0. represents fully transparent and 1.0 represents not transparent.
    Syntax:

    h1 {
        color:rgba(R, G, B, A);
    }

    Hexadecimal Notation: The hexadecimal notation begins with # symbol followed by 6 characters each range from 0 to F. For example: Red #FF0000, Green #00FF00, Blue #0000FF etc.
    Syntax:

    h1 {
        color:#(0-F)(0-F)(0-F)(0-F)(0-F)(0-F);
    }

    HSL: HSL stands for Hue, Saturation, and Lightness respectively. This format uses the cylindrical coordinate system.



    • Hue: Hue is the degree of the color wheel. Its value lies between 0 to 360 where 0 represents red, 120 represents green and 240 represents blue color.
    • Saturation: It takes percentage value, where 100% represents completely saturated, while 0% represents completely unsaturated (gray).
    • Lightness: It takes percentage value, where 100% represents white, while 0% represents black.

    Syntax:

    h1 {
        color:hsl(H, S, L);
    }

    HSLA: The HSLA color property is similar to HSL property, but the difference is HSLA contains A (Alpha) which specify the transparency of elements. The value of alpha lies between 0.0 to 1.0 where 0.0. represents fully transparent and 1.0 represents not transparent.
    Syntax:

    h1 {
        color:hsla(H, S, L, A);
    }

    15. How to create a link in HTML?

    A link is a connection from one Web resource to another. A link has two ends, An anchor and direction. The link starts at the “source” anchor and points to the “destination” anchor, which may be any Web resource such as an image, a video clip, a sound bite, a program, an HTML document, or an element within an HTML document.

    HTML Link Syntax: Links are specified in HTML using the “a” tag.

    <a href="url">Link Text<a>

    Explanation:

    • href: The href attribute is used to specify the destination address of the link used.
    • Text link: The text link is the visible part of the link.

    16. What is the use of target attribute in <link> tag.

    The HTML <link> target Attribute is used to specify the window or a frame where the linked document is loaded. It is not supported by HTML 5.

    Syntax:

    <link target="_blank|_self|_parent|_top|framename">

     

    Attribute Values:

    • _blank: It opens the link in a new window.
    • _self: It opens the linked document in the same frame.
    • _parent: It opens the linked document in the parent frameset.
    • _top: It opens the linked document in the full body of the window.
    • framename: It opens the linked document in the named frame.

    17. What is the use of alt attribute in images?

    The <img> alt attribute is used to specify the alternate text for an image. It is useful when the image not displayed. It is used to give alternative information for an image.

    Syntax:

    <img alt="text">

    18. What are the HTML tags used to display a table?

    TagDescription
    <table>Used to define a table.
    <tr>Used to define a row in a table.
    <th>Used to define a header cell in a table.
    <td>Used to define a cell in a table.
    <caption>Used to define the table caption.
    <colgroup>Used to define a group of one or more columns in a table for formatting.
    <col>Used with <colgroup> element to specify column properties for each column.
    <tbody>Used to define a group the body content in a table.
    <thead>Used to group the header content in a table.
    <tfooter>Used to group the footer content in a table.

    19. What are the different types of lists in HTML?

    HTML offers three ways for specifying lists of information. All lists must contain one or more list elements.

    The types of lists that can be used in HTML are :

    • ul : An unordered list. This will list items using plain bullets.
    • ol : An ordered list. This will use different schemes of numbers to list your items.
    • dl : A definition list. This arranges your items in the same way as they are arranged in a dictionary.

    20. What is the difference between block and inline elements?

    Every element in HTML has a default display value which depends upon the element type. Block or inline are the default display value for the most of the elements.

    Block Level Elements: A block-level element always starts on a new line and stretches out to the left and right as far as it can.

    • div element: The div element is used as a container for other HTML elements. It has no required attributes. Style, class and id are the commonly used attributes.

    Syntax:

    <div>GFG</div>

    Inline Elements: An inline element is the opposite of the block-level element. It does not start on a new line and takes up only necessary width.

    • span element: The span element is used as a container for text. It has no required attributes. Style, class and id are the commonly used attributes.

    Syntax:

    <span>GFG</span>

    Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




    My Personal Notes arrow_drop_up
Recommended Articles
Page :