What is an HTML File?
- HTML stands for Hyper Text Markup Language
- An HTML file is a text file containing small markup tags
- The markup tags tell the Web browser how to display the page
- An HTML file must have an htm or html file extension i.e .html
- An HTML file can be created using a simple text editor
Start Notepad.
Type in the following text:
<html>
<head>
<title>Title of page</title>
</head>
<body>
This is my first homepage
</body>
</html>
|
<html></html> this is the open and end tag for html document it contain every element of the site in view.
<head></head> this tag contain element that does not show in the body of the browser. It also contain the title tag i.e <title></title>,meta <meta></meta>.
<body></body> this tag contain all the stuff that will be display on the browser.
NOTE: for every tag you open you must close it.
To open/view what you have done, go to the folder where you saved it right click and select open.
NOTE:
The
first tag in your HTML document is <html>. This tag tells your
browser that this is the start of an HTML document. The last tag in your
document is </html>. This tag tells your browser that this is the
end of the HTML document.The text between the <head> tag and the </head> tag is header information. Header information is not displayed in the browser window.
The text between the <title> tags is the title of your document. The title is displayed in your browser's caption.
The text between the <body> tags is the text that will be displayed in your browser.
HTM or HTML Extension?
When you save an HTML file, you can use either the .htm or the .html extension. We have used .html in our examples. It might be a bad habit inherited from the past when some of the commonly used software only allowed three letter extensions.NOTE: Always use .html since it’s the newest.
Note on HTML Editors:
You can easily edit HTML files using a WYSIWYG (what you see is what you get) editor like FrontPage or Dreamweaver, instead of writing your markup tags in a plain text file.However, if you want to be a skillful Web developer, we strongly recommend that you use a plain text editor to learn your primer HTML.
HTML Elements
HTML documents are text files made up of HTML elements.
HTML elements are defined using HTML tags.
HTML Tags
- HTML tags are used to mark-up HTML elements
- HTML tags are surrounded by the two characters < and >
- The surrounding characters are called angle brackets
- HTML tags normally come in pairs like <b> and </b>
- The first tag in a pair is the start tag, the second tag is the end tag
- The text between the start and end tags is the element content
- HTML tags are not case sensitive, <b> means the same as <B>
HTML Elements
Remember the HTML example from the previous page:<html>
<head>
<title>Title of page</title>
</head>
<body>
This is my first homepage. <b>This text is bold</b>
</body>
</html>
|
<b>This text is bold</b>
|
The content of the HTML element is: This text is bold
The HTML element ends with an end tag: </b>
The purpose of the <b> tag is to define an HTML element that should be displayed as bold.
This is also an HTML element:
<body>
This is my first homepage. <b>This text is bold</b>
</body>
|
The purpose of the <body> tag is to define the HTML element that contains the body of the HTML document.
Why do We Use Lowercase Tags?
We have just said that HTML tags are not case sensitive: <B> means the same as <b>. If you surf the Web, you will notice that plenty of web sites use uppercase HTML tags in their source code. We always use lowercase tags. Why?If you want to follow the latest web standards, you should always use lowercase tags. The World Wide Web Consortium (W3C) recommends lowercase tags in their HTML 4 recommendation, and XHTML (the next generation HTML) demands lowercase tags.
Basic HTML Tags
The most important tags in HTML are tags that define headings, paragraphs and line breaks.
Headings
Headings are defined with the <h1> to <h6> tags. <h1> defines the largest heading. <h6> defines the smallest heading.<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
<h4>This is a heading</h4>
<h5>This is a heading</h5>
<h6>This is a heading</h6>
|
Paragraphs
Paragraphs are defined with the <p> tag.<p>This is a paragraph</p>
<p>This is another paragraph</p>
|
Don't Forget the Closing Tag
You might have noticed that paragraphs can be written without end tags </p>:<p>This is a paragraph
<p>This is another paragraph
|
Closing all HTML elements with an end tag is a future-proof way of writing HTML. It also makes the code easier to understand (read and browse) when you mark both where an element starts and where it ends.
Line Breaks
The <br> tag is used when you want to break a line, but don't want to start a new paragraph. The <br> tag forces a line break wherever you place it.<p>This <br> is a para<br>graph with line breaks</p>
|
<br> or <br />
More and more often you will see the <br> tag written like this: <br />Because the <br> tag has no end tag (or closing tag), it breaks one of the rules for future HTML (the XML based XHTML), namely that all elements must be closed.
Writing it like <br /> is a future proof way of closing (or ending) the tag inside the opening tag, accepted by both HTML and XML.
Comments in HTML
The comment tag is used to insert a comment in the HTML source code. A comment will be ignored by the browser. You can use comments to explain your code, which can help you when you edit the source code at a later date.<!-- This is a comment -->
|
Recap on HTML Elements
- Each HTML element has an element name (body, h1, p, br)
- The start tag is the name surrounded by angle brackets: <h1>
- The end tag is a slash and the name surrounded by angle brackets </h1>
- The element content occurs between the start tag and the end tag
- Some HTML elements have no content
- Some HTML elements have no end tag
Basic Notes - Useful Tips
When you write HTML text, you can never be sure how the text is displayed in another browser. Some people have large computer displays, some have small. The text will be reformatted every time the user resizes his window. Never try to format the text in your editor by adding empty lines and spaces to the text.HTML will truncate the spaces in your text. Any number of spaces count as one. Some extra information: In HTML a new line counts as one space.
Using empty paragraphs <p> to insert blank lines is a bad habit. Use the <br> tag instead. (But don't use the <br> tag to create lists. Wait until you have learned about HTML lists.)
HTML automatically adds an extra blank line before and after some elements, like before and after a paragraph, and before and after a heading.
We use a horizontal rule (the <hr> tag), to separate the sections in our tutorials.