HTML Primer
Basic formatting: Tags and attributes
An HTML tag is surrounded by < > brackets. Most tags come as a set with an "opening" form (Example: <div>) and a "closing" form with a / (Example: </div>) An individual tag inside of an HTML document is called an "element".
HTML tags nest together much like nesting boxes: tags can contain other tags inside of them between the opening and closing forms of the tag. Some tags can't contain other tags and these tags do not need closing tags.
Tags can also have attributes, which come in the form of name="value". For instance, when you are making a link to another page using the a
tag, your code will be:
<a href="http://www.dreamwidth.org">Dreamwidth</a>
In this instance, the href part of the opening tag is an attribute. The text inside of the link tag is what shows up as the link, and then the tag closes with the </a>
form of the tag.
Some important tag attributes are classes and ids. A class is a label that one can place on a tag, and an id is a unique identifier. You can then use these class and ID tags to apply CSS rules to an element-- see the CSS Primer for more information.
Inline versus block elements
Tag Overview
Html, Head and Body; comments
The basic structure of an HTML page uses these tags.
- <html> -- The HTML tag contains everything else.
- <head> -- The head tag doesn't contain tags that show up on the page. Instead, it includes other resource files, the title of the page, and other metadata tags.
- <body> -- The body tag contains all of the tags that actually show up on the page.
Example of the HTML, head, and body tags put together in their proper order:
<html> <head><title>My Page</title></head> <body> <p>Content of my page</p> </body> </html>
Notice that inside the head tag, we are using a title tag, and inside the body we are using a paragraph tag.
Head tags
Divs
Div tags mostly exist to give structure to an HTML page--they are usually used with class or ID attributes. They are block elements.
Spans
A span tag is mostly used to contain inline elements--again, usually used with class or ID attributes. Span tags are inline elements.
Paragraphs and Break tags
- <p> -- This tag defines a paragraph in the text.
- <br /> -- This tag defines a line break
Links
The link tag is the <a> tag:
<a href="http://www.dreamwidth.org">Dreamwidth</a>
Images
The image tag is how to include an image in an HTML document:
<img src="http://s.dreamwidth.org/img/silk/identity/user.png" width="16" height="16">
Headings
- <h1>
- <h2>
- <h3>
- <h4>
- <h5>
- <h6>
Lists
There are a few different types of lists.
Unordered and ordered lists
- <ol> -- This tag surrounds list elements in ordered lists.
- <ul> -- This tag surrounds list elements in unordered lists.
- <li> -- This is the tag for an individual list element in both ordered and unordered lists
Definition list
Not used too commonly:
- <dl> -- The tag that contains all of the list elements
- <dt> -- The title part of the definition in the list
- <dd> -- The definition part of the definition in the list.
Tables
- <table>
- <thead>
- <tbody>
- <tr>
- <th>
- <td>
Quoting
- <blockquote<
- <q<