Web Design 1 - HTML Lesson 15 - Special Characters & Comments

Special Characters

In your HTML code there will be times you want to use a special character - as in foreign languages, or other types of symbols such as mathematical ones.

To do this you cannot just type them into your code. Why not? One reason is that certain characters are set aside to mean something in the programming code. For example - what if you need to show this < or ; in your page?

So, to get around this we use what are often called escape characters and most of the time in HTML the format is as as follows

& + code + ;

one example is &lt;

This tells the browser to display a less than character in that space

The code on my page might look like this:

<p>Is this statement true? 20 &lt; 50</p>

What should display on the screen would be: Is this statement true? 20 < 50

What about symbols used in languages? Here the lowercase u with an umlaut is coded &uuml;

<p>Viel Gl&uuml;ck heute</p>

Viel Glück heute

(Which means Good Luck today in German)

Another popular code is to create a non-breaking space. You may have noticed that if you put more than one space between words in your code that when it displays there is only one. How do you add extra spaces if you want them? Just put in the code for a non-breaking space:

&nbsp;

These can be strung together if you need several spaces:

&nbsp;&nbsp;&nbsp;&nbsp;

Where can you find these codes?

There are many online sources - here are just a few:

Comments

When writing programs it is often helpful to add comments in your code - these can be notes to yourself to help keep track of what is going on, or notes that would be used by someone else who may need to updating your code. Think of working in a company where there is a team of software engineers working on a project - often your code must be clearly understood by someone else. In fact, as programs get more complex comments are necessary to help understand the flow of the logic.

To add a comment in html:

<!-- This is a comment to demonstrate how to correctly format this -->

Notice that the opening tag for a comment has an ! point: <!--
While the closing tag does not: -->

The text contained within a comment is only visible to the person reading the code. The text does not show up on the screen at all.

So you can have multiple lines of comments as long as the opening and ending tags are included

<!-- this section explains how to use comments
while this may look like a line of text it will only show up in the actual html code
and not on the screen and I can use this to leave notes for myself and others
-->


Assignment for HTML Lesson 15

  • Write a paragraph of text that includes at least 3 different special characters.

  • Add another paragraph (it can be one line) that has a phrase in another language.

  • Within your page add comments to at least 3 different areas
    - explain what your code doing or use them to keep track of the sections of the tables