How to

#HTML #Web Development #coding

Interview Questions

Basics of HTML

What is «HTML»?

HTML, HyperText Markup Language, is the standardized markup language for documents on the World Wide Web. Currently, the most recent version of this language is HTML5.

Back to Table of Contents

What is «XHTML»?

XHTML, eXtensible HyperText Markup Language, is a more strict version of HTML that adheres to all XML constraints and is essentially an application of XML in the realm of hypertext markup.

Back to Table of Contents

What is DOCTYPE and why is it needed?

The <!DOCTYPE> element specifies the type of the current document. This is necessary for the browser to understand which standard it should use to interpret the web page.

There are several types of <!DOCTYPE>, differing by the version of the language they are based on:

HTML 4.01

HTML 5

XHTML 1.0

XHTML 1.1

Back to Table of Contents

What is the purpose of the <head> tag?

The <head> tag is intended to hold other elements aimed at helping the browser manage the data. Within this container are meta tags, which are used to store information intended for browsers and search engines. For instance, search engines refer to meta tags for site descriptions, keywords, and other data.

The content of the <head> tag is not directly displayed on the web page, except for the <title> tag that sets the window title.

Inside the <head> container, the following elements may be included: <base>, <basefont>, <bgsound>, <link>, <meta>, <script>, <style>, <title>.

Syntax:

<head>
    ...
</head>

Specific attributes:

Back to Table of Contents

What is the difference between <div> and <span>?

<div> is a block-level element, while <span> is an inline element. Therefore, <div> creates a block by placing its content on a new line, whereas <span> does not break lines, placing elements inline. Additionally, according to W3C guidelines, inline tags cannot contain block tags, so <div> is generally used for block markup, and <span> for snippets of text.

Back to Table of Contents

How are comments denoted in HTML?

Comments in HTML code are denoted as follows: <!-- comment -->

Comments can be used anywhere on the page except within the <title> tag—they do not work there. Inside the <style> tag, HTML comments also do not work, as CSS code is commented differently.

Back to Table of Contents

How is the address of a document specified for linking?

To create links to other documents, the <a> tag is used. Depending on the presence of the name or href attributes, the <a> tag either establishes a link or an anchor. An anchor refers to a bookmark within a page that can be set as a link target. When using a link that points to an anchor, the browser navigates to the bookmark within the web page.

Syntax:

Specific attributes:

Back to Table of Contents

Creating a link to an email address is done similarly to creating a link to a web page, but instead of a URL, you use mailto:"email address"

<a href="mailto:user@address.net">Email me!</a>

Back to Table of Contents

What is the purpose of the <em> tag?

The <em> tag is used for emphasizing text. Browsers render such text in italics.

<em>Text</em>

Back to Table of Contents

What are the purposes of the <ol>, <ul>, <li> tags?

The <ol>, <ul>, and <li> tags are used for formatting lists.

<ol>
    Ordered List
    <li>first</li>
    <li>second</li>
    <li>third</li>
</ol>

<ul>
    Unordered List
    <li>first</li>
    <li>second</li>
    <li>third</li>
</ul>

Back to Table of Contents

What are the purposes of the <dl>, <dt>, <dd> tags?

The <dl>, <dt>, and <dd> tags are used for creating a definition list.

Each such list starts with a <dl> container, which includes a <dt> tag for creating a term and a <dd> tag for defining that term. The closing </dd> tag is optional since the following tag indicates the end of the previous element. However, it is good style to close all tags.

<dl>
    Definition List
    <dt>Term</dt>
    <dd>Definition</dd>
</dl>

Back to Table of Contents

What are the purposes of the <tr>, <th>, <td> tags?

<tr>: serves as a container for creating a table row. Each cell within the row can be created using <th> or <td>. <th>: used to create a cell for a table header. <td>: used to create a cell within a table.

<table>
    <tr>
        <th>Header</th>
    </tr>
    <tr>
        <td>Row</td>
    </tr>
</table>

Back to Table of Contents

Is it mandatory to use the alt attribute in the <img> tag?

Yes, it is mandatory.

The alt attribute specifies alternative text for images. This text provides textual information about the image when images are not loaded in the browser. Since images are loaded after the browser has gathered information about them, the alternative text appears before the image loads. As the image loads, the text is replaced by the image.

<img src="forest.jpg" alt="Forest" />

Back to Table of Contents

What is the best case for writing HTML code?

It is recommended to write all HTML code in lowercase: this applies to element names, attribute names, attribute values (except for text/CDATAs), selectors, properties, and their values (except for text).

Not recommended:

<a href="/">Home</a>

Recommended:

<a href="/">Home</a>

Back to Table of Contents

What is a “mnemonic (entity)”?

A mnemonic (entity) is a construction made from the & symbol followed by a letter (or numerical code) after it, intended to substitute characters that are prohibited for use in HTML in “visible form”.

# has the mnemonic &num;

Back to Table of Contents

Sources

Interview Questions