HTML Primer

From Dreamwidth Notes
Revision as of 22:04, 23 April 2011 by Foxfirefey (Talk | contribs)

Jump to: navigation, search

The following primer tries to give a short overview of HTML. See also the CSS Primer and Browser Developing Tools.

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. For instance, here is an image to Dreamwidth's little username icon:

<img src="http://s.dreamwidth.org/img/silk/identity/user.png" width="16" height="16" />

Headings

Headings are block level elements meant to organize a page into sections (think of entries in a table of contents)--the smaller the number, the higher the heading is in the hierarchy.

  • <h1> -- the highest level, usually the biggest in size
  • <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> -- Goes around the entire table
  • <caption> -- Gives the table a caption
  • <thead> -- This optionally goes around rows in the head of the table
  • <tbody> -- This optionally goes around rows in the body of the table
  • <tr> -- Indicates a row
  • <th> -- Table cell that is a header
  • <td> -- Normal table cell

Quoting

  • <blockquote> -- use for longer, block quotes
  • <q> -- use for shorter, inline quotes

References