Hyper Text Markup Language: What Is HTML?
Hyper Text Markup Language: What Is HTML?
What is HTML?
HTML Tags
The purpose of a web browser (like Internet Explorer or Firefox) is to read HTML
documents and display them as web pages. The browser does not display the HTML tags, but
uses the tags to interpret the content of the page:
Example
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Example Explained
The text between <html> and </html> describes the web page
The text between <body> and </body> is the visible page content
The text between <h1> and </h1> is displayed as a heading
The text between <p> and </p> is displayed as a paragraph
1. <!--This is a comment.-->
The comment tag is used to insert a comment in the source code. A comment will be
ignored by the browser. You can use comments to explain your code, which can help you when
you edit the source code at a later date.
2. <html>
The <html> tag tells the browser that this is an HTML document.
The html element is the outermost element in HTML and XHTML documents. The html element
is also known as the root element.
3. <head>
The head element is a container for all the head elements. Elements inside <head> can
include scripts, instruct the browser where to find style sheets, provide meta information, and
more.
The following tags can be added to the head section: <base>, <link>, <meta>, <script>,
<style>, and <title>.
4. <title>
The <title> tag defines the title of the document. The title element:
defines a title in the browser toolbar
provides a title for the page when it is added to favorites
displays a title for the page in search-engine results
5. <body>
The body element defines the document's body.The body element contains
all the contents of an HTML document, such as text, hyperlinks, images, tables,
lists, etc.
Attributes of BODY TAG:
BACKGROUND: The background attribute specifies a background image for a document.
Syntax: <body background="value">
TEXT: The text attribute specifies the color of the text in a document.
Syntax: <body text="value">
LINK: The link attribute specifies the default color of unvisited links in a document.
Syntax: <body link="value">
VLINK: The vlink attribute specifies the color of visited links in a document
.Syntax: <body vlink="value">
6. <font>
The font tag specifies the font face, font size, and font color of text.
FACE: The face attribute specifies the font of the text inside a font element.
Syntax : <font face="value">
SIZE: The size attribute specifies the size of the text inside a font element.
Syntax: <font size="value">
8. Scripting tags
Subscript: The <sub> tag defines subscript text. Subscript text appears half a character
below the baseline. Subscript text can be used for chemical formulas, like H2O.
Syntax : <sub>text</sub>
Superscript: The <sup> tag defines superscript text. Superscript text appears half a
character above the baseline. Superscript text can be used for footnotes, like WWW[1].
Syntax: <sup>text</sup>
9. Paragraphs(<p>&</p>)
The <p> tag defines a paragraph. The ‘p’ element automatically creates some space
before and after itself. The space is automatically applied by the browser, or you can specify it in
a style sheet.
10. Emphasis(<em>&</em>)
To emphasis certain words in paragraphs, simply enclose them between an <em> tag and
an </em> tag. Emphasized words appear in italics when Web-page is shown.
1. HTML Link Syntax: The HTML code for a link is simple. It looks like this:
Or, create a link to the "Useful Tips Section" from another page:
<a href="http://www.w3schools.com/html_links.htm#tips">
Visit the Useful Tips Section</a>
NOTE: If a browser does not find the named anchor specified, it goes to the top of the
document. No error occurs.
The alt attribute provides alternative information for an image if a user for some reason
cannot view it (because of slow connection, an error in the src attribute, or if the user uses a
screen reader).
OUTPUT:
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2
HTML Table Headers
Header information in a table are defined with the <th> tag. The text in a th element will
be bold and centered.
OUTPUT:
HTML Forms
HTML forms are used to pass data to a server.A form can contain input elements like text
fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists,
textarea, fieldset and label elements.
<form>
.
input elements
.
</form>
Text Fields
<input type="text" /> defines a one-line input field that a user can enter text into.
EX: <form>
First name: <input type="text" name="firstname" /><br />
Last name: <input type="text" name="lastname" />
</form>
OUTPUT:
Note: The form itself is not visible. Also note that the default width of a text field is 20
characters.
Password Field
<input type="password" /> defines a password field.
EX: <form>
Password: <input type="password" name="pwd" />
</form>
OUTPUT:
Note: The characters in a password field are masked (shown as asterisks or circles).
Radio Buttons
<input type="radio" /> defines a radio button. Radio buttons let a user select ONLY ONE one of
a limited number of choices.
EX: <form>
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female
</form>
OUTPUT:
Check Boxes
<input type="checkbox" /> defines a checkbox. Checkboxes let a user select ONE or MORE
options of a limited number of choices.
EX: <form>
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br />
<input type="checkbox" name="vehicle" value="Car" /> I have a car
</form>
OUTPUT:
Submit Button
<input type="submit" /> defines a submit button.
A submit button is used to send form data to a server. The data is sent to the page
specified in the form's action attribute. The file defined in the action attribute usually does
something with the received input.
OUTPUT:
HTML Frames
With frames, you can display more than one HTML document in the same browser
window. Each HTML document is called a frame, and each frame is independent of the others.
<frameset cols="25%,75%">
<frame src="frame_a.htm" />
<frame src="frame_b.htm" />
</frameset>
Note: The frameset column size can also be set in pixels (cols="200,500"), and one of the
columns can be set to use the remaining space, with an asterisk (cols="25%,*").
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
When tags like <font>, and color attributes were added to the HTML 3.2 specification, it
started a nightmare for web developers. Development of large web sites, where fonts and color
information were added to every single page, became a long and expensive process.
To solve this problem, the World Wide Web Consortium (W3C) created CSS.
In HTML 4.0, all formatting could be removed from the HTML document, and stored in a
separate CSS file. All browsers support CSS today.
What is CSS?
CSS Syntax
A CSS rule has two main parts: a selector, and one or more declarations:
3. The property is the style attribute you want to change. Each property has a value.
CSS Example
CSS declarations always ends with a semicolon, and declaration groups are surrounded
by curly brackets:
EX: p{color:red;text-align:center;}
To make the CSS more readable, you can put one declaration on each line, like this:
p
{
color:red;
text-align:center;
}
EX:
<html>
<head>
<style type="text/css">
p{color:red;text-align:center;}
</style>
</head>
<body>
<p>Hello World!</p>
<p>This paragraph is styled with CSS.</p>
</body>
</html>
OUTPUT:
Hello World!
This paragraph is styled with CSS.
CSS Comments
Comments are used to explain your code, and may help you when you edit the source
code at a later date. Comments are ignored by browsers.
A CSS comment begins with "/*", and ends with "*/", like this:
/*This is a comment*/
Each page must link to the style sheet using the <link> tag. The <link> tag goes inside
the head section:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
An external style sheet can be written in any text editor. The file should not contain any
html tags.
Your style sheet should be saved with a .css extension. An example of a style sheet file is
shown below:
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("images/back40.gif");}
Do not leave spaces between the property value and the units! "margin-left:20 px" (instead of
"margin-left:20px") will work in IE, but not in Firefox or Opera.
You define internal styles in the head section of an HTML page, by using the <style> tag,
like this:
<head>
<style type="text/css">
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("images/back40.gif");}
</style>
</head>
Inline Styles
Inline style uses the style attribute in the relevant tag. The style attribute can contain any
CSS property.
An inline style loses many of the advantages of style sheets by mixing content with
presentation.
The example shows how to change the color and the left margin of a paragraph:
EX: <p style="color:sienna;margin-left:20px">This is a paragraph.</p>
If the page with the internal style sheet also links to the external style sheet the properties
for h3 will be:
color:red;
text-align:right;
font-size:20pt;
The color is inherited from the external style sheet and the text-alignment and the font-
size is replaced by the internal style sheet.
Grouping Selectors
In style sheets there are often elements with the same style.
h1{color:green;}
h2{color:green;}
p{color:green;}
To minimize the code, you can group selectors. Separate each selector with a comma.
In the example below we have grouped the selectors from the code above:
h1,h2,p
{
color:green;
}