TAG & ELEMENTS
Tags & Elements
Tags and elements are the most basic ingredient of html. They make up an html document in the same way as bricks and mortar make up a building.
The most basic part of Html documents are tags. What ever you write in html is enclosed in tags.
A tag start with a < angle bracket, then has a name and ends with > angle bracket.
<p> is a tag used to start a pragraph.
<html> is a tag used to mark the begining of an html document.
Elements are basically tags combined to do a desired function. Html documents are made up of elements, which can be of two types.
- Non-Empty Elements.
- Empty Elements.
- A Non-Empty element starts with an opening tag, then have some content, followed by a closing tag.
<p>This is a pragraph </p>
This is an elements formed by <p> tags. You can see there is an opening tag <p>, then the content and then the closing tag </p>
An Empty element only has a single tag.
This is a line breaking element which consists of only one tag. Note that these elements have only one tag, which ends with a slash / followd by an angle bracket >.
Elements with in Elements
Nested elements are elements with in elements. You may have guessed that before. In html you place elements with in other elements, usually more than once.
This is <bold>bold</bold> text.
Here <bold> element is nested with in <p> tag.
The following example contains four HTML elements (
<h1>My First Heading</h1>
<p>My first paragraph.</p>
Attributes & Values
Attributes are combined or associated with elements. They give additional information or details about the element they are used with.
Every attribute is accompanied with a value, which describes how much or in what way that attriubute will effect the element.
Attributes and their values are always given in the opening tag of an element.
Attributes are used in the following way,
Here align attribute is used with value “center”. This wil position the contents of the <p> tag in the center.
Here border attribute is used with value “1”. This will draw a border around the table.
Here id attribute is used with value “message”. This will assign the <p> tag an id named “message”.
The href Attribute
<a> tag defines a hyperlink. The
href attribute specifies the URL of the page the link goes to:
We Suggest: Always Quote Attribute Values
The HTML standard does not require quotes around attribute values.
However, W3C recommends quotes in HTML, and demands quotes for stricter document types like XHTML.
Single or Double Quotes?
Double quotes around attribute values are the most common in HTML, but single quotes can also be used.
In some situations, when the attribute value itself contains double quotes, it is necessary to use single quotes: