Understanding HTML Syntax and Rules


The HTML language is simple language for describing Web page content. HTML stands for Hyper Text Markup Language. HTML is not a programming language, it is a markup language. A markup language is a set of markup tags to describe web pages. HTML rules, called syntax, govern the way in which code is written. Learning the right way to write your code can save you confusion and errors later.

Syntax Rules Reminders:

  1. Writing HTML
  2. Elements
  3. Attributes and Values
  4. Entities
  5. Avoid Syntax Errors

Writing HTML

The instructions you write in HTML are called tags. Tags are surrounded by angle brackets <>. You can write tags in upper or lower case. Many users prefer to write their tags in uppercase to make them easier to identify on the document page. If you create a page in XHTML, a stricter variation of HTML, you need to use lowercase letters for your tags.


Elements

Elements identify the different parts of your HTML document. For example, <BODY> and </BODY> are tags defining the body text element on a page. The browser reads any text between the two tags as part of the body element. Many elements use tag pairs, an opening and closing tag, such as <P> and </P> , while others, such as the Image tag <IMG> do not. Closing tags must always include a slash (/).


Attributes and Values

Each element has unique attributes you can assign. Many attributes require that you set a value, such as a measurement or specification. For example, you can set an alternative text for an image by using the ALT attribute and set the value enclosed in quotes <IMG ALT="This is a ruler GIF image" >. Remember that values are always enclosed in quotation marks and appear within the element's start tag.

.

Entities

Any special characters you add to a page, such as a copyright symbol or a fraction, are called entities. HTML use entities to represent characters not readily available on the keyboard. All entities are preceded with an ampersand and ended with a semicolon (;). For example, to add a copyright symbol to your page, the code looks like this: & copy.


Avoid Syntax Errors

To avoid HTML erros, always take time to proofread your code. Make sure you have brackets on your tags and that your closing tags include a slash. You must surround any values you define for attributes with quotation marks. It also helps to write your closing tags in reverse order of the opening tags. For example: <P> <B> My Text </B></P>. To help make your HTML readable, consider using new lines to enter code instead of running everything together on one long line. Using white space can also help, without increasing the file size.

Source: Simplified Creating Web Pages with HTML 3rd Edition by Sherry Willard Kinkoph
webmaster:jmistal@losmedanos.edu