html - tutorial 1

return to content page/computer science home

Topics:

  1. introduction to html
  2. the html page outline and comments
  3. the <head></head> section
  4. the <body></body> section - general notes
  5. formatting text
  6. positioning the contents of your page
  7. adding pictures to your page - the <img> tag
  8. linking - the <a></a> tag

  1. introduction to html
  2. html stands for hypertext markup language. the current standard is html 4.01, but xhtml (extensible html) is the way of the future.

    it defines a set of tags (usually in pairs such as <b> and </b>) and related attributes (such as the style attribute in <p style="align:right;">right aligned paragraph</p>), and how a browser interprets the tags the content in between. learn the set of tags, and their associated attributes, and how browsers treat them and you learn html.

    most tags are made up of both an opening tag such as <i> and a matching closing tag such as </i>. attributes only appear inside the opening tag.

    for some tags (e.g. <p> and <li>) the closing tag is optional, but for future version of html (xhtml) you should always put them in anyway.

    other tags are empty tags(e.g. <br>, <hr>) and also don't require a closing tag, but for these empty tags you should specifically indicate that they are empty by inserting a "/" before the closing ">" (e.g. <br /> and <hr />).

    static html pages (the ones you'll be making here) should be saved with the suffix .html or .htm

    although in older versions of html, the tags and their attributes are case-insensitive (e.g. an <hr /> tag is equivalent to an <HR /> tag), xhtml is not and so it is best to start writing all your tags in lower case.

    back to top


  3. the html page outline and comments
  4. all html pages follow the same outline:
    <html>
    
    <head>
        <!-- all information about your page goes here - it does not appear in the main browser window -->
    </head>
    
    <body>
        <!-- all the content of your page goes here - this is what appears in your browser window -->
    </body>
    
    </html>
    

    a note about comments in your html page: if you want to annotate your html source code with stuff that won't be picked up by the browser (so won't be displayed), put it inside <!-- these tags -->

    back to top


  5. the <head></head> section
    1. the <title></title> tag
    2. <title>put in here what is to appear in the top-most bar of your browser</title>

    3. the <meta/> tag and a note on attributes
    4. <meta name="type of meta-info" content="content/value of meta-info" />
        type of meta-info = e.g. keywords, description

      used by some search engines to determine how relevant your page is, although google scans your entire page contents.

      notice how the 'name' and 'content' words appear within the <meta> tag - these are the attributes of the tag. they usually give further information as to how the browser should interpret the tag. each attribute is represented by a name="value" pair. we will come across more attributes later.

    5. the <style> and <link> tags
    6. use to add styling to your page - see the css tutorial (to be created) for further details

    7. the <head> section for this page
    8. <head>
          <title>html - tutorial 1</title>
          <meta name="description" content="a visual introduction to the basics of html" />
          <meta name="keywords" content="html, tutorial, tags, markup, beginners, basic" />
          <link href="../../styles/notesstyle.css" rel="stylesheet" type="text/css"/>
      </head>
      

    back to top


  6. the <body></body> section - general notes
    1. page content
    2. the rest of this tutorial demonstrates the main tags used to markup (tell the browser how to display) the content of your web-page

    3. indenting your source code
    4. as there are many tags, and many which can be nested inside other tags (like the <title;> tag is nested inside the <head> tag), it is a really good idea to indent all your nesting. as a rule, for every level of nesting (i.e. after every opening tag) i indent 1 tab (or 4 spaces). this makes your source code soooo much easier to create. white-space is pretty much ignored by the browser (except in between <pre></pre> tags) so feel free to space things out as much as you need to make them clear. e.g.
      <table>
          <tr>
              <td>some content</td>
          </tr>
      </table>	
      

    5. common attributes: id, name, class and style
    6. almost all tags can take these attributes.

      id is a unique identifier (meaning only a single tag can have a particular id value on any one page), and it will surplant the use of name - but for now, you only need set the name and id attributes of a tag that you are going to want to link to directly on your page. e.g. for the title of this section:
        <h2 id="s4" name="s4"><li>the ...
      name is required for backwards compatibility and id for future-proofing. also, ensure that the id and name are the same, and that their value starts with a letter and contains only alpha-numerics.

      class is used to give a name to a group of tags for common styling

      style is used to format the html element - set the color, font, thickness, margins, type, etc.

      you will learn more about the class and style attributes in the css tutorial. but for now, if you have a group of tags on a page that will probably be formatted in the same way, you can set their 'class' attribute.

    back to top


  7. formatting text
  8. <u></u> should be used sparingly as people on the net associate it with links. furthermore, it is deprecated so replace with <span style="text-decoration:underline;"> underlined text</span>

    <font></font> is another deprecated tag that we will not cover here.

    the logical tags
    source displayed
    <h1>heading 1</h1>

    heading 1

    <h2>heading 2</h2>

    heading 2

    <h3>heading 3</h3>

    heading 3

    <h4>heading 4</h4>

    heading 4

    <h5>heading 5</h5>
    heading 5
    <em>emphasis</em> emphasis
    <strong>strong</strong> strong
    <del>deleted text</del> deleted text
    <code>code</code> code
    base value<sup>superscript</sup> base valuesuperscript
    base value<sub>subscript</sub> base valuesubscript

    the physical tags
    source displayed
    <b>bold</b> bold
    <i>italic</i> italic
    <u>underline</u> underline - deprecated! avoid using
    <big>big</big> big
    <small>small</small> small
    <span style="color:red;">span style="color:red;"</span> span style="color:red;"

    the exact appearance of how a browser displays all of these tag's contents can be precisely controlled using stylesheets or the style attribute - see the next tutorial on adding style as to how to do this (once you've written your site, especially using logical markup tags, you can set the look and feel using a stylesheet - this way you can make your pages more uniform, and it is easy to change the look of your whole site - you just need to change a single file!)

    back to top


  9. positioning the contents of your page
    1. the <p></p> and <br/> tags
    2. <p> - starts a new paragraph (the end tag </p> at the end of the paragraph is optional)

      <br /> - forces a line break (same as <br> - i.e. an empty tag)

      source displayed
      <p>paragraph 1</p>
      <p>paragraph 2</p>

      paragraph 1

      paragraph 2

      line 1<br />
      line 2
      line 1
      line 2

    3. lists - <ul>, <ol> and <li> tags
      1. list items - the <li> tag
      2. every item in a list is preceded by the <li> tag - the closing </li> tag at the end of the list item is optional

        <li>'s can be used within an ordered (<ol>) or unordered (<ul>) list.

        source displayed
        <ol>
            <li>list item 1</li>
            <li>list item 2</li>
            <li>list item 3</li>
        </ol>
        
        1. list item 1
        2. list item 2
        3. list item 3
        <ul>
            <li>list item 1</li>
            <li>list item 2</li>
            <li>list item 3</li>
        </ul>
        
        • list item 1
        • list item 2
        • list item 3

        the type attribute (see below in ordered and unordered lists) can also be aplied to the <li> tag

      3. unordered lists - the <ul></ul> tag
      4. attribute: type="disc|square|circle" - deprecated, use the style attribute: list-style-type

        style="list-style-type:none|disc|square|circle"

        source displayed
        <ul style="list-style-type:none;">
            <li>list item 1</li>
            <li>list item 2</li>
            <li>list item 3</li>
        </ul>
        
        • list item 1
        • list item 2
        • list item 3
        <ul style="list-style-type:disc;">
            <li>list item 1</li>
            <li>list item 2</li>
            <li>list item 3</li>
        </ul>
        
        • list item 1
        • list item 2
        • list item 3
        <ul style="list-style-type:square;">
            <li>list item 1</li>
            <li>list item 2</li>
            <li>list item 3</li>
        </ul>
        
        • list item 1
        • list item 2
        • list item 3
        <ul style="list-style-type:circle;">
            <li>list item 1
            <li>list item 2
            <li>list item 3
        </ul>
        
        • list item 1
        • list item 2
        • list item 3

      5. ordered lists - the <ol></ol> tag
      6. attribute: type="1|A|a|I|i" - deprecated, use the style attribute: list-style-type

        style="list-style-type:decimal|upper-alpha|lower-alpha|upper-roman|lower-roman"

        source displayed
        <ol style="list-style-type:decimal;">
            <li>list item 1
            <li>list item 2
            <li>list item 3
        </ol>
        
        1. list item 1
        2. list item 2
        3. list item 3
        <ol style="list-style-type:upper-alpha;">
            <li>list item 1
            <li>list item 2
            <li>list item 3
        </ol>
        
        1. list item 1
        2. list item 2
        3. list item 3
        <ol style="list-style-type:lower-alpha;">
            <li>list item 1
            <li>list item 2
            <li>list item 3
        </ol>
        
        1. list item 1
        2. list item 2
        3. list item 3
        <ol style="list-style-type:upper-roman;">
            <li>list item 1
            <li>list item 2
            <li>list item 3
        </ol>
        
        1. list item 1
        2. list item 2
        3. list item 3
        <ol style="list-style-type:lower-roman;">
            <li>list item 1
            <li>list item 2
            <li>list item 3
        </ol>
        
        1. list item 1
        2. list item 2
        3. list item 3

        attribute: start="an integer" - although this attribute is deprecated, i would still use it as there isn't a suitable replacement in css as yet. e.g.

        source displayed
        <ol start="4">
            <li>list item 1
            <li>list item 2
            <li>list item 3
        </ol>
        
        1. list item 1
        2. list item 2
        3. list item 3

    4. tables - <table>, <tbody>, <tr> and <td> tags
      1. basic table structure
      2. <table></table> goes around the entire table,
        <tbody></tbody> goes around all the rows of the table,
        <tr></tr> goes around each table row and
        <td></td> goes around the table data (i.e. the content of each table cell)

        source displayed
        <table border="1">
            <caption>this is the table caption</caption>
            <thead>this is the table header</thead>
            <tfoot>this is the table footer</tfoot>
            <tbody>
                <tr>
                    <td>row 1, col 1</td>
                    <td>row 1, col 2</td>
                </tr>
                <tr>
                    <td>row 2, col 1</td>
                    <td>row 2, col 2</td>
                </tr>
            <tbody>
        </table>
        
        this is the table headerthis is the table footer
        this is the table caption
        row 1, col 1 row 1, col 2
        row 2, col 1 row 2, col 2

        other elements that go just before the section are:
        <caption></caption>
        <thead></thead>
        <tfoot></tfoot>

      3. <td> attributes: rowspan and colspan
      4. source displayed
        <table border="1">
            <tr>
                <td width="100px">cell 1</td>
                <td width="100px">cell 2</td>
                <td width="100px">cell 3</td>
            </tr>
            <tr>
                <td colspan="2">cell 4 - colspan="2"</td>
                <td rowspan="2">cell 5 - rowspan="2"</td>
            </tr>
            <tr>
                <td>cell 6</td>
                <td>cell 7</td>
            </tr>
            <tr>
                <td>cell 8</td>
                <td colspan="2" rowspan="2">
                    cell 9 - colspan="2" rowspan="2"</td>
            </tr>
            <tr>
                <td>cell 10</td>
            </tr>
        </table>
        
        cell 1 cell 2 cell 3
        cell 4 - colspan="2" cell 5 - rowspan="2"
        cell 6 cell 7
        cell 8 cell 9 - colspan="2" rowspan="2"
        cell 10

      5. <table> attributes: cellpadding, cellspacing and border
      6. cellpadding is the spacing (in pixels) between the contents of a cell and the inside border/edge of the cell

        cellspacing is the spacing (in pixels) between cells

        border is the thickness of the border (in pixels) around the table and cells

        cellspacing, cellpadding and border attributes
        source displayed
        <table border="1" cellspacing="0" cellpadding="5">
            <tr>
                <td>cell 1</td>
                <td>cell 2</td>
            </tr>
            <tr>
                <td>cell 3</td>
                <td>cell 4</td>
            </tr>
        </table>
        
        cell 1 cell 2
        cell 3 cell 4
        <table border="1" cellspacing="5" cellpadding="0">
            <tr>
                <td>cell 1</td>
                <td>cell 2</td>
            </tr>
            <tr>
                <td>cell 3</td>
                <td>cell 4</td>
            </tr>
        </table>
        
        cell 1 cell 2
        cell 3 cell 4
        <table border="0" cellspacing="5" cellpadding="0">
            <tr>
                <td>cell 1</td>
                <td>cell 2</td>
            </tr>
            <tr>
                <td>cell 3</td>
                <td>cell 4</td>
            </tr>
        </table>
        
        cell 1 cell 2
        cell 3 cell 4

    5. lining things up - align and valign
    6. many of the tags in this section can also take the attributes align ("left|center|right" - the horizontal alignment of the contents of the tag) and valign (the vertical alignment of the contents of the tag)

      <p align="center">

      <p align="left"> - the default

      <p align="right">

      <table align="center"...
      <table align="left"...

      <table align="right"...

      <td valign="top"... <td valign="middle"... <td valign="bottom"...

    back to top


  10. adding pictures to your page - the <img> tag
  11. <img src="url of image" alt="alt text">

    e.g. in the same folder that this html page is in is another folder called images, in here is a picture named smileynuts.gif

    source displayed
    <img src="images/smileynuts.gif" alt="smile nutter!"> smile nutter!
    <img src="images/wrongname.gif" alt="smile nutter!"> smile nutter!

    if, for some reason, the browser can't find your image - it displayes the 'alt' text instead.

    back to top


  12. linking - the <a></a> tag
  13. <a></a>: the anchor tag

    <a href="rel or abs url">link text</a>

    1. linking to another page on your site - using a relative url
    2. these start with a folder name or the page name itself, or with "../" which moves up one level to the parent folder of the current folder.

      so to link back to the computer science page, i use the url: "../CompSci.html"
        <a href="../CompSci.html">back to computer home</a>

    3. linking to a page on a different site - using an absolute url
    4. start with "http://"
        <a href="http://www.google.co.nz"> go to google nz<a>

      but if people use this link, they leave your site (unless they right-click and select 'open in new window/tab'). to open the link in a new page add the attribute: target="_blank":
      <a href="http://www.google.co.nz" target="_blank"> open google nz in a new page<a>     - try it!

    5. linking to a specific point on a page
    6. first, for each point you will want to directly link to you need to give it a name with an anchor tag: <a name="name of section"></a>beginning of your section

      then you can link to it by appending to the end of the url with #name of section

      if moving to different places on the same page, you use href="#name of section" in your link
      e.g. for the back to top sections:<a href="#top">back to top</a>

      if i wanted to link to <a href="here"></a>here from another page, i would use
      <a href="http://alicia.orcon.net.nz/computer/webtutorials/htmltutorial1.html#here">link to 'here' in html tutorial</a>

      try it!

back to top