HTML Syntax

Syntax of HTML Tags and Attributes

HTML is made up of tags (technically called elements) and attributes on those tags that are written to a text file with the extension .html or .htm. But how does a web browser know which parts of the document are the tags and attributes and which are not?

What is an HTML Tag

An HTML tag is written in the following format:


The tag name is surrounded by a less-than sign (<) and a greater-than sign (>).

These two characters tell the web browser that everything inside them is an HTML tag.

The closing tag is written:


The browser knows that that is a closing tag because of the slash that precedes the tag name.

Inside the opening and closing tags is the web page contents. This is often what will display on the web page. For example, to indicate that “HTML” is an abbreviation, you would write:


Some tags are singleton tags – these tags are stand alone, and don't enclose any content within them. They are written as just the tag, or in XHTML with a slash inside the tag at the end. For example, a line break:

HTML: <br>
XHTML: <br />

What are HTML Attributes

HTML attributes are modifiers that are added to HTML tags. They are separated from the tag name in the opening tag by a space, and the value of the attribute is assigned with an equal sign.

<tagname attribute=value>

If an attribute value has spaces or other special characters in it, you should enclose the value in quotation marks (").

<tagname attribute="value with spaces">

XHTML requires that you surround all attributes in quotes.

You can put attributes on any HTML tag, both singleton and regular tags. For example:

<a href="">About Web Design</a>
<hr style="color:black;">

A few attributes don't require any value, these can be written in HTML with the “=value” portion removed. In XHTML, you must include a value, usually a repeat of the attribute name. For example:

HTML: <input disabled>
XHTML: <input disabled="disabled">