HTML & CSS tutorials
1. Hello world!
Note: While reading this page, bear in mind that although I have some experience of writing HTML and CSS I'm no expert. If you find errors or have proposals for improvements, please send me a message and help make this a better page for the benefit of future visitors. If you're new to or not that experienced in HTML and CSS, I suggest you go to the Introduction page and follow the instructions. To the left, there are links to more HTML and CSS tutorials.
Considering the fact that I refer HTML and CSS beginners to HTML Dog at the Introduction page, a Hello world tutorial is perhaps a bit superfluous. Anyway, it is the first HTML and CSS tutorial for now. To complete this tutorial, follow these instructions:
1. Open a new empty document with Notepad++ or some other text editor.
2. Write or copy this code to the document:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
3. Save the document as hello_world.html (or whatever as long as the extension is html).
4. Open hello_world.html (or whatever you've called the document) with Mozilla Firefox 10, Internet Explorer 9 or some other modern browser. The text
Hello world! should appear in the window.
Comments on the HTML code
Line 1 is an XML declaration. According to the page XHTML™ 1.0 The Extensible HyperText Markup Language (Second Edition) on w3.org,
an XML declaration is not required in all XML documents; however XHTML document authors are strongly encouraged to use XML declarations in all their documents. Such a declaration is required when the character encoding of the document is other than the default UTF-8 or UTF-16 and no encoding was determined by a higher-level protocol. When I started learning HTML, I decided to follow this recommendation, thinking that it would be useful at some point when I knew more; however, including an XML declaration in each and every HTML document has, as far as I know, had to influence whatsoever over how my web pages have been rendered by browsers. Decide for yourself whether to include an XML declaration or not in your HTML documents; according to W3C:s HTML validator, an XHTML document is valid whether an XML declaration is present or not (as long as the encoding is UTF-8, that is).
Line 5 tells a browser what kind of content the document contains (text/html) and what encoding that is used (UTF-8). I suggest you always use UTF-8, because any special character you will ever use should be rendered correctly if you do; that is not the case if you're using some other encoding, like ANSI.
See also HTML Beginner Tutorial on htmldog.com.
Would you like to comment on this page or some other page? Send an email to firstname.lastname@example.org or a letter to Mats Kristiansson, Timmervägen 3A, 541 64 Skövde, Sweden with the title of the page you want to comment on, your comment and your name or a pseudonym.