HTML

1.2 HTML Syntax

Contents

Overview

HTML syntax is comprised of three different parts:

  1. Elements: an individual object on a page. The <p> specifies a paragraph:
  2. 
    
    <p>Hello World!</p>
    
    
  3. Attributes: a property of an element. The align attribute can be used to align the text in the paragraph (this will not work without a value — see next bullet):
  4. 
    
    <p align>Hello World!</p>
    
    
  5. Values: the value or setting for the attribute. By setting align to right, the text will align to the right hand side of the page:
  6. 
    
    <p align="right">Hello World!</p>
    
    

Feel free to try this in the HTML file you previously created.

Form vs. Function

Understand that the format of the code you are writing does not impact how it is rendered in the browser. For example, if you skip a line in your HTML code, the text rendered in the browser will not match it. You need to use the HTML element (i.e. the instruction) to skip that line. The same goes for spaces and alignment. With that said, you do want to be thoughtful with your formatting of your code. You should get in the habit of:

  1. Skipping every other line
  2. Indenting nested, structural elements

Many times you will not be the only person editing the file so you want to be consistent with your formatting. If you are coming on to an already-existing project, the project manager/agency will give you their style guide.

The Starting Four

Every HTML document should start with these four basic elements:



<html>
<head>
	<title>The title of my webpage</title>
</head>
<body>
	Visible content in the browser
</body>
</html>

Here is a brief description of each:

HTML5 Requirements

To bring your HTML document up to the HTML5 standard, the W3C requires you to insert three more pieces of code:



<!doctype html>
<html lang="en">
<head>
	<title>The title of my webpage</title>
	<meta charset="utf-8" />
</head>
<body>
	Visible content in the browser
</body>
</html>

Here is a brief description of each: