Interview Questions HTML

HTML


51. How can I include an HTML page in another HTML page?
With a Strict DTD, there is only one valid option: the OBJECT element type:
HTML Code:
<object type="text/html" href="http://example.com/foo.html">
alternate content here
</object>
Unfortunately, support for OBJECT is all but non-existent in Internet Explorer.

With a Transitional DTD, we can also use the IFRAME element type:
HTML Code:
<iframe src="http://example.com/foo.html">
alternate content here
</iframe>
A much better way is to handle inclusion on the server-side. Server-side includes (SSI) is the simplest way to include a file into another, as long as they are from the same domain:
HTML Code:
<!--#include virtual="/foo.shtml"-->
(This cannot be used to include a complete HTML document into another, though; only fragments.)

With other server-side technologies you can do more advanced things. Your web server must support those technologies, of course. Shared servers with free hosting often don't provide any such technologies ? not even SSI.

Using JavaScript to 'include' things like navigation menus is not a very brilliant idea. That means visitors without JavaScript support won't be able to navigate your site. In that case, using a FRAMESET might be the lesser evil.

52. What is the difference between ABBR and ACRONYM?
No one really seems to know. Even the HTML specification is contradicting itself.

ABBR was a Netscape extension to HTML during the browser wars. ACRONYM was Microsoft's extension. Both meant the same thing, more or less. Both element types were incorporated into the HTML specification, with different semantics.


53. What is the use of the VAR element type?
To mark up a variable, or placeholder, part of an example. It is a typographic convention to italicise such variables, which will be replaced by actual data in real life use. For instance, in a telephone system manual, the instruction for relaying incoming calls to another extension could look something like this:
HTML Code:
<kbd>* 21 * <var>extension</var> #</kbd>
Here, a VAR element is used to mark up 'extension' (which will be italic by default). Someone trying to program the telephone system to relay his incoming calls to extension 942 would type '*21*942#'. Thus the VAR element indicates that you shouldn't actually type 'e-x-t-e-n-s-i-o-n', but enter the actual extension number instead. The word 'extension' is a variable.

A common misconception is that VAR should be used for marking up variables in programming code samples.

54. Should I use DIVs instead of layout tables?
No, we should use semantically correct element types as far as possible, and only revert to DIVs when there are no other options.

Abusing DIVs is no better than abusing TABLEs. We can set id and class attributes on virtually any element type. We can assign CSS rules to virtually any element type. Not only DIVs.

55. Should I use P or BR?
The P element marks up a paragraph of text. A paragraph is one or more sentences that deal with a single thought.

A line break (BR) is mostly a presentational thing, and should be handled by CSS rather than HTML. However, there are a few cases where line breaks can be said to have semantic meaning, for instance in poetry, song lyrics, postal addresses and computer code samples. These can be legitimate uses for BR, but using BR to separate 'paragraphs' is definitely not a legitimate use.

On the other hand, P has a very clear semantic meaning: it denotes a paragraph. Sometimes web authors tend to treat P as a generic block-level container element, but that's not correct. It's not uncommon to see a LABEL and an INPUT field wrapped inside a P within a FORM, but I would argue that it's semantically wrong. A label and an input field does not constitute a 'paragraph'.

56. Can I Use Word to Write My Web Page?
Using Microsoft Word to create a Web page is not always the best solution, as Word is meant to create print documents, rather than HTML documents.

57. How can I control the order of how the images load on a Web page?
Most browsers interact with the Web servers in a sequential manner, so they will start loading an image that appears first in the HTML before an image that appears later. There isn't any way to control the order of images loading on Web pages using HTML.
However, if an image was loaded on a previous page, it will usually be in the browser cache and will load more quickly. Also, you can use JavaScript to affect the load of images by setting timeouts on the visibility.

58. Should I use P or BR?
The P element marks up a paragraph of text. A paragraph is one or more sentences that deal with a single thought.
A line break (BR) is mostly a presentational thing, and should be handled by CSS rather than HTML. However, there are a few cases where line breaks can be said to have semantic meaning, for instance in poetry, song lyrics, postal addresses and computer code samples. These can be legitimate uses for BR, but using BR to separate 'paragraphs' is definitely not a legitimate use.
On the other hand, P has a very clear semantic meaning: it denotes a paragraph. Sometimes web authors tend to treat P as a generic block-level container element, but that's not correct. It's not uncommon to see a LABEL and an INPUT field wrapped inside a P within a FORM, but I would argue that it's semantically wrong. A label and an input field does not constitute a 'paragraph'.

59. Why should I validate my markup?
Why should you spell-check your text before publishing it on the Web? Because mistakes and errors can confuse your readers and detract from the important information. It is the same with markup. Invalid markup can confuse browsers, search engines and other user agents. The result can be improper rendering, dysfunctional pages, unindexed pages in the search engines, program crashes, or the end of the universe as we know it.
If your page doesn't display the way you intended, always validate your markup before you start looking for other problems (or asking for help on SitePoint). With invalid markup, there are no guarantees.
Use the HTML validator at W3C to check for compliance. Don't forget to include a DOCTYPE declaration, so the validator knows what to check against.
HTML Tidy is a free tool that can help you tidy up sloppy markup and make it nicely formatted and easier to read.

60. Why does HTML allow sloppy coding?
It doesn't, but it recommends that user agents handle markup errors and try to recover.
It is sometimes alleged ? usually as an argument for why XHTML is superior to HTML ? that HTML allows improperly nested elements like <b><i>foo</b></i>. That is not true; the validator will complain about that because it is not valid HTML. However, browsers will usually guess what the author meant, so the error can go by undetected.
Some dislike that HTML allows certain (but not all!) end tags to be omitted. That is not a problem for browsers, because valid markup can be parsed unambiguously anyway. In the early years it was very common to omit certain end tags, e.g., </p> and </li>. Nowadays it's usually considered good practice to use explicit end tags for all elements except those where it is forbidden (like BR and IMG).