Difference between revisions of "HTML:Essentials"

From mi-linux
Jump to navigationJump to search
 
(23 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==Introduction==
+
[[Main Page]] >> [[4CC002|Website fundamentals]] >> [[4CC002Workbook|Workbook]] >> [[HTML]] >> Essential Tags
  
This chapter contains the essentials for formatting text on a web page.  The tags in this section control most of the formatting you will ever want to do.  You should practice the use of ALL the tags in this section EXTENSIVELY before progressing to the next section.
+
== Introduction ==
  
==Heading Tags==
+
This chapter contains the essentials for formatting text on a web page. The tags in this section control most of the formatting you will ever want to do. You should practice the use of ALL the tags in this section EXTENSIVELY before progressing to the next section.
  
Heading tags are used to create headings and subheadings in your document.  There are six sizes of heading available for you to use, but it is likely that you will only use a few of them.
+
== Heading Tags ==
  
*'''HINT''': ''You should use headings sparingly, as they tend to distract the reader from the content of the web page if they are overused.''
+
Heading tags are used to create headings and subheadings in your document. There are six sizes of heading available for you to use, but it is likely that you will only use a few of them.
 +
 
 +
* '''HINT''': ''You should use headings sparingly, as they tend to distract the reader from the content of the web page if they are overused.''
  
 
For example, the following tags:
 
For example, the following tags:
 +
<pre><nowiki>&lt;H1&gt;Whale&lt;/H1&gt;&lt;H2&gt;Elephant&lt;/H2&gt;&lt;H3&gt;Horse&lt;/H3&gt;&lt;H4&gt;Dog&lt;/H4&gt;
 +
&lt;H5&gt;Cat&lt;/H5&gt;&lt;H6&gt;Mouse&lt;/H6&gt;</nowiki></pre>
 +
When opened in a web browser, your web page should look like this:
  
<nowiki>
+
[[Image:Headers.png|Image:headers.png]]
<H1>Whale</H1><H2>Elephant</H2><H3>Horse</H3><H4>Dog</H4>
 
<H5>Cat</H5><H6>Mouse</H6></nowiki>
 
  
When opened in a web browser, your web page should look like this:
+
* '''TIME TO PRACTICE'''
 +
** Now you have a go at the example above. Remember to start with the "Standard Web Page Structure" from [[HTML:Basics]] and add the text in the blue box above in the appropriate place. Include an appropriate title. You may wish to save the examples as you follow them. Refer to the section of "Saving Your Work" for instructions on how to save your examples.
  
[[Image:headers.png]]
+
== Additional Exercises ==
  
*'''TIME TO PRACTICE'''
 
**Now you have a go at the example above.  Remember to start with the "Standard Web Page Structure" from [[02 – The Basics Of HTML]] and add the text in the blue box above in the appropriate place.  Include an appropriate title.  You may wish to save the examples as you follow them.  Refer to the section of "Saving Your Work" for instructions on how to save your examples.
 
 
==Additional Exercises==
 
 
Experiment with putting text in and around the heading tags to see how the rest of the text in the document flows when the browser comes across a heading. For example, try the following:
 
Experiment with putting text in and around the heading tags to see how the rest of the text in the document flows when the browser comes across a heading. For example, try the following:
 +
<pre><nowiki>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
 +
&lt;HTML&gt;
 +
&lt;HEAD&gt;
 +
&lt;TITLE&gt; put your title here &lt;/TITLE&gt;
 +
&lt;/HEAD&gt;
 +
&lt;BODY&gt;
 +
&lt;H1&gt;Heading 1&lt;/H1&gt;
 +
&lt;P&gt;Hello&lt;/P&gt;
 +
&lt;H2&gt;My name is&lt;/H2&gt;
 +
&lt;P&gt;Fred&lt;/P&gt;
 +
&lt;/BODY&gt;
 +
&lt;/HTML&gt;</nowiki></pre>
 +
== Aligning Headings ==
  
<nowiki><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 
<HTML>
 
  <HEAD>
 
      <TITLE> put your title here </TITLE>
 
  </HEAD>
 
  <BODY>
 
<H1>Heading 1</H1>
 
<P>Hello</P>
 
<H2>My name is</H2>
 
<P>Fred</P>
 
  </BODY>
 
</HTML></nowiki>
 
 
==Aligning Headings==
 
 
If we wanted a heading to be centred horizontally on the page, we would use the "ALIGN" attribute and the value "center"
 
If we wanted a heading to be centred horizontally on the page, we would use the "ALIGN" attribute and the value "center"
  
 
* ''HINT: Note the American spelling of the word "center"''
 
* ''HINT: Note the American spelling of the word "center"''
 
+
<pre>&lt;H1 style="text-align:center"&gt;Whale&lt;/H1&gt;</pre>
<nowiki><H1 style="text-align:center">Whale</H1></nowiki>
 
 
...which would look like this...
 
...which would look like this...
  
[[Image:centeredheading.png]]
+
[[Image:Centeredheading.png|Image:centeredheading.png]]
 
 
You can also align text to the right hand side of the page like this…
 
  
<nowiki><H1 style="text-align:right">Whale</H1></nowiki>
+
You can also align text to the right hand side of the page like this…
 +
<pre>&lt;H1 style="text-align:right"&gt;Whale&lt;/H1&gt;</pre>
 
...which would look like this...
 
...which would look like this...
  
[[Image:rightheading.png]]
+
[[Image:Rightheading.png|Image:rightheading.png]]
  
In order to align the text to the left hand margin, you could use ALIGN="left", but you don’t have to, because the browser does this by default.
+
In order to align the text to the left hand margin, you could use align="left", but you don’t have to, because the browser does this by default.
  
==Structuring Text==
+
== Structuring Text ==
  
It is important to note at this stage, that a web browser ignores carriage returns (or blank lines, line feeds, new lines) in a web page. New lines are not rendered as you would expect them to be in something like a text editor.
+
It is important to note at this stage, that a web browser ignores carriage returns (or blank lines, line feeds, new lines) in a web page. New lines are not rendered as you would expect them to be in something like a text editor.
  
 
For example, try the following web page, and notice the difference in where the '''line breaks''' are in your source code when compared to the rendered web page.
 
For example, try the following web page, and notice the difference in where the '''line breaks''' are in your source code when compared to the rendered web page.
 +
<pre><nowiki>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
 +
&lt;HTML&gt;
 +
&lt;HEAD&gt;
 +
&lt;TITLE&gt; put your title here &lt;/TITLE&gt;
 +
&lt;/HEAD&gt;
 +
&lt;BODY&gt;
 +
&lt;H1 style="text-align:center"&gt;The Alphabet&lt;/H1&gt;
 +
&lt;P&gt;The alphabet is made up of 26 letters.
 +
A is the first letter,
 +
B is the second,
 +
and so on until Z, the 26th letter.
 +
&lt;/P&gt;
 +
&lt;/BODY&gt;
 +
&lt;/HTML&gt;</nowiki></pre>
 +
[[Image:Alphabet1.png|Image:alphabet1.png]]
  
<nowiki><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+
As you can see from the example above, the carriage returns or new lines we put in our HTML are not displayed in the web page. There are a number of ways in which we can achieve the results we are looking for.
<HTML>
 
  <HEAD>
 
      <TITLE> put your title here </TITLE>
 
  </HEAD>
 
  <BODY>
 
    <H1 style="text-align:center">The Alphabet</H1>
 
    <P>The alphabet is made up of 26 letters.
 
    A is the first letter,
 
    B is the second,
 
    and so on until Z, the 26th letter.
 
    </P>
 
  </BODY>
 
</HTML></nowiki>
 
 
 
[[Image:alphabet1.png]]
 
  
As you can see from the example above, the carriage returns or new lines we put in our HTML are not displayed in the web page.  There are a number of ways in which we can achieve the results we are looking for.
+
== Paragraph Tags ==
  
==Paragraph Tags==
+
Paragraph tags are interpreted by the browser as the start and end of a paragraph, and are the simplest way to separate long text in a web page into logical sections, the same way as in a book, or this workbook for example. A paragraph tag is made up of a start tag and an end tag.&nbsp; The start tag is <nowiki>&lt;P&gt;</nowiki> and the end tag is <nowiki>&lt;/P&gt;</nowiki>.
 
 
Paragraph tags are interpreted by the browser as the start and end of a paragraph, and are the simplest way to separate long text in a web page into logical sections, the same way as in a book, or this workbook for example.
 
A paragraph tag is <nowiki><P></nowiki> and the end tag is <nowiki></P></nowiki>.  The paragraph tag is one of the simple tags as we defined earlier, and can be used like the
 
 
 
tag, in that we don’t have to specify attributes and values.
 
  
 
* '''HINT''': ''Refer back to Chapter 2 for a refresher on names, attributes and values.''
 
* '''HINT''': ''Refer back to Chapter 2 for a refresher on names, attributes and values.''
  
 
For example, try the following:
 
For example, try the following:
 +
<pre><nowiki>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
 +
&lt;HTML&gt;
 +
&lt;HEAD&gt;
 +
&lt;TITLE&gt; put your title here &lt;/TITLE&gt;
 +
&lt;/HEAD&gt;
 +
&lt;BODY&gt;
 +
&lt;H1 style="text-align:center"&gt;The Alphabet&lt;/H1&gt;
 +
&lt;P&gt;The alphabet is made up of 26 letters.&lt;/P&gt;
 +
&lt;P&gt;A is the first letter,&lt;/P&gt;
 +
&lt;P&gt;B is the second,&lt;/P&gt;
 +
&lt;P&gt;and so on until Z, the 26th letter.&lt;/P&gt;
 +
&lt;/BODY&gt;
 +
&lt;/HTML&gt;</nowiki></pre>
 +
[[Image:Alphabet2.png|Image:alphabet2.png]]
  
<nowiki><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+
<br>
<HTML>
 
  <HEAD>
 
      <TITLE> put your title here </TITLE>
 
  </HEAD>
 
  <BODY>
 
    <H1 style="text-align:center">The Alphabet</H1>
 
    <P>The alphabet is made up of 26 letters.</P>
 
    <P>A is the first letter,</P>
 
    <P>B is the second,</P>
 
    <P>and so on until Z, the 26th letter.</P>
 
  </BODY>
 
</HTML></nowiki>
 
 
 
[[Image:alphabet2.png]]
 
  
 +
* '''TIME TO PRACTICE'''
 +
** Create a web page with at least a few hundred words on a subject of your choice. Save this somewhere safe as we will be using it many times in the coming exercises.
 +
** Experiment with using paragraph and heading tags to split the text into logical sections. Save this page, as you will be amending it in coming exercises. Ensure you have started with the "web page standard structure"
  
*'''TIME TO PRACTICE'''
+
== Line Breaks ==
**Create a web page with at least a few hundred words on a subject of your choice. Save this somewhere safe as we will be using it many times in the coming exercises.
 
** Experiment with using paragraph and heading tags to split the text into logical sections. Save this page, as you will be amending it in coming exercises.  Ensure you have started with the "web page standard structure"
 
  
==Line Breaks==
+
A line break can be used to force a carriage return in your text. It is VERY IMPORTANT to note that a line break is one of the few tags in HTML that does not have a closing tag. The line break tag is <nowiki>&lt;BR&gt;</nowiki> but there is no such thing as a <nowiki>&lt;/BR&gt;</nowiki> - it does not exist because it is not needed.
A line break can be used to force a carriage return in your text. It is VERY IMPORTANT to note that a line break is one of the few tags in HTML that does not have a closing tag. The line break tag is <nowiki><BR></nowiki> but there is no such thing as a <nowiki></BR></nowiki> - it does not exist because it is not needed.
 
  
 
For example, try the following:
 
For example, try the following:
<nowiki><P>This is my first line<BR>This is my second<BR>Here is a third</P></nowiki>
+
<pre><nowiki>&lt;P&gt;This is my first line&lt;BR&gt;This is my second&lt;BR&gt;Here is a third&lt;/P&gt;</nowiki></pre>
 
+
=== [[HTML Good Practice]] 2 – Use <nowiki>&lt;BR&gt;</nowiki> Sparingly ===
===[[HTML Good Practice]] 2 – Use <nowiki><BR></nowiki> Sparingly===
 
  
Excessive use of <nowiki><BR></nowiki> to control the formatting of a document is bad practice – there are better formatting controls (paragraphs, tables, Cascading Style Sheets, etc.) that you will cover later in this workbook. Excessive use of <nowiki><BR></nowiki> in your exercises and related assessments will likely reduce your grades.
+
Excessive use of <nowiki>&lt;BR&gt;</nowiki> to control the formatting of a document is bad practice – there are better formatting controls (paragraphs, tables, Cascading Style Sheets, etc.) that you will cover later in this workbook. Excessive use of <nowiki>&lt;BR&gt;</nowiki> in your exercises and related assessments will likely reduce your grades.
  
*'''TIME TO PRACTICE'''
+
* '''TIME TO PRACTICE'''  
** Using the Alphabet HTML code example on the previous page, try to add <BR> tags in the correct places so that the rendered web page looks like the HTML, that is, with the correct line breaks in the correct places.
+
** Using the Alphabet HTML code example on the previous page, try to add <br>tags in the correct places so that the rendered web page looks like the HTML, that is, with the correct line breaks in the correct places.
  
*'''HINT''': ''When the workbook refers to HTML code, it means the web page as it looks in a text editor, so that you can see all the HTML tags.''
+
* '''HINT''': ''When the workbook refers to HTML code, it means the web page as it looks in a text editor, so that you can see all the HTML tags.''
  
 +
<br>
  
==Bold==
+
== Bold ==
  
There are a number of ways to control the "strength" of displayed text in HTML. Text which is stronger than normal text is what we usually call BOLD text.
+
There are a number of ways to control the "strength" of displayed text in HTML. Text which is stronger than normal text is what we usually call BOLD text.
  
The traditional way of making text bold, is to use the <nowiki><B></B></nowiki> tags. When a browser finds text that is within this tag pair, it makes the text appear bold.  
+
The traditional way of making text bold, is to use the <nowiki>&lt;B&gt;&lt;/B&gt;</nowiki> tags. When a browser finds text that is within this tag pair, it makes the text appear bold.
  
 
Try this:
 
Try this:
<nowiki>
+
<pre><nowiki>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+
  &lt;HTML&gt;
  <HTML>
+
&lt;HEAD&gt;
  <HEAD>
+
&lt;TITLE&gt; put your title here &lt;/TITLE&gt;
      <TITLE> put your title here </TITLE>
+
&lt;/HEAD&gt;
  </HEAD>
+
&lt;BODY&gt;
  <BODY>
+
&lt;P&gt;&lt;B&gt;This is some bold text&lt;/B&gt; and this is not&lt;/P&gt;
    <P><B>This is some bold text</B> and this is not</P>
+
&lt;/BODY&gt;
  </BODY>
+
  &lt;/HTML&gt;</nowiki></pre>
  </HTML>
+
[[Image:Boldnotbold.png|Image:boldnotbold.png]]
</nowiki>
 
  
[[Image:boldnotbold.png]]
+
* '''TIME TO PRACTICE'''
 +
** Using your long text web page you are developing, use the bold tags to highlight some key words.
  
*'''TIME TO PRACTICE'''
+
== Strong ==
**Using your long text web page you are developing, use the bold tags to highlight some key words.
 
  
==Strong==
+
As we have discussed earlier, the modern approach to building web pages is to separate the content from the presentation. By using '''<nowiki>&lt;BOLD&gt;</nowiki>''' tags, you are forcing both the content and the presentation together, not separating them. Using the bold tag, you (the web page designer) are forcing your opinion of how a webpage should look on your visitors. The more appropriate approach to identify some content in a stronger way than the norm is to use the '''<nowiki>&lt;STRONG&gt;</nowiki>''' tag.
As we have discussed earlier, the modern approach to building web pages is to separate the content from the presentation. By using '''<nowiki><BOLD></nowiki>''' tags, you are forcing both the content and the presentation together, not separating them. Using the bold tag, you (the web page designer) are forcing your opinion of how a webpage should look on your visitors. The more appropriate approach to identify some content in a stronger way than the norm is to use the '''<nowiki><STRONG></nowiki>''' tag.
 
  
Strong enables the client to determine how they want to present STRONG content. For example, perhaps a client wants to make all strong content very large and green, flashing text. By using STRONG, you enable them to do this. By using BOLD, you do not.
+
Strong enables the client to determine how they want to present STRONG content. For example, perhaps a client wants to make all strong content very large and green, flashing text. By using STRONG, you enable them to do this. By using BOLD, you do not.
  
 
Whilst BOLD conforms to strict HTML 4.01, you should replace all instances of BOLD with STRONG as a matter of best practice.
 
Whilst BOLD conforms to strict HTML 4.01, you should replace all instances of BOLD with STRONG as a matter of best practice.
  
*'''TIME TO PRACTICE'''
+
* '''TIME TO PRACTICE'''  
**Using the long text web page from the previous examples, replace the bold tags with STRONG. This is a good opportunity to practice using the "find and replace" features of your text editor – a very valuable skill.
+
** Using the long text web page from the previous examples, replace the bold tags with STRONG. This is a good opportunity to practice using the "find and replace" features of your text editor – a very valuable skill.
  
===[[HTML Good Practice]] 3 – Use <nowiki><STRONG></nowiki> or CSS, not <nowiki><B></nowiki>===
+
=== [[HTML Good Practice]] 3 – Use <nowiki>&lt;STRONG&gt;</nowiki> or CSS, not <nowiki>&lt;B&gt;</nowiki> ===
  
For the purposes of the exercises in this workbook and any related assessments, you are required to use either <nowiki><STRONG></nowiki> or CSS to control the strength of text, not the bold tag. Usage of the bold tag will reduce your grades.
+
For the purposes of the exercises in this workbook and any related assessments, you are required to use either <nowiki>&lt;STRONG&gt;</nowiki> or CSS to control the strength of text, not the bold tag. Usage of the bold tag will reduce your grades.
  
==Italic==
+
== Italic ==
  
There are a number of ways to control the "emphasis" of displayed text in HTML. Text which is emphasised more than normal text is what we usually call ITALIC text, and is used for quotations, speech, and similar types of text.
+
There are a number of ways to control the "emphasis" of displayed text in HTML. Text which is emphasised more than normal text is what we usually call ITALIC text, and is used for quotations, speech, and similar types of text.
  
The traditional way of making text italic, is to use the <nowiki><I></I></nowiki> tags. When a browser finds text that is within this tag pair, it makes the text appear italic.
+
The traditional way of making text italic, is to use the <nowiki>&lt;I&gt;&lt;/I&gt;</nowiki> tags. When a browser finds text that is within this tag pair, it makes the text appear italic.
  
 
Try the following:
 
Try the following:
<nowiki><P><I>This is italic</I>but this is not</P></nowiki>
+
<pre><nowiki>&lt;P&gt;&lt;I&gt;This is italic&lt;/I&gt;but this is not&lt;/P&gt;</nowiki></pre>
 
+
* '''TIME TO PRACTICE'''  
*'''TIME TO PRACTICE'''
+
** Using your long text web page from the previous page, use the italic tags to highlight some key words.
**Using your long text web page from the previous page, use the italic tags to highlight some key words.
 
  
==EM-phasis==
+
== EM-phasis ==
  
As we have discussed with the BOLD tags, the practice of forcing the browser to render emphasised text in italics is becoming outdated. Cascading Style Sheets (CSS) offer some greater control for both the author and the reader in terms of emphasised text, as you will see in the final chapter, but there is an alternate tag that performs the same function, but puts the user in control, namely the <nowiki><EM></EM></nowiki> (short for emphasis) tags.
+
As we have discussed with the BOLD tags, the practice of forcing the browser to render emphasised text in italics is becoming outdated. Cascading Style Sheets (CSS) offer some greater control for both the author and the reader in terms of emphasised text, as you will see in the final chapter, but there is an alternate tag that performs the same function, but puts the user in control, namely the <nowiki>&lt;EM&gt;&lt;/EM&gt;</nowiki> (short for emphasis) tags.
  
*'''TIME TO PRACTICE'''
+
* '''TIME TO PRACTICE'''  
**Using your long text web page, replace the italic tags with <nowiki><EM></nowiki> tags.
+
** Using your long text web page, replace the italic tags with <nowiki>&lt;EM&gt;</nowiki> tags.
  
===[[HTML Good Practice]] 4 – Use <nowiki><EM></nowiki> or CSS, not <nowiki><I></nowiki>===
+
=== [[HTML Good Practice]] 4 – Use <nowiki>&lt;EM&gt;</nowiki> or CSS, not <nowiki>&lt;I&gt;</nowiki> ===
  
For the purposes of the exercises in this workbook and any related assessments, you are required to use either <nowiki><EM></nowiki> or CSS to control the emphasis of text, not the italic tag. Usage of the italic tag will reduce your grades.
+
For the purposes of the exercises in this workbook and any related assessments, you are required to use either <nowiki>&lt;EM&gt;</nowiki> or CSS to control the emphasis of text, not the italic tag. Usage of the italic tag will reduce your grades.
  
==Underlining Text==
+
== Underlining Text ==
  
It is possible to underline text in web pages, however this practice has become outdated due primarily to the fact that most users expect underlined text to be a Hyperlink – see next chapter. Also, the HTML standards list the underline tags <nowiki><U></U></nowiki> as deprecated, meaning that browsers will likely still make text within the <nowiki><U></nowiki> tag underlined, but authors should no longer use this function. As such, whilst it is possible to underline text, you are recommended against doing so.
+
It is possible to underline text in web pages, however this practice has become outdated due primarily to the fact that most users expect underlined text to be a Hyperlink – see next chapter. Also, the HTML standards list the underline tags <nowiki>&lt;U&gt;&lt;/U&gt;</nowiki> as deprecated, meaning that browsers will likely still make text within the <nowiki>&lt;U&gt;</nowiki> tag underlined, but authors should no longer use this function. As such, whilst it is possible to underline text, you are recommended against doing so.
  
===[[HTML Good Practice]] 5 – Do not underline text unless it is a hyperlink===
+
=== [[HTML Good Practice]] 5 – Do not underline text unless it is a hyperlink ===
  
For the purposes of the exercises in this workbook and any related assessments, you should not underline any non-hyperlink text. Doing so will likely decrease your grade.
+
For the purposes of the exercises in this workbook and any related assessments, you should not underline any non-hyperlink text. Doing so will likely decrease your grade.
  
==Combining Tags==
+
== Combining Tags ==
  
It is possible to combine tags together to make enhanced use of different formatting commands. The <nowiki><STRONG></nowiki> and <nowiki><EM></nowiki> tags from the sections previously are a good example. It is possible to create a word or words that are both bold and emphasised.
+
It is possible to combine tags together to make enhanced use of different formatting commands. The <nowiki>&lt;STRONG&gt;</nowiki> and <nowiki>&lt;EM&gt;</nowiki> tags from the sections previously are a good example. It is possible to create a word or words that are both bold and emphasised.
  
 
For example, try this:
 
For example, try this:
<nowiki><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+
<pre><nowiki>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
  <HTML>
+
  &lt;HTML&gt;
  <HEAD>
+
&lt;HEAD&gt;
      <TITLE> put your title here </TITLE>
+
&lt;TITLE&gt; put your title here &lt;/TITLE&gt;
  </HEAD>
+
&lt;/HEAD&gt;
  <BODY>
+
&lt;BODY&gt;
    <P>This example shows how to <STRONG><EM>combine</EM></STRONG> tags to enhanced effect.</P>
+
&lt;P&gt;This example shows how to &lt;STRONG&gt;&lt;EM&gt;combine&lt;/EM&gt;&lt;/STRONG&gt; tags to enhanced effect.&lt;/P&gt;
  </BODY>
+
&lt;/BODY&gt;
  </HTML></nowiki>
+
  &lt;/HTML&gt;</nowiki></pre>
 
+
[[Image:Strongem.png|Image:strongem.png]]
[[Image:strongem.png]]
 
  
When using multiple tags together, HTML standards dictate that the closing tags must be in the reverse order of the opening tags. This is easier to demonstrate than it is to discuss.
+
When using multiple tags together, HTML standards dictate that the closing tags must be in the reverse order of the opening tags. This is easier to demonstrate than it is to discuss.
  
 
This is correct '''NOTE: do not type this in - it is to demonstrate the concept, but it won't render anything'''
 
This is correct '''NOTE: do not type this in - it is to demonstrate the concept, but it won't render anything'''
 
+
<pre><nowiki>&lt;TAG1&gt;&lt;TAG2&gt;&lt;TAG3&gt;This is my text&lt;/TAG3&gt;&lt;/TAG2&gt;&lt;/TAG1&gt;</nowiki></pre>
<nowiki><TAG1><TAG2><TAG3>This is my text</TAG3></TAG2></TAG1></nowiki>
 
 
 
 
Anything else, like the following, is '''wrong''':
 
Anything else, like the following, is '''wrong''':
 +
<pre><nowiki>&lt;TAG1&gt;&lt;TAG2&gt;&lt;TAG3&gt;This is my text&lt;/TAG1&gt;&lt;/TAG2&gt;&lt;/TAG3&gt;</nowiki></pre>
 +
=== [[HTML Good Practice]] 6 – Combination tags must be closed correctly ===
  
<nowiki><TAG1><TAG2><TAG3>This is my text</TAG1></TAG2></TAG3></nowiki>
+
For the purposes of the exercises in this workbook and any related assessments, you should close all combination tags in the correct order. Failure to do so will likely decrease your grade.
 
 
===[[HTML Good Practice]] 6 – Combination tags must be closed correctly===
 
 
 
For the purposes of the exercises in this workbook and any related assessments, you should close all combination tags in the correct order. Failure to do so will likely decrease your grade.
 
  
==Controlling Fonts using CSS==
+
== Controlling Fonts using CSS ==
  
In previous versions of HTML, the way to control the font, size and colour of text was by using the <nowiki><FONT></FONT></nowiki> tags. These are now deprecated in version 4.01 of the HTML specifications – meaning basically that as authors you should not use them any more. It is now considered better practice to control the font of a section of text by using the style attribute of the section, for example, using the paragraph tag <nowiki><P></nowiki> we can control the font, size and colour by controlling the style attribute of the paragraph tag.
+
In previous versions of HTML, the way to control the font, size and colour of text was by using the <nowiki>&lt;FONT&gt;&lt;/FONT&gt;</nowiki> tags. These are now deprecated in version 4.01 of the HTML specifications – meaning basically that as authors you should not use them any more. It is now considered better practice to control the font of a section of text by using the style attribute of the section, for example, using the paragraph tag <nowiki>&lt;P&gt;</nowiki> we can control the font, size and colour by controlling the style attribute of the paragraph tag.
  
It’s important that we look at this closely, because this is the first instance that we are experimenting with Cascading Style Sheets (CSS).  There is a full chapter on CSS at the end of this workbook, but we’ll closely look at these examples as they will be important from now on.  These examples use a form of CSS called "Inline Style."
+
These examples use a form of CSS called "Inline Style."
  
Almost all tags can have a style attribute. The style attribute controls the visual representation of the contents of that tag and is very versatile. The value of the style attribute is written in a slightly different language to HTML and this subtle difference is critical in getting the desired results.
+
Almost all tags can have a '''style''' attribute. The style attribute controls the visual representation of the contents of that tag and is very versatile. The value of the style attribute is written in a slightly different language to HTML and this subtle difference is critical in getting the desired results.
  
 
Inline Style syntax is always in lowercase, and is made up of one or many names and values – the name is the thing we want to change and the value is what we want to change it to.
 
Inline Style syntax is always in lowercase, and is made up of one or many names and values – the name is the thing we want to change and the value is what we want to change it to.
  
font-family
+
=== font-family ===
 
+
<pre>font-family</pre>
 
The font-family component of style controls which font the text is rendered in.
 
The font-family component of style controls which font the text is rendered in.
 +
<pre><nowiki>&lt;P style="font-family: Arial"&gt;Hello, this should be in Arial Font&lt;/P&gt;</nowiki></pre>
 +
This example shows how we can change the font of the paragraph by changing the font-family name to the value Arial. Notice carefully the syntax of the style attribute’s value. The font-family has a ":" symbol after it, followed by the name of the font we want to use. We can change the font to any font that is installed on the machine that the web page will be viewed on NOT the fonts available on the author’s machine. For example, if the author has the Tahoma font installed on their machine, and the viewer of that web page does not, the text will appear in the default font for their browser. Also, font changes should be used sparingly – too many fonts make a page difficult to read – try to stick to some basic fonts that are available to most visitors (Courier, Arial, and Times.) Most PC users using Microsoft Operating systems should have Georgia and Verdana also – those fonts are specifically designed for ease of reading when displayed on a webpage, and have been used in this workbook.
  
<nowiki><P style="font-family: Arial">Hello, this should be in Arial Font</P></nowiki>
+
* '''TIME TO PRACTICE'''
 +
** Change some fonts in your long web page exercise used previously.
  
This example shows how we can change the font of the paragraph by changing the font-family name to the value Arial.  Notice carefully the syntax of the style attribute’s value.  The font-family has a ":" symbol after it, followed by the name of the font we want to use.
+
=== [[HTML Good Practice]] 7 – Use fonts changes sparingly and carefully ===
We can change the font to any font that is installed on the machine that the web page will be viewed on NOT the fonts available on the author’s machine.  For example, if the author has the Tahoma font installed on their machine, and the viewer of that web page does not, the text will appear in the default font for their browser.  Also, font changes should be used sparingly – too many fonts make a page difficult to read – try to stick to some basic fonts that are available to most visitors (Courier, Arial, and Times.)  Most PC users using Microsoft Operating systems should have Georgia and Verdana also – those fonts are specifically designed for ease of reading when displayed on a webpage, and have been used in this workbook.
 
  
==<font color=red>TIME TO PRACTICE</font>==
+
As not all fonts can be rendered by the users of your web pages, try to stick to a few common fonts and use them sparingly. Failure to do this may result in lower grades for assessments.
  
Change some fonts in your long web page exercise used previously.
+
=== font-size ===
 +
<pre>font-size</pre>
 +
The size of the font can also be controlled; however this facility comes with many warnings.Let’s discuss the warnings first.
  
===[[Matthew’s Rule]] 7 – Use fonts changes sparingly and carefully===
+
Whilst you can change the size of the text in your document you should refrain from specifying exact sizes. Exact or fixed sizes of fonts (like 20 point text for example) cause problems for users using alternative browsers, like hand-held computers that have small screens. Most browsers allow the user to change the size of all the text in a web site – Internet Explorer’s and Firefox's text-size control can be found in the View menu for example. This helps people with sight difficulties see web pages more clearly. However, using fixed or exact sizes stops this function from working.
 
 
As not all fonts can be rendered by the users of your web pages, try to stick to a few common fonts and use them sparingly.  Failure to do this may result in lower grades for assessments.
 
 
 
===Font Sizes===
 
 
 
font-size
 
 
 
The size of the font can also be controlled; however this facility comes with many warnings.  Let’s discuss the warnings first.  Whilst you can change the size of the text in your document you should refrain from specifying exact sizes. Exact or fixed sizes of fonts (like 20 point text for example) cause problems for users using alternative browsers, like handheld computers that have small screens. Most browsers allow the user to change the size of all the text in a web site – Internet Explorer’s text-size control can be found in the View menu for example. This helps people with sight difficulties see web pages more clearly. However, using fixed or exact sizes stops this function from working.
 
  
 
It is much better to use what we call relative or proportional sizing in your fonts (and other web page elements that we’ll discuss later) as it offers the user more control over how they want to see your site, but still allows you the author the power to make one section of text bigger than another.
 
It is much better to use what we call relative or proportional sizing in your fonts (and other web page elements that we’ll discuss later) as it offers the user more control over how they want to see your site, but still allows you the author the power to make one section of text bigger than another.
  
In order to use proportional sizing, CSS provides for some keywords to control sizes or you can control the size as a percentage (with 100% being "normal" size). Following are some examples:
+
In order to use proportional sizing, CSS provides some ''keywords'' to control sizes or you can control the size as a ''percentage'' (with 100% being "normal" size). Following are some examples:
 
+
<pre><nowiki>&lt;P style="font-size: small"&gt;This is small&lt;/P&gt; &lt;P style="font-size: large"&gt;This is large&lt;/P&gt;</nowiki></pre>
<nowiki><P style="font-size: small">This is small</P> <P style="font-size: large">This is large</P></nowiki>
 
 
 
 
'''Font size keywords are xx-small, x-small, small, medium, large, x-large, and xx-large'''
 
'''Font size keywords are xx-small, x-small, small, medium, large, x-large, and xx-large'''
 +
<pre><nowiki>&lt;P style="font-size: 75%"&gt;This is small&lt;/P&gt;&lt;P style="font-size: 150%"&gt;This is large&lt;/P&gt;</nowiki></pre>
 +
* '''TIME TO PRACTICE'''
 +
** Change some font sizes in your long web page example previously used. Use the text size changer in your browser (on the View menu in Internet Explorer) to see how the user can control part of the experience of viewing your pages.
  
<nowiki><P style="font-size: 75%">This is small</P><P style="font-size: 150%">This is large</P></nowiki>
+
=== [[HTML Good Practice]] 8 – Font sizes should be proportional, not fixed ===
  
==<font color=red>TIME TO PRACTICE</font>==
+
Font sizing can cause problems for your users. Use font sizes that the user can control. Failure to do this may result in lower grades for assessments.
 
 
Change some font sizes in your long web page example previously used.  Use the text size changer in your browser (on the View menu in Internet Explorer) to see how the user can control part of the experience of viewing your pages.
 
 
 
===[[Matthew's Rule]] 8 – Font sizes should be proportional, not fixed===
 
 
 
Font sizing can cause problems for your users. Use font sizes that the user can control. Failure to do this may result in lower grades for assessments.
 
 
 
===Font Colors===
 
  
 +
=== color ===
 +
<pre>color</pre>
 
As in the previous examples of font family and sizes, colour is also controllable but also has warnings.
 
As in the previous examples of font family and sizes, colour is also controllable but also has warnings.
  
The first warning is that some colours are usually reserved in web pages to show hyperlink usage (covered in next chapter) – your browser will show hyperlinks in blue underlined text most of the time, and visited links are usually shown in purple underlined text. You should not use these colours in your content to avoid confusion. Also, not everyone can view colours in their browsers – some only show web pages in greyscale or even black and white. Finally, care must be taken with the colour of text in context with the colour of the background. White text on white background will be invisible, yellow text on white is very difficult to read, as is dark blue on black, and so on. Make sure there is sufficient contrast (difference between text colour and background) in your colour scheme, and also avoid colours which are difficult to read for long periods (bright green on bright pink is hard on the eyes.)
+
The first warning is that some colours are usually reserved in web pages to show hyperlink usage (covered in next chapter) – your browser will show hyperlinks in blue underlined text most of the time, and visited links are usually shown in purple underlined text. You should not use these colours in your content to avoid confusion. Also, not everyone can view colours in their browsers – some only show web pages in grey or even black and white. Finally, care must be taken with the colour of text in context with the colour of the background. White text on white background will be invisible, yellow text on white is very difficult to read, as is dark blue on black, and so on. Make sure there is sufficient contrast (difference between text colour and background) in your colour scheme, and also avoid colours which are difficult to read for long periods (bright green on bright pink is hard on the eyes.)
  
There are two different ways of setting the colour of text – using colour names or colour hex values. The HTML specification provides for a basic set of 16 colour names (aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, yellow) but most PC users can display millions of colours. A good resource to find the codes and names of colours can be found at [http://www.w3schools.com/html/html_colornames.asp http://www.w3schools.com/html/html_colornames.asp]
+
There are two different ways of setting the colour of text – using ''colour names'' or colour ''hex values''. The HTML specification provides for a basic set of 16 colour names
 +
<pre>aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, yellow</pre>
 +
but most PC users can display millions of colours. A good resource to find the codes and names of colours can be found at [http://www.w3schools.com/html/html_colornames.asp]
 +
<pre><nowiki>&lt;P style="color: aqua"&gt;This is a light-blue-ish&lt;/P&gt;&lt;P style="color: red"&gt;This is red&lt;/P&gt;
 +
&lt;P style="color: #8A2Be2"&gt;This is violet&lt;/P&gt;&lt;P style="color: #D2691E"&gt;This is chocolate&lt;/P&gt;</nowiki></pre>
 +
* '''HINT''': ''Notice how the word "color" is spelt in American English?''
  
<nowiki><P style="color: aqua">This is a light-blue-ish</P><P style="color: red">This is red</P></nowiki>
+
* '''TIME TO PRACTICE'''
 +
** Using your long text web page, experiment with using colours in your page, perhaps combining them with heading tags to have coloured headings. Remember not to use blue or purple with underlined text.
  
<nowiki><P style="color: #8A2Be2">This is violet</P><P style="color: #D2691E">This is chocolate</P></nowiki>
+
== Combination Font Changes ==
  
''[[HINT]]: Notice how the word "color" is spelt in American English?''
+
It was shown earlier how multiple tags could be used to combine effects on text. In a similar fashion, it is possible to combine multiple effects of the attributes of the font tag, however the way this is done is different for the inline CSS.
 
+
<pre><nowiki>&lt;P style="font-family: Georgia; font-size: large; color: green"&gt;This is the text to be displayed&lt;/P&gt;</nowiki></pre>
color
+
Notice how the different aspects of the change (family, size and color) are all separated with ";" symbols – this is critical or none of the changes will work.
 
 
==<font color=red>TIME TO PRACTICE</font>==
 
 
 
Using your long text web page, experiment with using colours in your page, perhaps combining them with heading tags to have coloured headings.  Remember not to use blue or purple with underlined text.
 
  
==Combination Font Changes==
+
* '''TIME TO PRACTICE'''
 +
** Using your long text web page, experiment with using AT LEAST ONE example of a multiple attribute font tag
  
It was shown earlier how multiple tags could be used to combine effects on text.  In a similar fashion, it is possible to combine multiple effects of the attributes of the font tag, however the way this is done is different for the inline CSS.
+
== Ready to move on? ==
  
<nowiki><P style="font-family: Georgia; font-size: large; color: green">This is the text to be displayed</P></nowiki>
+
A considerable number of new topics have been introduced in this chapter. It is VITAL that you experiment with these extensively before progressing. Understanding of the topics in this chapter is CRITICAL to your success in all areas of web development, as well as ALL of the assessments for this module.
  
Notice how the different aspects of the change (family, size and color) are all separated with ";" symbols – this is critical or none of the changes will work.
+
If you're happy that you've practiced enough with the content in this section, try [[HTML:Hyperlinks]]
  
==<font color=red>TIME TO PRACTICE</font>==
+
= Related Pages =
  
Using your long text web page, experiment with using AT LEAST ONE example of a multiple attribute font tag
+
<categorytree mode="pages">HTML</categorytree>
A considerable number of new topics have been introduced in this chapter.  It is VITAL that you experiment with these extensively before progressing.  Understanding of the topics in this chapter is CRITICAL to your success in all areas of web development, as well as ALL of the assessments for this module.
 
  
==Ready to move on?==
+
[[Category:HTML]]
If you're happy that you've practiced enough with the content in this section, try [[04 - Hyperlinks]]
 

Latest revision as of 15:00, 12 July 2011

Main Page >> Website fundamentals >> Workbook >> HTML >> Essential Tags

Introduction

This chapter contains the essentials for formatting text on a web page. The tags in this section control most of the formatting you will ever want to do. You should practice the use of ALL the tags in this section EXTENSIVELY before progressing to the next section.

Heading Tags

Heading tags are used to create headings and subheadings in your document. There are six sizes of heading available for you to use, but it is likely that you will only use a few of them.

  • HINT: You should use headings sparingly, as they tend to distract the reader from the content of the web page if they are overused.

For example, the following tags:

<H1>Whale</H1><H2>Elephant</H2><H3>Horse</H3><H4>Dog</H4>
 <H5>Cat</H5><H6>Mouse</H6>

When opened in a web browser, your web page should look like this:

Image:headers.png

  • TIME TO PRACTICE
    • Now you have a go at the example above. Remember to start with the "Standard Web Page Structure" from HTML:Basics and add the text in the blue box above in the appropriate place. Include an appropriate title. You may wish to save the examples as you follow them. Refer to the section of "Saving Your Work" for instructions on how to save your examples.

Additional Exercises

Experiment with putting text in and around the heading tags to see how the rest of the text in the document flows when the browser comes across a heading. For example, try the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <HTML>
 <HEAD>
 <TITLE> put your title here </TITLE>
 </HEAD>
 <BODY>
 <H1>Heading 1</H1>
 <P>Hello</P>
 <H2>My name is</H2>
 <P>Fred</P>
 </BODY>
 </HTML>

Aligning Headings

If we wanted a heading to be centred horizontally on the page, we would use the "ALIGN" attribute and the value "center"

  • HINT: Note the American spelling of the word "center"
<H1 style="text-align:center">Whale</H1>

...which would look like this...

Image:centeredheading.png

You can also align text to the right hand side of the page like this…

<H1 style="text-align:right">Whale</H1>

...which would look like this...

Image:rightheading.png

In order to align the text to the left hand margin, you could use align="left", but you don’t have to, because the browser does this by default.

Structuring Text

It is important to note at this stage, that a web browser ignores carriage returns (or blank lines, line feeds, new lines) in a web page. New lines are not rendered as you would expect them to be in something like a text editor.

For example, try the following web page, and notice the difference in where the line breaks are in your source code when compared to the rendered web page.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <HTML>
 <HEAD>
 <TITLE> put your title here </TITLE>
 </HEAD>
 <BODY>
 <H1 style="text-align:center">The Alphabet</H1>
 <P>The alphabet is made up of 26 letters.
 A is the first letter,
 B is the second,
 and so on until Z, the 26th letter.
 </P> 
 </BODY>
 </HTML>

Image:alphabet1.png

As you can see from the example above, the carriage returns or new lines we put in our HTML are not displayed in the web page. There are a number of ways in which we can achieve the results we are looking for.

Paragraph Tags

Paragraph tags are interpreted by the browser as the start and end of a paragraph, and are the simplest way to separate long text in a web page into logical sections, the same way as in a book, or this workbook for example. A paragraph tag is made up of a start tag and an end tag.  The start tag is <P> and the end tag is </P>.

  • HINT: Refer back to Chapter 2 for a refresher on names, attributes and values.

For example, try the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <HTML>
 <HEAD>
 <TITLE> put your title here </TITLE>
 </HEAD>
 <BODY>
 <H1 style="text-align:center">The Alphabet</H1>
 <P>The alphabet is made up of 26 letters.</P>
 <P>A is the first letter,</P>
 <P>B is the second,</P>
 <P>and so on until Z, the 26th letter.</P>
 </BODY>
 </HTML>

Image:alphabet2.png


  • TIME TO PRACTICE
    • Create a web page with at least a few hundred words on a subject of your choice. Save this somewhere safe as we will be using it many times in the coming exercises.
    • Experiment with using paragraph and heading tags to split the text into logical sections. Save this page, as you will be amending it in coming exercises. Ensure you have started with the "web page standard structure"

Line Breaks

A line break can be used to force a carriage return in your text. It is VERY IMPORTANT to note that a line break is one of the few tags in HTML that does not have a closing tag. The line break tag is <BR> but there is no such thing as a </BR> - it does not exist because it is not needed.

For example, try the following:

<P>This is my first line<BR>This is my second<BR>Here is a third</P>

HTML Good Practice 2 – Use <BR> Sparingly

Excessive use of <BR> to control the formatting of a document is bad practice – there are better formatting controls (paragraphs, tables, Cascading Style Sheets, etc.) that you will cover later in this workbook. Excessive use of <BR> in your exercises and related assessments will likely reduce your grades.

  • TIME TO PRACTICE
    • Using the Alphabet HTML code example on the previous page, try to add
      tags in the correct places so that the rendered web page looks like the HTML, that is, with the correct line breaks in the correct places.
  • HINT: When the workbook refers to HTML code, it means the web page as it looks in a text editor, so that you can see all the HTML tags.


Bold

There are a number of ways to control the "strength" of displayed text in HTML. Text which is stronger than normal text is what we usually call BOLD text.

The traditional way of making text bold, is to use the <B></B> tags. When a browser finds text that is within this tag pair, it makes the text appear bold.

Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <HTML>
 <HEAD>
 <TITLE> put your title here </TITLE>
 </HEAD>
 <BODY>
 <P><B>This is some bold text</B> and this is not</P>
 </BODY>
 </HTML>

Image:boldnotbold.png

  • TIME TO PRACTICE
    • Using your long text web page you are developing, use the bold tags to highlight some key words.

Strong

As we have discussed earlier, the modern approach to building web pages is to separate the content from the presentation. By using <BOLD> tags, you are forcing both the content and the presentation together, not separating them. Using the bold tag, you (the web page designer) are forcing your opinion of how a webpage should look on your visitors. The more appropriate approach to identify some content in a stronger way than the norm is to use the <STRONG> tag.

Strong enables the client to determine how they want to present STRONG content. For example, perhaps a client wants to make all strong content very large and green, flashing text. By using STRONG, you enable them to do this. By using BOLD, you do not.

Whilst BOLD conforms to strict HTML 4.01, you should replace all instances of BOLD with STRONG as a matter of best practice.

  • TIME TO PRACTICE
    • Using the long text web page from the previous examples, replace the bold tags with STRONG. This is a good opportunity to practice using the "find and replace" features of your text editor – a very valuable skill.

HTML Good Practice 3 – Use <STRONG> or CSS, not <B>

For the purposes of the exercises in this workbook and any related assessments, you are required to use either <STRONG> or CSS to control the strength of text, not the bold tag. Usage of the bold tag will reduce your grades.

Italic

There are a number of ways to control the "emphasis" of displayed text in HTML. Text which is emphasised more than normal text is what we usually call ITALIC text, and is used for quotations, speech, and similar types of text.

The traditional way of making text italic, is to use the <I></I> tags. When a browser finds text that is within this tag pair, it makes the text appear italic.

Try the following:

<P><I>This is italic</I>but this is not</P>
  • TIME TO PRACTICE
    • Using your long text web page from the previous page, use the italic tags to highlight some key words.

EM-phasis

As we have discussed with the BOLD tags, the practice of forcing the browser to render emphasised text in italics is becoming outdated. Cascading Style Sheets (CSS) offer some greater control for both the author and the reader in terms of emphasised text, as you will see in the final chapter, but there is an alternate tag that performs the same function, but puts the user in control, namely the <EM></EM> (short for emphasis) tags.

  • TIME TO PRACTICE
    • Using your long text web page, replace the italic tags with <EM> tags.

HTML Good Practice 4 – Use <EM> or CSS, not <I>

For the purposes of the exercises in this workbook and any related assessments, you are required to use either <EM> or CSS to control the emphasis of text, not the italic tag. Usage of the italic tag will reduce your grades.

Underlining Text

It is possible to underline text in web pages, however this practice has become outdated due primarily to the fact that most users expect underlined text to be a Hyperlink – see next chapter. Also, the HTML standards list the underline tags <U></U> as deprecated, meaning that browsers will likely still make text within the <U> tag underlined, but authors should no longer use this function. As such, whilst it is possible to underline text, you are recommended against doing so.

HTML Good Practice 5 – Do not underline text unless it is a hyperlink

For the purposes of the exercises in this workbook and any related assessments, you should not underline any non-hyperlink text. Doing so will likely decrease your grade.

Combining Tags

It is possible to combine tags together to make enhanced use of different formatting commands. The <STRONG> and <EM> tags from the sections previously are a good example. It is possible to create a word or words that are both bold and emphasised.

For example, try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <HTML>
 <HEAD>
 <TITLE> put your title here </TITLE>
 </HEAD>
 <BODY>
 <P>This example shows how to <STRONG><EM>combine</EM></STRONG> tags to enhanced effect.</P>
 </BODY>
 </HTML>

Image:strongem.png

When using multiple tags together, HTML standards dictate that the closing tags must be in the reverse order of the opening tags. This is easier to demonstrate than it is to discuss.

This is correct NOTE: do not type this in - it is to demonstrate the concept, but it won't render anything

<TAG1><TAG2><TAG3>This is my text</TAG3></TAG2></TAG1>

Anything else, like the following, is wrong:

<TAG1><TAG2><TAG3>This is my text</TAG1></TAG2></TAG3>

HTML Good Practice 6 – Combination tags must be closed correctly

For the purposes of the exercises in this workbook and any related assessments, you should close all combination tags in the correct order. Failure to do so will likely decrease your grade.

Controlling Fonts using CSS

In previous versions of HTML, the way to control the font, size and colour of text was by using the <FONT></FONT> tags. These are now deprecated in version 4.01 of the HTML specifications – meaning basically that as authors you should not use them any more. It is now considered better practice to control the font of a section of text by using the style attribute of the section, for example, using the paragraph tag <P> we can control the font, size and colour by controlling the style attribute of the paragraph tag.

These examples use a form of CSS called "Inline Style."

Almost all tags can have a style attribute. The style attribute controls the visual representation of the contents of that tag and is very versatile. The value of the style attribute is written in a slightly different language to HTML and this subtle difference is critical in getting the desired results.

Inline Style syntax is always in lowercase, and is made up of one or many names and values – the name is the thing we want to change and the value is what we want to change it to.

font-family

font-family

The font-family component of style controls which font the text is rendered in.

<P style="font-family: Arial">Hello, this should be in Arial Font</P>

This example shows how we can change the font of the paragraph by changing the font-family name to the value Arial. Notice carefully the syntax of the style attribute’s value. The font-family has a ":" symbol after it, followed by the name of the font we want to use. We can change the font to any font that is installed on the machine that the web page will be viewed on NOT the fonts available on the author’s machine. For example, if the author has the Tahoma font installed on their machine, and the viewer of that web page does not, the text will appear in the default font for their browser. Also, font changes should be used sparingly – too many fonts make a page difficult to read – try to stick to some basic fonts that are available to most visitors (Courier, Arial, and Times.) Most PC users using Microsoft Operating systems should have Georgia and Verdana also – those fonts are specifically designed for ease of reading when displayed on a webpage, and have been used in this workbook.

  • TIME TO PRACTICE
    • Change some fonts in your long web page exercise used previously.

HTML Good Practice 7 – Use fonts changes sparingly and carefully

As not all fonts can be rendered by the users of your web pages, try to stick to a few common fonts and use them sparingly. Failure to do this may result in lower grades for assessments.

font-size

font-size

The size of the font can also be controlled; however this facility comes with many warnings.Let’s discuss the warnings first.

Whilst you can change the size of the text in your document you should refrain from specifying exact sizes. Exact or fixed sizes of fonts (like 20 point text for example) cause problems for users using alternative browsers, like hand-held computers that have small screens. Most browsers allow the user to change the size of all the text in a web site – Internet Explorer’s and Firefox's text-size control can be found in the View menu for example. This helps people with sight difficulties see web pages more clearly. However, using fixed or exact sizes stops this function from working.

It is much better to use what we call relative or proportional sizing in your fonts (and other web page elements that we’ll discuss later) as it offers the user more control over how they want to see your site, but still allows you the author the power to make one section of text bigger than another.

In order to use proportional sizing, CSS provides some keywords to control sizes or you can control the size as a percentage (with 100% being "normal" size). Following are some examples:

<P style="font-size: small">This is small</P> <P style="font-size: large">This is large</P>

Font size keywords are xx-small, x-small, small, medium, large, x-large, and xx-large

<P style="font-size: 75%">This is small</P><P style="font-size: 150%">This is large</P>
  • TIME TO PRACTICE
    • Change some font sizes in your long web page example previously used. Use the text size changer in your browser (on the View menu in Internet Explorer) to see how the user can control part of the experience of viewing your pages.

HTML Good Practice 8 – Font sizes should be proportional, not fixed

Font sizing can cause problems for your users. Use font sizes that the user can control. Failure to do this may result in lower grades for assessments.

color

color

As in the previous examples of font family and sizes, colour is also controllable but also has warnings.

The first warning is that some colours are usually reserved in web pages to show hyperlink usage (covered in next chapter) – your browser will show hyperlinks in blue underlined text most of the time, and visited links are usually shown in purple underlined text. You should not use these colours in your content to avoid confusion. Also, not everyone can view colours in their browsers – some only show web pages in grey or even black and white. Finally, care must be taken with the colour of text in context with the colour of the background. White text on white background will be invisible, yellow text on white is very difficult to read, as is dark blue on black, and so on. Make sure there is sufficient contrast (difference between text colour and background) in your colour scheme, and also avoid colours which are difficult to read for long periods (bright green on bright pink is hard on the eyes.)

There are two different ways of setting the colour of text – using colour names or colour hex values. The HTML specification provides for a basic set of 16 colour names

aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, yellow

but most PC users can display millions of colours. A good resource to find the codes and names of colours can be found at [1]

<P style="color: aqua">This is a light-blue-ish</P><P style="color: red">This is red</P>
<P style="color: #8A2Be2">This is violet</P><P style="color: #D2691E">This is chocolate</P>
  • HINT: Notice how the word "color" is spelt in American English?
  • TIME TO PRACTICE
    • Using your long text web page, experiment with using colours in your page, perhaps combining them with heading tags to have coloured headings. Remember not to use blue or purple with underlined text.

Combination Font Changes

It was shown earlier how multiple tags could be used to combine effects on text. In a similar fashion, it is possible to combine multiple effects of the attributes of the font tag, however the way this is done is different for the inline CSS.

<P style="font-family: Georgia; font-size: large; color: green">This is the text to be displayed</P>

Notice how the different aspects of the change (family, size and color) are all separated with ";" symbols – this is critical or none of the changes will work.

  • TIME TO PRACTICE
    • Using your long text web page, experiment with using AT LEAST ONE example of a multiple attribute font tag

Ready to move on?

A considerable number of new topics have been introduced in this chapter. It is VITAL that you experiment with these extensively before progressing. Understanding of the topics in this chapter is CRITICAL to your success in all areas of web development, as well as ALL of the assessments for this module.

If you're happy that you've practiced enough with the content in this section, try HTML:Hyperlinks

Related Pages

<categorytree mode="pages">HTML</categorytree>