The other HTML FAQ

This is an attempt to answer some of the more frequently asked questions in the Usenet newsgroup comp.infosystems.www.authoring.html. It concentrates on basic questions for the most part. You will find browser-specific tricks in here, with notes on their limitations and compatibilities with older versions and other browsers.

A translation into Belorussian provided by 'PC' and a translation into Ukrainian by Mark Pozner is available.

Table of contents

How do I indent the first line in my paragraphs?

Use a stylesheet:

P:first-line { margin-left: 3em; }

This applies the style "set the left margin to 3EM" to the first line of every paragraph.

In the past various tricks with technically invalid HTML (or a 1x1 pixel GIF) were used, but these are more likely to screw up the result.

How do I indent a full paragraph of text?

Again, use a stylesheet:

P { margin-left: 5em; }

This would set the left margin of every paragraph to five ems. You can use an ID or CLASS to select only a specific paragraph, or wrap the paragraphs in question in a DIV element and set the left margin of that DIV element to something of your liking.

Can I put markup in ALT text?

No. Character entities (©, &#nnn; and such) are permitted, though.

If you want to know how to write good ALT texts without markup, please see Alan Flavell's essay on choosing ALT texts.

How do I include one file in another?

Use server-side includes, if your server supports them. Ask your Webmaster if this is the case, and if so, what the exact syntax is for your server. If you use a language such as PHP, Perl or Python to generate your webpages dynamically, you can use the include command to dynamically include other files.

Since server-side includes make the document slower, they are not always desirable. If your documents only have a static footer, which doesn't change every day, you might be better off by using an editor which can insert files in the current document, or a preprocessor.

How do I get scrolling text in the status bar?

This is not an HTML question, it's done with a Javascript. Check any page which has this feature, and copy the script from the source.

These scripts have two big problems. First, usually it uses the decrement operator (c--) at some point. The "--" sequence in a comment actually closes it on some browsers, so your code may "leak" on those browsers. The same goes for ">".

Second, keep in mind that many people consider this even worse than <BLINK>, and that it also suppresses the status information which normally appears there. It prevents people from knowing where a link goes to.

How do I hide my source?

You can't. The source is necessary for the browser to display your document. You have to send the complete, unencrypted source to the browser. Even if a particular browser doesn't have a "View source" option, there are many that do, and you can always retrieve the document by hand (using telnet) to get its source. Or check the browser's cache.

You can of course put a few hundred empty lines above the actual source, then newbies who don't see the scrollbars will think there is nothing there.

How can I make a custom rule, or a list with custom bullets?

Use a stylesheet:

UL LI { list-style-image: url(mybullet.gif); }

This states that the file 'mybullet.gif' should be used as the image for every bullet in a bulleted-list. Again, you can use classes or the ID attribute to change the image on one specific bullet.

How do I display the current date or time in my document?

With server-side includes. Ask your webmaster if this is supported, and what the exact syntax is for your server. But this will display the local time on the server, not for the client. And if the document is cached, the date will of course be incorrect after some time.

JavaScript can be used to display the local time for the client, but as most people already have one or more clocks on their screen, why display another one?

For what screen size should I write?

HTML does not depend on screen size. The text will be wrapped by the browser when the end of the screen is encountered. The only exception to this is when you use <PRE>-formatted text, which will only wrap at the line breaks you indicate. So make sure these lines are no longer than 70 characters, otherwise text mode users will see ugly line breaks on their terminals. And users of graphical browsers might have to scroll horizontally to see the rest, which is one of the most hated things to do when you read a document.

Of course, an image cannot be wrapped, so you have to be careful with that. It seems that 400 or 500 pixels is a reasonable width; anything above 600 will mean a certain percentage of users will have to scroll to see the rightmost bit. This percentage increases with your image width. Keep in mind that not everyone runs his browser at full screen!

How do I get my visitor's e-mail addresses?

You can't. Although each request for a document is usually logged with the name or address of the remote host, the actual username is almost never logged as well. This is mostly because of performance reasons, as it would require that the server uses the ident protocol to see who is on the other end. This takes time. And if a cache proxy is doing the request, you don't get anything sensible.

The most reliable way is to put up a form, asking the visitor to fill in his e-mail address. If you offer him something in return, he will most likely do it.

How do I do a pagebreak?

You don't. HTML is not a page layout language. It's up to the browser to decide where and how to insert page breaks when the document is being printed.

The CSS2 standard for stylesheets, allows you to specify pagebreak points for printing. However this option is not widely supported at this time.

How do I center a table?

Use a stylesheet:

TABLE { text-align: center; }

How do I make animated GIFs?

Ask on the comp.infosystems.www.authoring.images group. Or search for such tools on Google.

Is there a way to get indexed better by the search engines?

The best way is to provide good content and to avoid any tricks like repeatedly including the same keywords, or putting keywords in white-text-on-white-background to fool search engines. And get links from other sites. That increases your popularity and hence your position in the search results.

In the past you could use the META tag "keywords" to suggest extra keywords. This no longer works, because it has been heavily abused. You can however still use:

<META NAME="description" CONTENT="description of your site">

This allows you to suggest a descriptive text that a search engine could show if this page is found in a search. You can put up to 1022 characters in the CONTENT attribute.

How do I redirect someone to my new page?

The most reliable way is to configure the server to send out a redirection instruction when the old URL is requested. Then the browser will automatically get the new URL. This is the fastest way to do this. You can of course also simply put up a small page with a text like "This page has moved to http://new.url/, please adjust your bookmarks".

A less reliable option is to use:

which will load the new URL after x seconds. This should go in the HEAD of the document. But if you do this, also include a short text saying "Document moved to new URL so-and-so" for other browsers.

This option has the disadvantage that if you press "Back" after you have been redirected, you will be taken to the document with the META refresh. Then the refresh will be activated, and so you'll jump to the page you just tried to leave.

How do I get a back button on my page?

In HTML, this is impossible. Going "back" means that you go to the previous page in your history. The webserver cannot know which page this is, since it depends on the web browsing session. A user may have entered the URL by hand, selected it from his bookmarks or clicked on it from an e-mail. In such situations, the previous webpage is completely unknown to the webserver.

You might be able to create a link to the URL specified in the "HTTP_REFERER" environment variable in your document, but that only creates a link to a new location in your history. Even worse, the information in that variable can be plain wrong. Some browsers incorrectly send the variable when you use a bookmark or type in an URL manually, and some don't send that variable at all. Then you would end up with an empty link.

If you want to use JavaScript, you could use

<A href="javascript:history.back()">Go back</A>

although this results in a link that does not work for people that have Javascript disabled.

How do I force a download?

You can't. Next question, please.

Ok, I'll explain anyway. :-) When someone downloads a document, the server tells the browser what type of file it is. The browser then picks the appropriate helper application, or displays it himself. If the server doesn't know the file type, it tells the browser that the file is "text/plain", or just plain text. You will have to ask your server admin to configure this particular file with the MIME type you want.

"Forcing" a download is not what you are supposed to do. After all, what is more convenient than having the proper application started when I download a particular file? Browsing through a download directory can be quite a pain. And most browsers allow the user to download to disk if they want to.

If the file must be saved to disk, as there is absolutely NO other way to handle it, the MIME type should be "application/octet-stream".

Why is my binary file not downloaded, but shown on the screen?

Actually, the browser has downloaded the document, it is just treating it as a plain text file. This is because the server said it was a plain text file. To get the file in the helper application (or plug-in), you will have to configure the server to send out the right MIME type, and the browser to start the appropriate helper application for files with that MIME type.

How do I use an image instead of the standard submit button?

Use <INPUT NAME=foo TYPE=image SRC=""> instead of the normal submit tag. There is no way to do this for the reset button.

Note that browsers will also send the x and y coordinates of the location where the user clicked on the image to the server. They are available as "foo.x=000&foo.y=000" in the CGI input.

How do I get a so-and-so character in my HTML?

HTML text is supposed to be written in the ISO Latin-1 character set. A complete overview of all the characters in this set is available from the Web Design Group.

How do I get a counter?

Either ask your Webmaster for access to the log files, or for a server-side include which can do this, or use one of the freeware counters available at the CGI archives. There is no HTML tag to do this.

Counters are quite pointless, though. They can be set to any value the owner wants, so they don't give you any information. Because of the delay that often occurs when using an external counter, your visitors may get annoyed with the long loading time of your document. The server's logfile provides a lot more reliable information for you, and you don't have to bother your readers with it.

How do I detect what browser is being used?

Many browsers identify themselves when they request a document. A CGI script will have this information available in the HTTP_USER_AGENT environment variable, and it can use that to send out a version of the document which is optimized for that browser.

Keep in mind not all browsers identify themselves correctly. Some webmasters use browser detection scripts and prevent certain browsers from accessing their site. Because of this, many browsers allow their users to change the identification string completely.

And of course, if a cache proxy keeps the Internet Explorer-specific version, someone with an other browser will also get this document if he goes through the cache.

Should I put quotes around attribute values or not?

It depends. It is never wrong to use them, but you don't have to if the attribute value consists only of letters, digits, periods and/or hyphens.

Oh, and keep in mind that if you use double quotes, you should escape any quotes inside the value with "&quot;" so you don't accidentally terminate the value prematurely.

Should I use lower case or upper case for tags?

Tags are case insensitive, so it doesn't matter. This is just a matter of style. Many people prefer upper case, as it makes the tags "stand out" better amongst the text.

My images/hyperlinks are coming out all wrong, or don't load! What's up?

Most likely you forgot to close a quote at the end of an HREF or SRC. Alternatively, perhaps you used a ">" character in an ALT text or somewhere else inside a tag. Although this is legal, several older browsers will think the tag ends there, so the rest is displayed as normal text.

This especially happens if you use comment tags to "comment out" text with HTML tags. Although the correct syntax is <!-- --> (without "--" occurring anywhere inside the comment), some browsers will think the comment ends at the first > they see.

How do I get a button which takes me to a new page?

This is done with a small form:

<INPUT TYPE=submit VALUE="Text on button" NAME=foo>

If you want to line up buttons next to each other, you will have to put them in a one-row table, with each button in a separate cell.