![]() |
HTML for Newcomers |
Home
Index
Introduction Lesson 2 |
Using this Lesson
If you've completed the Introduction you know how to use this Lesson. If not, remember:
, or any
term to see an
now)Adding style with CSS
In Lesson 1, you marked up the plain text notes (from the Introduction). In this Lesson, we'll use the file you created, and add some rules to it. It's better to use your own file, but if you don't have it, download this example
active.htm file now.
In , we'll add a little style to active.htm with rules. If you're unsure of what means, hover your mouse over
for a brief description.
Remember that you can 
Open active.htm in Notepad
If you have Notepad's window open from the previous Lesson, you can skip .
Notepad will not be the application registered to open HTM files (this will be your default browser's job), and so we'll need to use Notepad :
and purple text are InfoBox cues.
We use a distinctive, bold purple cue where it's more appropriate. Either way, you'll know there are more details you can read whenever you want, simply by hovering your mouse over this device.HTML=HyperText Markup Language is a system of tags to specify text layout. A tag looks like <b>M</b>, which says: put the letter M in bold. A <b> says start making what follows bold, and a </b> says stop. Tags usually come in start/stop pairs. It's how we put bold letters in "HyperText Markup Language". A browser (such as Internet Explorer or Mozilla) doesn't show the tags, it obeys them. An editor like Notepad merely shows the tags along with other text.
Cascading Style Sheets are a system of rules to add style. HTML includes tags for basic style features, but it was never meant to handle fine details. So CSS was added. CSS codes supersede old HTML tags. "Style Sheet" is an old name for a Print firm's style manual. And "Cascading" because you can add new rules over old ones. Together, the rules apply in an order called the Cascade.
In some Windows versions (eg Windows Millennium), the Open With option is shown at the first Right-click, so you won't need to use the Shift +Right-click method that we explain in .
Note Remember to use the Notepad window in its default size.
. Using Notepad in a restored window means you can see the CueWindow properly.
When several windows are open, only one has focus (it has a standard dark blue title bar). The window with focus is the one that receives any keystrokes from your keyboard. Where a window has keyboard input boxes, the box with focus is the one that typed characters will appear in. An easy way to shift focus is to click on a window (or its Taskbar button), or click in an input box. You can also use Alt Tab to put up a menu that will cycle the focus through all windows.
View as HTML
If your HTML view window is still open from Lesson 1, skip this re-opening step. If not, the below will help you open your active.htm document in a Browser window scaled to fit the Lesson's window layout, as before.
Click in the box, enter filename – or browse
Enter full path, or click Browse and locate your file:
Either enter the to the active.htm file in the box; Or use the Browse button to find it; then click on it; then click the Open button (you can use the Files of type pull-down box to look only for *.htm,*.html files to make it easier to locate).
Document as HTML
With the path to your file in the box, click the View as HTML button. A new window opens, placed so you can compare your progress at each Step with a .
The Lesson plan:
Using CSS rules
Lesson 1 dealt with basic , now let's add some Style with . We'll split the job into four logical stages, and learn some useful rules. This is the plan:
With rules, you can easily change fonts and colours. You can even create rules to change (or add to) the rendering of standard tags, as we'll soon see,
CSS rules can be kept in a separate file
A useful way to work with rules is to keep them in a separate file, which all your pages can use. That means you can change a style feature throughout an entire website by changing its rule in only one file. For our present purpose, however, we'll put our rules in the , where they apply to the whole of the current document.
Body settings:
Font and colour
Changing overall settings for the document:
The tag
In the of our document, we can specify rules enclosed between and </> tags. These rules will apply to the whole document :
Remember to get help
Use the help built into this page (it's there whether you stay online or
, or any
term to see an
for details and cross-referencesRules for the
We used the standard tag to mark our document's main content. We can alter the meaning of this tag with a rule. For example, we can add a rule about what font to use, and it will apply to all text between and .
To change any tag's meaning, this is what we need to do:
Specifying
We can choose which font the will use with the
This shows a capital "H" in a sans-serif and a serifed font together. Arial is a Microsoft font very similar to the standard sans-serif font Helvetica.
The document Body is where the main content of the page goes. In simple pages, it may be just paragraphs of text. In more complex cases there will be text, images, tables, and a variety of other content. The Body is contained between <body> and </body> tags.
The Head is where the properties of a document, such as Title, Keywords (for search engines), Style details, Script functions, and many other administrative elements go. Most of these are not seen by the user. The Head is contained between <head> and </head> tags.
Any problems?
Browsers are very strict on spelling and punctuation in rules. They will ignore any rules that are misspelt or mispunctuated, and may even ignore (correct) rules that follow them. So, if the HTML view of your document doesn't respond to any rules you add, check all the spelling of tags and rules carefully.
And remember: you must save Notepad changes before HTML view will show them.
Specifying
We can add a
is the full height of a font from the top of an ascender to the bottom of a descender. The em-height works relative to the font size in use, so 1.5em means use 1½ times the current height. It's best not to set an absolute size (in points=1/72 inch), since some people might have set their browser to use bigger text. If we use em-height, it's relative to whatever base size they've set. In older usage, an em was the width of the font's letter m .
And now for COLOUR ...
You specify colours with in one of five ways (we'll use the first):

Remember to get help
Use the help built into this page (it's there whether you stay online or
, or any
term to see an
for details and cross-referencesFor this Lesson, we'll use the colour names
For precise work, you'll probably use one of the numerical mixing methods, but for quickly testing a few ideas, the (faintly whimsical) Colour Names are quite useful.
We can specify the text colour with the rule, and the document's background colour with the
Try :yellow;:chocolate. See what you think :
A matter of taste
Colours are a matter of taste. The 140 Colour Names make an easy way to test colour combinations. Click the Colours button on the right; it will re-display the list in a small window that you can drag around, and see with your Notepad window open.
You may want to play with research a few changes of and
We'll wait here until you've finished researching ...
Spans of inline text:
Using Text-Level tags
Next, we'll look at how to change the appearance of individual letters, words, or phrases. This is called "Text-Level" tagging.
Emboldening text
The tag can be used to make a span of text look bold. Try using it to make the technical term: stand out :
The user-definable Text-Level tag:
Here, emboldening isn't very effective. We could use a rule to add a colour change to the tag. But there's a more versatile way. We'll try it with another term.
We can tag ing with the user-definable tag, . It won't appear to have any effect until we define some rules for it :
Adding rules to
We can now add rules to the tag. Let's add a colour rule :
Note If a rule used inside a tag needs Space s use quotes around the rule, eg:
More research ...
You may want to try some other colour combinations. Use the button to see the Colour Names list again (in a small window). Remember to save any changes in Notepad before refreshing the HTML view window. Remember, too, that you can read the RGB decimal values of any colour in the list by hovering your mouse over its colour block.
Adding further rules
We can make our ing appear in bold as well. We could do it with :
Either would work. Notice that you must nest tags properly, enclosing both open and close of the inner tag within the outer. So, for example, this version would be wrong:
The rule
However, we won't use , instead we'll use a new rule:
Text in a Block:
Block-Level tagging and re-usable es
Now we'll turn our attention to text in Blocks:
A Block means any chunk of content that you want to stand alone. It could be:
But this quote: "Then felt I like some watcher of the skies when a new planet swims into his ken; or like stout Cortez when with eagle eyes he stared at the Pacific – and with all his men looked at each other with a wild surmise – silent, upon a peak in Darien" is not a Block (although it's quite long), since it's only a part of this sentence. However, this entire paragraph (Keats and all) is a Block.
The user-definable Block-Level tag:
We've used three Block-Level tags: , and . Each has a special function, but we could use rules to give them a quite different function, if we chose.
However, also has a user-definable Block-Level tag: (the Block equivalent of ). If we need a special block layout, it's often better to create a that meets our requirements, rather than alter one of the standard Block-Level tags.
Let's try out this idea by placing the heading of our notes in a user-definable tag instead of the tag we're using at the moment :
Using rules in a
We could add a centre rule inside the new tag. We could, but we won't. Instead we'll define a for our tag to use. A is a set of one or more rules, and we define it in the section of the document .
We must choose a name for our – we'll call it myclass. Not very informative, but amidst all the other syntax, myclass will remind us that it's a word we chose. For now, we'll just put a
Specify in
We need to tell the Browser to use myclass for our . The instruction for this goes inside the tag :
Re-using myclass
The purpose of creating a of rules is to re-use it elsewhere in the document. Let's put the footnote in a myclass , too :
Copyright symbol ©
While we're working on the footnote, let's add a pair of © symbols to it. We can do that with the
Adding rules to myclass
Now we have two Blocks (heading and footnote) assigned to myclass. If we add rules to myclass, then all Blocks assigned to it will change simultaneously.
Remember that rules can be loaded from a file. Re-usable es mean that you could re-style an entire Website with one rule change in one file.
Let's change the text of myclass and embolden it, too :
More research ...
If you're not keen on oldlace you may want to research other colours.
And finally...
Customising text
On a slightly less serious note:
Signing off
Let's sign off with a custom at the end of our document :
Centre and change font
We'll add rules on
Add real style
We can add more rules. We could add them in same style= section. However, some Browsers (such as Internet Explorer) can handle separate style= sections on new lines, which keeps the document tidier and the lines shorter.
Note If you're not using Internet Explorer, keep all these extra rules inside the "quotes" of our first style= section and all on one long line – or they'll be ignored.
We'll use a rule that we haven't met before:
It's up to you ...
Of course, the precise colours for your "own work" are still up to you ...
pull-down box
Take the time to glance through the s for the tags and rules we've met. The Course Reference pull-down box grows automatically with each Lesson, so it now includes all the terms from Lessons 1 and 2, and has extra cross-references.
And finally ...
That ends this short Course in and . Try the to finish off.
The Lesson summary
Remember: Preview
Do
Review. We'll end with a Review of what we've learnt:
That's all for now
This short demonstration Course in HTML for Newcomers is offered as practical example of our interactive writing techniques. We hope you found it interesting and informative. You can read more about our work and the services we offer.