HTML

  Home  World Wide Web  HTML


“HTML Interview Questions and Answers will guide now that HTML, which stands for Hyper Text Markup Language, is the predominant markup language for web pages. It provides a means to create structured documents by denoting structural semantics for text such as headings, paragraphs, lists etc, so learn basics of HTML and get preparation for the job of HTML with the help of this Hyper Text Markup Language (HTML) Interview Questions with Answers guide”



84 HTML Questions And Answers

41⟩ How do I create a link?

Use an anchor element. The HREF attribute specifies the URL of the document that you want to link to. The following example links the text "Web Authoring FAQ" to <URL:http://www.htmlhelp.com/faq/html/>:

<A HREF="http://www.yoursite.com/faq/html/">Web Authoring FAQ</A>

 201 views

43⟩ How can I make a form with custom buttons?

Rather than a normal submit button (<input type="submit" ...>), you can use the image input type (<input type="image" ...>). The image input type specifies a graphical submit button that functions like a server-side image map.

Unlike normal submit buttons (which return a name=value pair), the image input type returns the x-y coordinates of the location where the user clicked on the image. The browser returns the x-y coordinates as name.x=000 and name.y=000 pairs.

For compatability with various non-graphical browsing environments, the VALUE and ALT attributes should be set to the same value as the NAME attribute. For example:

<input type="image" name="Send" alt="Send" value="Send" src="send-button.gif">

For the reset button, one could use <button type="reset" ...>, JavaScript, and/or style sheets, although none of these mechanisms work universally.

 216 views

44⟩ Which should I use, &entityname; or &#number; ?

In HTML, characters can be represented in three ways:

1. a properly coded character, in the encoding specified by the "charset" attribute of the "Content-type:" header;

2. a character entity (&entityname;), from the appropriate HTML specification (HTML 2.0/3.2, HTML 4, etc.);

3. a numeric character reference (&#number;) that specifies the Unicode reference of the desired character. We recommend using decimal references; hexadecimal references are less widely supported.

In theory these representations are equally valid. In practice, authoring convenience and limited support by browsers complicate the issue.

HTTP being a guaranteed "8-bit clean" protocol, you can safely send out 8-bit or multibyte coded characters, in the various codings that are supported by browsers.

A. HTML 2.0/3.2 (Latin-1)

By now there seems no convincing reason to choose &entityname; versus &#number;, so use whichever is convenient.

If you can confidently handle 8-bit-coded characters this is fine too, probably preferred for writing heavily-accented languages. Take care if authoring on non-ISO-8859-based platforms such as Mac, Psion, IBM mainframes etc., that your upload technique delivers a correctly coded document to the server. Using &-representations avoids such problems.

B. A single repertoire other than Latin-1

In such codings as ISO-8859-7 Greek, koi8-r Russian Cyrillic, and Chinese, Japanese and Korean (CJK) codings, use of coded characters is the most widely supported and used technique.

Although not covered by HTML 3.2, browsers have supported this quite widely for some time now; it is a valid option within the HTML 4 specifications--use a validator such as the WDG HTML Validator or the W3C HTML Validation Service which supports HTML 4 and understands different character encodings.

Browser support for coded characters may depend on configuration and font resources. In some cases, additional programs called "helpers" or "add-ins" supply virtual fonts to browsers.

"Add-in" programs have in the past been used to support numeric references to 15-bit or 16-bit code protocols such as Chinese Big5 or Chinese GB2312.

In theory you should be able to include not only coded characters but also Unicode numeric character references, but browser support is generally poor. Numeric references to the "charset-specified" encoding may appear to produce the desired characters on some browsers, but this is wrong behavior and should not be used. Character entities are also problematical, aside from the HTML-significant characters <, & etc.

C. Internationalization per HTML 4

Recent versions of the popular browsers have support for some of these features, but at time of writing it seems unwise to rely on this when authoring for a general audience.

 215 views

45⟩ How do I remove the border around frames?

Removing the border around frames involves both not drawing the frame borders and eliminating the space between the frames. The most widely supported way to display borderless frames is <FRAMESET ... BORDER=0 FRAMEBORDER=0 FRAMESPACING=0>.

Note that these attributes are proprietary and not part of the HTML 4.01 specifications. (HTML 4.01 does define the FRAMEBORDER attribute for the FRAME element, but not for the FRAMESET element.) Also, removing the border around a frame makes it difficult to resize it, as this border is also used in most GUIs to change the size of the frame.

 196 views

46⟩ How can I specify background images?

With HTML, you can suggest a background image with the BACKGROUND attribute of the BODY element. Here is an example:

<body background="imagefile.gif" bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#000080">

If you specify a background image, you should also specify text, link, and background colors since the reader's default colors may not provide adequate contrast against your background image. The background color may be used by those not using your background image. Authors should not rely on the specified background image since browsers allow their users to disable image loading or to override document-specified backgrounds.

 218 views

47⟩ Is it possible to make the HTML source not viewable?

In short, there is no real method or script for making standard HTML source code not viewable. You may consider doing any of the below if they are concerned about your source code.

1. Create the web page in Macromedia Flash or a similar program. The visitor would need to download the Macromedia Flash plug-in and would be unable to view the source code for the flash applet.

2. There are various scripts that will disable the right click feature, preventing the user from saving images or viewing the source. However, this will not protect the source code of your page. For example, Internet Explorer users may still click "View" and "Source" to view the source code of the page, or a user could disable scripts and images can be saved by simply saving the web page to the hard drive.

3. There are several programs that will help scramble your code, making it difficult (not impossible) to read. Again, this is not going to prevent someone from viewing your code.

 231 views

48⟩ How do I make a thumbnail for my image(s)?

Thumbnails are very useful, but they take a little bit of time to make. All you need is a graphics editing program that has functions to resize an image (sometimes it's under a function called image attributes). Be advised--when you have made a thumbnail, you will need to save it as something different than the original. Also, you will generally want to link to the larger graphic when you are done.

Here are the steps:

1. Load a copy of the image into your graphics editing program.

2. Determine the ratio the thumbnail to be. (Do you want it to be half the size? One third of the size? One quarter of the size? One tenth of the size?)

3. Find the resize (or change attributes) function of your program. Most programs will recogize a percentage, for example you can type in 25% for height and width if you want the thumbnail to be a quarter of the size. (It it doesn't do percentages, you can calculate it by multiplying the pixels by the percentage. If you have a graphic that is 400 by 100, and you want it 25% of the size, multiple each measurement by .25. In this case, you'll get 100 and 25.)

4. Once you are satisfied with the thumbnail, think of a name for the image. Choose Save As and enter that name. (Tip: I like to just add t after the image name. For taco.jpg I'd use tacot.jpg)

5. Upload the image to your site, and edit your HTML to load the new image name with the new, smaller size. If you wish, you can link to the larger image around the image.

Example: You have taco.jpg which is 400 pixels wide and 100 pixels high. You made a thumbnail of it called tacot.jpg, which is now 100 pixels wide and 25 pixels high. After you have both images uploaded, here's the code:

<a href="taco.jpg"><img src="tacot.jpg" width=100 height=25 border=0 alt="click for larger taco"></a>

You'll find border=0 to be helpful in eliminating a link-colored box around your thumbnail.

 202 views

49⟩ How do I rename all the files from .htm to .html after copying them from a PC to a UNIX machine?

UNIX's mv (`move') command won't handle wildcard filenames. However, there's a program called htmaddl (for `HTM-add-"L"'), so you can login and type htmaddl. This will rename all .htm files to .html

If you haven't got this program on your UNIX machine, you can type it into a file called htmaddl:

#! /bin/sh

for f in *.htm; do

base=`basename $f .htm`

mv $f $base.html

done

After saving it and exiting your editor, make it executable by typing the command

chmod ugo+x htmaddl

Best of all, move it into your ~/bin directory, or ask your WebMeister to put it in /usr/local/bin so everyone can use it.

 216 views

50⟩ Can I use any HTML in the box?

Yes. Any HTML tag that your browser supports will work in the box. So you can carry tags from chapters to chapters and mix and match...

 206 views

51⟩ I am trying to include a HTML document in another document...Is there a way to do this?

Yes, there are several ways to do this. But remember, HTML is not a programming language - it doesn't have `directives': it's a markup language, so trying to compare it to C or Pascal is not going to be very meaningful.

SGML already provides the standard way to do this, using an entry in the DocType Declaration for a file:

<!doctype html public "-//IETF//DTD HTML 3.0//EN" [

<!entity foo system "bar.html">

]>

...

and then later when you want to include the file

...

&foo;

This is the General Entity mechanism used universally in normal SGML work and does exactly what is wanted, with the added benefit that you can have multiple occurrences of &foo; if you need to include some text at more than one place. Unfortunately none of the browsers except Panorama support it, basically because very few of the programmers who write browsers bothered to read up on what can be done.

* The second way is to use the facilities of your server. This has to be enabled by someone with access to the server configuration files (ask your WebMeister). For example, the NCSA server lets you embed a command inside an SGML comment:

<!--#exec cmd="cat myfile.html"-->

Provided this occurs in a file with a special file type (eg .shtml, and this is what has to be specified in the server configuration), the server will parse the file and send out the result of the command embedded in the document.

* There is in fact a vastly easier way to do this. SGML provides a PI mechanism (Processing Instruction) in the form:

<?cat myfile>

SGML/HTML couldn't care what you put inside (except it must not, for obvious reasons, contain the `>' character!). This would be a great way to specify a page break, for example: suppose you were processing an SGML file using PostScript, you could say <?showpage>...but again, none of the browsers except Panorama support this, again because they guys who write them have never bothered to actually read up on how SGML works.

 215 views

52⟩ The colors on my page look different when viewed on a Mac and a PC.

The Mac and the PC use slighly different color palettes. There is a 216 "browser safe" color palette that both platforms support; the Microsoft color picker page has some good information and links to other resources about this. In addition, the two platforms use different gamma (brightness) values, so a graphic that looks fine on the Mac may look too dark on the PC. The only way to address this problem is to tweak the brightness of your image so that it looks acceptable on both platforms.

 185 views

53⟩ My page looks good on one browser, but not on another.

There are slight differences between browsers, such as Netscape Navigator and Microsoft Internet Explorer, in areas such as page margins. The only real answer is to use standard HTML tags whenever possible, and view your pages in multiple browsers to see how they look.

 186 views

54⟩ How do I make a link or form in one frame update another frame?

In the frameset document (the HTML document containing the <frameset> <frame> tags), make sure to name the individual frames using the NAME attribute. The following example creates a top frame named "navigation" and a bottom frame named "content":

<frameset rows="*,3*">

<frame name="navigation" src="navigation.html">

<frame name="content" src="content.html">

<noframes><body>

<!-- Alternative non-framed version -->

</body></noframes>

</frameset>

Then, in the document with the link, use the TARGET attribute to specify which frame should be used to display the link. (The value of the TARGET attribute should match the value of the target frame's NAME attribute.) For example:

<a target="content" href=...>

To target a form submission, use the TARGET attribute of the FORM element, like this:

<form target="content" action=...>

Note that when forms are processed entirely by JavaScript, the target frame must be specified in the JavaScript. The value of the TARGET attribute is irrelevant.

Normally, the default target frame is the current frame ("_self"). To change the default target for every link/form on the page, use the TARGET attribute of the BASE element, like this:

 181 views

55⟩ How do I update two frames at once?

There are two basic techniques for updating multiple frames with a single link: The HTML-based technique links to a new frameset document that specifies the new combination of frames. The JavaScript-based solution uses the onClick attribute of the link to update the additional frame (or frames).

The HTML-based technique can link to a new frameset document with the TARGET="_top" attribute (replacing the entire frameset). However, there is an alternative if the frames to be updated are part of a nested frameset. In the initial frameset document, use a secondary frameset document to define the nested frameset. For example:

<frameset cols="*,3*">

<frame src="contents.html" name="Contents">

<frame src="frameset2.html" name="Display">

<noframes>

<!-- Alternative non-framed version -->

</body></noframes>

</frameset>

A link can now use the TARGET="Display" attribute to replace simultaneously all the frames defined by the frameset2.html document.

The JavaScript-based solution uses the onClick attribute of the link to perform the secondary update. For example:

<a href="URL1" target="Frame1" onClick="top.Frame2.location='URL2';">Update frames

The link will update Frame1 with URL1 normally. If the reader's browser supports JavaScript (and has it enabled), then Frame2 will also be updated (with URL2).

 218 views

56⟩ Is there a site that shows which tags work on which browsers?

There have been several attempts to do this, but I'm not aware of any really good source of comparisons between the browsers. The trouble is that there are many different versions of each browser, and many different tags. All current browsers should support the tags in the official HTML 3.2 specification, but the major ones also support nonstandard tags and sometimes have slightly different implementations. One place that has fairly good compatibility info is Browsercaps.

 200 views

57⟩ How can I display an image on my page?

Use an IMG element. The SRC attribute specifies the location of the image. The ALT attribute provides alternate text for those not loading images. For example:

<img src="logo.gif" alt="ACME Products">

 196 views

58⟩ How do I get out of a frameset?

If you are the author, this is easy. You only have to add the TARGET attribute to the link that takes readers to the intended 'outside' document. Give it the value of _top.

In many current browsers, it is not possible to display a frame in the full browser window, at least not very easily. The reader would need to copy the URL of the desired frame and then request that URL manually.

I would recommend that authors who want to offer readers this option add a link to the document itself in the document, with the TARGET attribute set to _top so the document displays in the full window if the link is followed.

 179 views

59⟩ Are there any problems with using frames?

The fundamental problem with the design of frames is that framesets create states in the browser that are not addressable. Once any of the frames within a frameset changes from its default content, there is no longer a way to address the current state of the frameset. It is difficult to bookmark - and impossible to link or index - such a frameset state. It is impossible to reference such a frameset state in other media. When the sub-documents of such a frameset state are accessed directly, they appear without the context of the surrounding frameset. Basic browser functions (e.g., printing, moving forwards/backwards in the browser's history) behave differently with framesets. Also, browsers cannot identify which frame should have focus, which affects scrolling, searching, and the use of keyboard shortcuts in general.

Furthermore, frames focus on layout rather than on information structure, and many authors of framed sites neglect to provide useful alternative content in the NOFRAMES element. Both of these factors cause accessibility problems for browsers that differ significantly from the author's expectations and for search engines.

 171 views

60⟩ How do I open a link into a new window?

This feature is a byproduct of frames (In many opinions, the only good things frames did for web design). On any HTML page, you can just add target="_blank" to your link syntax. e.g. yoursite.com

 167 views