Saturday, 26 March 2016

HTML ASCII Codes

HTML ASCII Codes



There are 27 = 128 printable characters which can be represented by different 7-BIT ASCII codes. Another set of characters are not for HTML representation but they are devised to control hardware.
Following tables list down all the 7-BIT ASCII codes and their equivalent HTML Entity Codes.
If you want to see equivalent HEX, OCT and extended set of ASCII codes then check next chapter.
7-BIT Printable ASCII Characters:
ASCII Characters
Description
HTML Entity Codes

space
 
!
exclamation mark
!
"
quotation mark
"
#
number sign
#
$
dollar sign
$
%
percent sign
%
&
ampersand
&
'
apostrophe
'
(
left parenthesis
(
)
right parenthesis
)
*
asterisk
*
+
plus sign
+
,
comma
,
-
hyphen
-
.
period
.
/
slash
/
0
digit 0
0
1
digit 1
1
2
digit 2
2
3
digit 3
3
4
digit 4
4
5
digit 5
5
6
digit 6
6
7
digit 7
7
8
digit 8
8
9
digit 9
9
:
colon
:
;
semicolon
&#59;
<
less-than
&#60;
=
equals-to
&#61;
>
greater-than
&#62;
?
question mark
&#63;
@
at sign
&#64;
A
uppercase A
&#65;
B
uppercase B
&#66;
C
uppercase C
&#67;
D
uppercase D
&#68;
E
uppercase E
&#69;
F
uppercase F
&#70;
G
uppercase G
&#71;
H
uppercase H
&#72;
I
uppercase I
&#73;
J
uppercase J
&#74;
K
uppercase K
&#75;
L
uppercase L
&#76;
M
uppercase M
&#77;
N
uppercase N
&#78;
O
uppercase O
&#79;
P
uppercase P
&#80;
Q
uppercase Q
&#81;
R
uppercase R
&#82;
S
uppercase S
&#83;
T
uppercase T
&#84;
U
uppercase U
&#85;
V
uppercase V
&#86;
W
uppercase W
&#87;
X
uppercase X
&#88;
Y
uppercase Y
&#89;
Z
uppercase Z
&#90;
[
left square bracket
&#91;
\
backslash
&#92;
]
right square bracket
&#93;
^
caret
&#94;
_
underscore
&#95;
`
grave accent
&#96;
a
lowercase a
&#97;
b
lowercase b
&#98;
c
lowercase c
&#99;
d
lowercase d
&#100;
e
lowercase e
&#101;
f
lowercase f
&#102;
g
lowercase g
&#103;
h
lowercase h
&#104;
i
lowercase i
&#105;
j
lowercase j
&#106;
k
lowercase k
&#107;
l
lowercase l
&#108;
m
lowercase m
&#109;
n
lowercase n
&#110;
o
lowercase o
&#111;
p
lowercase p
&#112;
q
lowercase q
&#113;
r
lowercase r
&#114;
s
lowercase s
&#115;
t
lowercase t
&#116;
u
lowercase u
&#117;
v
lowercase v
&#118;
w
lowercase w
&#119;
x
lowercase x
&#120;
y
lowercase y
&#121;
z
lowercase z
&#122;
{
left curly brace
&#123;
|
vertical bar
&#124;
}
right curly brace
&#125;
~
tilde
&#126;
 
7-BIT ASCII Device Control Characters
ASCII Characters
Description
HTML Entity Codes
NUL
null character
&#00;
SOH
start of header
&#01;
STX
start of text
&#02;
ETX
end of text
&#03;
EOT
end of transmission
&#04;
ENQ
enquiry
&#05;
ACK
acknowledge
&#06;
BEL
bell (ring)
&#07;
BS
backspace
&#08;
HT
horizontal tab
&#09;
LF
line feed
&#10;
VT
vertical tab
&#11;
FF
form feed
&#12;
CR
carriage return
&#13;
SO
shift out
&#14;
SI
shift in
&#15;
DLE
data link escape
&#16;
DC1
device control 1
&#17;
DC2
device control 2
&#18;
DC3
device control 3
&#19;
DC4
device control 4
&#20;
NAK
negative acknowledge
&#21;
SYN
synchronize
&#22;
ETB
end transmission block
&#23;
CAN
cancel *
&#24;
EM
end of medium
&#25;
SUB
substitute
&#26;
ESC
escape
&#27;
FS
file separator
&#28;
GS
group separator
&#29;
RS
record separator
&#30;
US
unit separator
&#31;
DEL
delete (rubout)
&#127

HTML Fonts Reference

HTML Fonts Reference



Fonts are specific to platform. You will have different look and feel of a web page on different machines running different operating systems like Windows, Linux or Mac iOS. Here we are giving a list of fonts which are available in various operating systems.
HTML <font> tag is deprecated in version 4.0 onwards and now all fonts are set by using CSS. Here is the simple syntax of setting font of a body of web page.
body { font-family: "new century schoolbook"; }

or

<body style="font-family:new century schoolbook;">
Example
<!DOCTYPE html>
<html>
<head>
<title>Font Setting Using CSS</title>
</head>
<body>

<p>Change any of the style and try it.</p>
<div style="font-family:verdana;">This is demo for font family</div>
<br />
<div style="font-size:120%;">This is demo for font size</div>
<br />
<div style="font-size:14pt;">This is demo for font size</div>

</body>
</html>
This will produce following result:
Change any of the style and try it.
This is demo for font family

This is demo for font size

This is demo for font size
Fonts for Microsoft Systems
Font
Font
Font
Andale Mono
Arial
Arial Bold
Arial Italic
Arial Bold Italic
Arial Black
Comic Sans MS
Comic Sans MS Bold
Courier New
Courier New Bold
Courier New Italic
Courier New Bold Italic
Georgia
Georgia Bold
Georgia Italic
Georgia Bold Italic
Impact
Lucida Console
Lucida Sans Unicode
Marlett
Minion Web
Symbol
Times New Roman
Times New Roman Bold
Times New Roman Italic
Times New Roman Bold Italic
Tahoma
Trebuchet MS
Trebuchet MS Bold
Trebuchet MS Italic
Trebuchet MS Bold Italic
Verdana
Verdana Bold
Verdana Italic
Verdana Bold Italic
Webdings
You can check example fonts here: Microsoft Fonts Examples. You can also have more information on Microsoft Fonts at http://www.microsoft.com/typography/fonts.
Fonts for Macintosh Systems
Following is the list of fonts supported by Macintosh System 7 and higher versions
Font
Font
Font
American Typewriter
Andale Mono
Apple Chancery
Arial
Arial Black
Brush Script
Baskerville
Big Caslon
Comic Sans MS
Copperplate
Courier New
Gill Sans
Futura
Herculanum
Impact
Lucida Grande
Marker Felt
Optima
Trebuchet MS
Verdana
Webdings
Palatino
Symbol
Times
Osaka
Papyrus
Times New Roman
Textile
Zapf Dingbats
Zapfino
Techno
Hoefler Text
Skia
Hoefler Text Ornaments
Capitals
Charcoal
Gadget
Sand

You can check example fonts here: Mac Fonts Examples
Fonts for Unix Systems
Following is the list of fonts supported by most Unix System variants
Font
Font
Font
Charter
Clean
Courier
Fixed
Helvetica
Lucida
Lucida bright
Lucida Typewriter
New Century Schoolbook
Symbol
Terminal
Times
Utopia


You can check example fonts here: Unix Fonts Examples

HTML Event Reference

HTML Events Reference



When users visit your website, they do things like click various links, bring mouse over text and images etc. These are examples of what we call events in Javascript and VBScript terminologies.
We can write our event handlers using Javascript or VBScript and can specify some actions to be taken against these events. Though these are the events but they will be specified as attributes for the HTML tags.
The HTML 4.01 specification had defined 19 events but later HTML-5 has added many other events which we have listed down here:
Events
HTML-5
Description
onafterprint
HTML-5
Triggers after a document is printed
onbeforeprint
HTML-5
Triggers before a document is printed
onbeforeonload
HTML-5
Triggers before a document loads
onerror
HTML-5
Triggers when an error occurs
onhaschange
HTML-5
Triggers when a document has changed
onload

Triggers when a document loads
onmessage
HTML-5
Triggers when a message is triggered
onoffline
HTML-5
Triggers when a document goes offline
ononline
HTML-5
Triggers when a document comes online
onpagehide
HTML-5
Triggers when a window is hidden
onpageshow
HTML-5
Triggers when a window becomes visible
onpopstate
HTML-5
Triggers when a window's history changes
onredo
HTML-5
Triggers when a document performs a redo
onresize
HTML-5
Triggers when a window is resized
onstorage
HTML-5
Triggers when a document loads
onundo
HTML-5
Triggers when a document performs an undo
onunload

Triggers when a user leaves the document
 
Form Events

Following tags have been introduced in older versions of HTML but all the tags marked with HTML-5 are part of HTML-5.
Events
HTML-5
Description
onblur

Triggers when a window loses focus
onchange

Triggers when an element changes
oncontextmenu
HTML-5
Triggers when a context menu is triggered
onfocus

Triggers when a window gets focus
onformchange
HTML-5
Triggers when a form changes
onforminput
HTML-5
Triggers when a form gets user input
oninput
HTML-5
Triggers when an element gets user input
oninvalid
HTML-5
Triggers when an element is invalid
onreset

Triggers when a form is reset
onselect

Triggers when an element is selected
onsubmit

Triggers when a form is submitted
 
Keyboard Events
Events
HTML-5
Description
onkeydown

Triggers when a key is pressed
onkeypress

Triggers when a key is pressed and released
onkeyup

Triggers when a key is released
 
Mouse Events
Following tags have been introduced in older versions of HTML but all the tags marked with HTML-5 are part of HTML-5.
Events
HTML-5
Description
onclick

Triggers on a mouse click
ondblclick

Triggers on a mouse double-click
ondrag
HTML-5
Triggers when an element is dragged
ondragend
HTML-5
Triggers at the end of a drag operation
ondragenter
HTML-5
Triggers when an element has been dragged to a valid drop target
ondragleave
HTML-5
Triggers when an element leaves a valid drop target
ondragover
HTML-5
Triggers when an element is being dragged over a valid drop target
ondragstart
HTML-5
Triggers at the start of a drag operation
ondrop
HTML-5
Triggers when a dragged element is being dropped
onmousedown

Triggers when a mouse button is pressed
onmousemove

Triggers when the mouse pointer moves
onmouseout

Triggers when the mouse pointer moves out of an element
onmouseover

Triggers when the mouse pointer moves over an element
onmouseup

Triggers when a mouse button is released
onmousewheel
HTML-5
Triggers when the mouse wheel is being rotated
onscroll
HTML-5
Triggers when an element's scrollbar is being scrolled
 
Media Events
Following tags have been introduced in older versions of HTML but all the tags marked with HTML-5 are part of HTML-5.
Events
HTML-5
Description
onabort

Triggers on an abort event
oncanplay
HTML-5
Triggers when a media can start play, but might has to stop for buffering
oncanplaythrough
HTML-5
Triggers when a media can be played to the end, without stopping for buffering
ondurationchange
HTML-5
Triggers when the length of a media is changed
onemptied
HTML-5
Triggers when a media resource element suddenly becomes empty.
onended
HTML-5
Triggers when a media has reached the end
onerror
HTML-5
Triggers when an error occurs
onloadeddata
HTML-5
Triggers when media data is loaded
onloadedmetadata
HTML-5
Triggers when the duration and other media data of a media element is loaded
onloadstart
HTML-5
Triggers when the browser starts loading the media data
onpause
HTML-5
Triggers when media data is paused
onplay
HTML-5
Triggers when media data is going to start playing
onplaying
HTML-5
Triggers when media data has started playing
onprogress
HTML-5
Triggers when the browser is fetching the media data
onratechange
HTML-5
Triggers when the playing rate of media data has changed
onreadystatechange
HTML-5
Triggers when the ready-state changes
onseeked
HTML-5
Triggers when the seeking attribute of a media element is no longer true, and the seeking has ended
onseeking
HTML-5
Triggers when the seeking attribute of a media element is true, and the seeking has begun
onstalled
HTML-5
Triggers when there is an error in fetching media data
onsuspend
HTML-5
Triggers when the browser has been fetching media data, but stopped before the entire media file was fetched
ontimeupdate
HTML-5
Triggers when media changes its playing position
onvolumechange
HTML-5
Triggers when a media changes the volume, also when volume is set to "mute"

HTML Attribute Reference

HTML Attribute Reference



There are few HTML attributes which are standard and associated to all the HTML tags. These attributes are listed here with a brief description.

Global Attributes

Not valid in base, head, html, meta, param, script, style, and title elements.

Attribute
HTML-5
Description
accesskey

Specifies a shortcut key for an element to be used in place of keyboard.
class

The class of the element
contenteditable
Yes
Boolean attribute to specify whether the element is editable or not.
contextmenu
Yes
Specifies a context menu for an element.
data-*
Yes
Used to store custom data associated with the element.
draggable
Yes
Boolean attribute to specify whether the element can be dragged or not.
dropzone
Yes
Specifies whether the dragged data is copied, moved, or linked, when dropped.
hidden
Yes
Specifies whether element should be visible or not.
id

A unique id for the element
spellcheck
Yes
Specifies if the element must have it's spelling or grammar checked.
style

An inline style definition
tabindex

Specifies the tab order of an element.
title

A text to display in a tool tip
translate
Yes
Boolean attribute specifies whether the content of an element should be translated or not


Language Attributes
The lang attribute indicates the language being used for the enclosed content. The language is identified using the ISO standard language abbreviations, such as fr for French, en for English, and so on. RFC 1766 (http://www.ietf.org/rfc/rfc1766.txt) describes these codes and their formats.

Not valid in base, br, frame, frameset, hr, iframe, param, and script elements.

Attribute
Value
Description
dir
ltr | rtl
Sets the text direction
lang
language_code
Sets the language code

HTML Tag Reference

HTML Tag Reference




Following tags have been introduced in older versions of HTML but all the tags marked with HTML-5 are part of HTML-5.
Tag
Description
Version
<!--...-->
Specifies a comment

<!DOCTYPE>
Specifies the document type

<a>
Specifies an anchor

<abbr>
Specifies an abbreviation

<acronym>
Specifies an acronym

<address>
Specifies an address element

<applet>
Deprecated. Specifies an applet

<area>
Specifies an area inside an image map

<article>
Specifies an article
HTML-5
<aside>
Specifies some content loosely related to the page content. If it is removed, the remaining content still makes sense
HTML-5
<audio>
Specifies a sound content
HTML-5
<b>
Specifies bold text

<base>
Specifies a base URL for all the links in a page

<basefont>
Deprecated. Specifies a base font

<bdo>
Specifies the direction of text display

<bdi>
Represents text that must be isolated from its surrounding for bidirectional text formatting. It allows embedding a span of text with a different, or unknown, directionality
HTML-5
<bgsound>
Specifies background music

<big>
Specifies big text

<blink>
Specifies a text which blinks

<blockquote>
Specifies a long quotation

<body>
Specifies the body element

<br>
Inserts a single line break

<button>
Specifies a push button

<canvas>
For making graphics with a script
HTML-5
<caption>
Specifies a table caption

<center>
Deprecated. Specifies centered text

<cite>
Specifies a citation

<code>
Specifies computer code text

<col>
Specifies attributes for table columns

<colgroup>
Specifies groups of table columns

<comment>
Puts a comment in the document

<datalist>
A list of options for input values
HTML-5
<dd>
Specifies a definition description

<del>
Specifies deleted text

<dfn>
Specifies a definition term

<dialog>
Specifies a dialog box or window
HTML-5
<dir>
Deprecated. Specifies a directory list

<div>
Specifies a section in a document

<dl>
Specifies a definition list

<dt>
Specifies a definition term

<em>
Specifies emphasized text

<embed>
Specifies a container for an external (non-HTML) application
HTML-5
<fieldset>
Specifies a fieldset

<figcaption>
Specifies a caption for a <figure> element
HTML-5
<figure>
Specifies self-contained content
HTML-5
<font>
Deprecated. Specifies text font, size, and color

<footer>
Specifies a footer for a document or section
HTML-5
<form>
Specifies a form

<frame>
Specifies a sub window (a frame)

<frameset>
Specifies a set of frames

<h1> to <h6>
Specifies header 1 to header 6

<head>
Specifies information about the document

<header>
Specifies a header for a document or section
HTML-5
<hr>
Specifies a horizontal rule

<html>
Specifies an html document

<i>
Specifies italic text

<iframe>
Specifies an inline sub window (frame)

<ilayer>
Specifies an inline layer

<img>
Specifies an image

<input>
Specifies an input field

<ins>
Specifies inserted text

<isindex>
Deprecated. Specifies a single-line input field

<kbd>
Specifies keyboard text

<keygen>
Generate key information in a form
HTML-5
<label>
Specifies a label for a form control

<layer>
Specifies a layer

<legend>
Specifies a title in a fieldset

<li>
Specifies a list item

<link>
Specifies a resource reference

<main>
Specifies the main or important content in the document. There is only one element in the document
HTML-5
<map>
Specifies an image map

<mark>
Specifies a text highlighted for reference purposes, that is for its relevance in another context
HTML-5
<marquee>
Creates a scrolling-text marquee

<menu>
Deprecated. Specifies a menu list

<menuitem>
Specifies a command/menu item that the user can invoke from a popup menu
HTML-5
<meta>
Specifies meta data of an html document which is not displayed on the page

<meter>
Specifies a scalar measurement within a known range (a gauge)

<multicol>
Specifies a multicolumn text flow

<nav>
Specifies a section that contains only navigation links
HTML-5
<nobr>
No breaks allowed in the enclosed text

<noembed>
Specifies content to be presented by browsers that do not support the <embed> tag

<noframes>
Specifies a noframe section

<noscript>
Specifies a noscript section

<object>
Specifies an embedded object

<ol>
Specifies an ordered list

<optgroup>
Specifies an option group

<option>
Specifies an option in a drop-down list

<output>
Specifies the result of a calculation
HTML-5
<p>
Specifies a paragraph

<param>
Specifies a parameter for an object

<plaintext>
Deprecated. Render the remainder of the document as preformatted plain text

<pre>
Specifies preformatted text

<progress>
Specifies a completion progress of a task
HTML-5
<q>
Specifies a short quotation

<rp>
Specifies to show browsers that do not support the ruby element
HTML-5
<rt>
Specifies an text ruby annotation
HTML-5
<ruby>
Specifies an ruby annotation
HTML-5
<s>
Deprecated. Specifies strikethrough text

<samp>
Specifies sample computer code

<script>
Specifies a script

<section>
Specifies a section in a document
HTML-5
<select>
Specifies a selectable list

<spacer>
Specifies a white space

<small>
Specifies small text

<source>
Specifies a media resources for media elements, defined inside video or audio elements
HTML-5
<span>
Specifies a section in a document

<strike>
Deprecated. Specifies strikethrough text

<strong>
Specifies strong text

<style>
Specifies a style definition

<sub>
Specifies subscripted text

<summary>
Specifies a summary, caption, or legend for a given <details>
HTML-5
<sup>
Specifies superscripted text

<table>
Specifies a table

<tbody>
Specifies a table body

<td>
Specifies a table cell

<textarea>
Specifies a text area

<tfoot>
Specifies a table footer

<th>
Specifies a table heading

<thead>
Specifies a table header

<time>
Specifies a date and time <details>
HTML-5
<title>
Specifies the document title

<tr>
Specifies a table row

<track>
Specifies a text tracks used in mediaplayers
HTML-5
<tt>
Specifies teletype text

<u>
Deprecated. Specifies underlined text

<ul>
Specifies an unordered list

<var>
Specifies a variable

<video>
Specifies a text tracks used in mediaplayers
HTML-5
<wbr>
Indicates a potential word break point within a <nobr> section

<xmp>
Deprecated. Specifies preformatted text

HTML Layouts

HTML Layouts



A webpage layout is very important to give better look to your website. It takes considerable time to design a website's layout with great look and feel.

Now a days, all modern websites are using CSS and Javascript based framework to come up with responsive and dynamic websites but you can create a good layout using simple HTML tables or division tags in combination with other formatting tags. This chapter will give you few examples on how to create a simple but working layout for your webpage using pure HTML and its attributes.

HTML Layout - Using Tables

The simplest and most popular way of creating layouts is using HTML <table> tag. These tables are arranged in columns and rows, so you can utilize these rows and columns in whatever way you like.

Example

For example, the following HTML layout example is achieved using a table with 3 rows and 2 columns but the header and footer column spans both columns using the colspan attribute:

<!DOCTYPE html>
<html>
<head>
<title>HTML Layout using Tables</title>
</head>
<body>
<table width="100%" border="0">
  <tr>
    <td colspan="2" bgcolor="#b5dcb3">
      <h1>This is Web Page Main title</h1>
    </td>
  </tr>
  <tr valign="top">
    <td bgcolor="#aaa" width="50">
      <b>Main Menu</b><br />
      HTML<br />
      PHP<br />
      PERL...
    </td>
    <td bgcolor="#eee" width="100" height="200">
        Technical and Managerial Tutorials
    </td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#b5dcb3">
      <center>
      Copyright © 2015 sambhajikarad.info
      </center>
    </td>
  </tr>
</table>
</body>
</html>
This will produce following result:

This is Web Page Main title
Main Menu
HTML
PHP
PERL...
Technical and Managerial Tutorials

Copyright © 2015 sambhajikarad.info

Multiuple Columns Layout - Using Tables

You can design your webpage to put your web content in multiple pages. You can keep your content in middle column and you can use left column to use menu and right column can be used to put advertisement or some other stuff. This layout will be very similar to what we have at our website tutorialspoint.com.

Example

Here is an example to create three column layout:

<!DOCTYPE html>
<html>
<head>
<title>Three Column HTML Layout</title>
</head>
<body>
<table width="100%" border="0">
  <tr valign="top">
    <td bgcolor="#aaa" width="20%">
      <b>Main Menu</b><br />
      HTML<br />
      PHP<br />
      PERL...
    </td>
    <td bgcolor="#b5dcb3" height="200" width="60%">
        Technical and Managerial Tutorials
    </td>
    <td bgcolor="#aaa" width="20%">
      <b>Right Menu</b><br />
      HTML<br />
      PHP<br />
      PERL...
    </td>
   </tr>
<table>
</body>
</html>
This will produce following result:

Main Menu
HTML
PHP
PERL...


Technical and Managerial Tutorials

Right Menu
HTML
PHP
PERL...

HTML Layouts - Using DIV, SPAN
The <div> element is a block level element used for grouping HTML elements. While the <div> tag is a block-level element, the HTML <span> element is used for grouping elements at an inline level.

Although we can achieve pretty nice layouts with HTML tables, but tables weren't really designed as a layout tool. Tables are more suited to presenting tabular data.

Note: This example makes use of Cascading Style Sheet (CSS), so before understanding this example you need to have a better understanding on how CSS works.

Example

Here we will try to achieve same result using <div> tag along with CSS, whatever you have achieved using <table> tag in previous example.

<!DOCTYPE html>
<html>
<head>
<title>HTML Layouts using DIV, SPAN</title>
</head>
<body>
<div style="width:100%">
  <div style="background-color:#b5dcb3; width:100%">
      <h1>This is Web Page Main title</h1>
  </div>
  <div style="background-color:#aaa; height:200px;width:100px;float:left;">
      <div><b>Main Menu</b></div>
      HTML<br />
      PHP<br />
      PERL...
  </div>
  <div style="background-color:#eee; height:200px;width:350px;float:left;">
    <p>Technical and Managerial Tutorials</p>
  </div>
  <div style="background-color:#aaa; height:200px;width:100px;float:right;">
      <div><b>Right Menu</b></div>
      HTML<br />
      PHP<br />
      PERL...
  </div>
  <div style="background-color:#b5dcb3;clear:both">
  <center>
      Copyright © 2015 sambhajikarad.info
  </center>
  </div>
</div>
</body>
</html>
This will produce following result:

This is Web Page Main title

Main Menu
HTML
PHP
PERL...

Technical and Managerial Tutorials

Right Menu
HTML
PHP
PERL...

Copyright © 2015 sambhajikarad.info

You can create better layout using DIV, SPAN along with CSS. For more information on CSS, please refer to CSS Tutorial

HTML JavaScript

HTML JavaScript



A script is a small piece of program that can add interactivity to your website. For example, a script could generate a pop-up alert box message, or provide a dropdown menu. This script could be written using Javascript or VBScript.

You can write various small functions, called event handlers using any of the scripting language and then you can trigger those functions using HTML attributes.

Now a days only Javascript and associated frameworks are being used by most of the web developers, VBScript is not even supported by various major browsers.

You can keep Javascript code in a separate file and then include it whereever it's needed, or you can define functionality inside HTML document itself. Let's see both the cases one by one with suitable examples.

External Javascript

If you are going to define a functionality which will be used in various HTML documents then it's better to keep that functionality in a separate Javascript file and then include that file in your HTML documents. A Javascript file will have extension as .js and it will be included in HTML files using <script> tag.

Example

Consider we define a small function using Javascript in script.js which has following code:

function Hello()
{
    alert("Hello, World");
}

Now let's make use of the above external Javascript file in our following HTML document:

<!DOCTYPE html>
<html>
<head>
<title>Javascript External Script</title>
<script src="/html/script.js" type="text/javascript"/></script>
</head>
<body>
<input type="button" onclick="Hello();" name="ok" value="Click Me"  />
</body>
</html>
This will produce following result, where you can try to click on the given button:

Click Me


Internal Script

You can write your script code directly into your HTML document. Usually we keep script code in header of the document using <script> tag, otherwise there is no restriction and you can put your source code anywhere in the document but inside <script> tag.

Example

<!DOCTYPE html>
<html>
<head>
<title>Javascript Internal Script</title>
<base href="http://www.tutorialspoint.com/" />
<script type="text/javascript">
function Hello(){
   alert("Hello, World");
}
</script>
</head>
<body>
<input type="button" onclick="Hello();" name="ok" value="Click Me"  />
</body>
</html>
This will produce following result, where you can try to click on the given button:

Click Me

Event Handlers

Event handlers are nothing but simply defined functions which can be called against any mouse or keyboard event. You can define your business logic inside your event handler which can vary from a single to 1000s of line code.

Following example explains how to write an event handler. Let's write one simple function EventHandler() in the header of the document. We will call this function when any user brings mouse over a paragraph.

<!DOCTYPE html>
<html>
<head>
<title>Event Handlers Example</title>
<base href="http://www.sambhajikarad.com/" />
<script type="text/javascript">
function EventHandler(){
   alert("I'm event handler!!");
}
</script>
</head>
<body>
<p onmouseover="EventHandler();">Bring your mouse here to see an alert</p>
</body>
</html>

Now this will produce following result. Bring your mouse over this line and see the result:
Bring your mouse here to see an alert

Hide Scripts from Older Browsers

Although most (if not all) browsers these days support Javascript, but still some older browsers don't. If a browser doesn't support JavaScript, instead of running your script, it would display the code to the user. To prevent this, you can simply place HTML comments around the script as shown below.
JavaScript Example:

<script type="text/javascript">
<!--
document.write("Hello Javascript!");
//-->
</script>

VBScript Example:
<script type="text/vbscript">
<!--
document.write("Hello VBScript!")
'-->
</script>

The <noscript> Element

You can also provide alternative info to the users whose browsers don't support scripts and for those users who have disabled script option their browsers. You can do this using the <noscript> tag.
JavaScript Example:

<script type="text/javascript">
<!--
document.write("Hello Javascript!");
//-->
</script>
<noscript>Your browser does not support Javascript!</noscript>
VBScript Example:
<script type="text/vbscript">
<!--
document.write("Hello VBScript!")
'-->
</script>
<noscript>Your browser does not support VBScript!</noscript>

Default Scripting Language
There may be a situation when you will include multiple script files and ultimately using multiple <script> tags. You can specify a default scripting language for all your script tags. This saves you from specifying the language everytime you use a script tag within the page. Below is the example:

<meta http-equiv="Content-Script-Type" content="text/JavaScript" />

Note that you can still override the default by specifying a language within the script tag.

HTML Style Sheets

HTML Style Sheet



Cascading Style Sheets (CSS) describe how documents are presented on screens, in print, or perhaps how they are pronounced. W3C has actively promoted the use of style sheets on the Web since the Consortium was founded in 1994.

Cascading Style Sheets (CSS) provide easy and effective alternatives to specify various attributes for the HTML tags. Using CSS, you can specify a number of style properties for a given HTML element. Each property has a name and a value, separated by a colon (:). Each property declaration is separated by a semi-colon (;).

Example

First let's consider an example of HTML document which makes use of <font> tag and associated attributes to specify text color and font size:

<!DOCTYPE html>
<html>
<head>
<title>HTML CSS</title>
</head>
<body>
<p><font color="green" size="5">Hello, World!</font></p>
</body>
</html>
We can re-write above example with the help of Style Sheet as follows:
<!DOCTYPE html>
<html>
<head>
<title>HTML CSS</title>
</head>
<body>
<p style="color:green;font-size:24px;">Hello, World!</p>
</body>
</html>
This will produce following result:
Hello, World!

You can use CSS in three ways in your HTML document:

  • External Style Sheet - Define style sheet rules in a separate .css file and then include that file in your HTML document using HTML <link> tag.
  • Internal Style Sheet - Define style sheet rules in header section of the HTML document using <style> tag.
  • Inline Style Sheet - Define style sheet rules directly along-with the HTML elements using style attribute.

Let's see all the three cases one by one with the help of suitable examples.

External Style Sheet
If you need to use your style sheet to various pages, then its always recommended to define a common style sheet in a separate file. A cascading style sheet file will have extension as .css and it will be included in HTML files using <link> tag.

Example
Consider we define a style sheet file style.css which has following rules:

.red{
   color: red;
}
.thick{
   font-size:20px;
}
.green{
   color:green;
}
Here we defined three CSS rules which will be applicable to three different classes defined for the HTML tags. I suggest you should not bother about how these rules are being defined because you will learn them while studying CSS. Now let's make use of the above external CSS file in our following HTML document:

<!DOCTYPE html>
<html>
<head>
<title>HTML External CSS</title>
<link rel="stylesheet" type="text/css" href="/html/style.css">
</head>
<body>
<p class="red">This is red</p>

<p class="thick">This is thick</p>

<p class="green">This is green</p>

<p class="thick green">This is thick and green</p>
</body>
</html>
This will produce following result:

This is red

This is thick

This is green

This is thick and green

Internal Style Sheet

If you want to apply Style Sheet rules to a single document only then you can include those rules in header section of the HTML document using <style> tag.
Rules defined in internal style sheet overrides the rules defined in an external CSS file.

Example

Let's re-write above example once again, but here we will write style sheet rules in the same HTML document using <style> tag:

<!DOCTYPE html>
<html>
<head>
<title>HTML Internal CSS</title>
<style type="text/css">
.red{
   color: red;
}
.thick{
   font-size:20px;
}
.green{
   color:green;
}
</style>
</head>
<body>
<p class="red">This is red</p>

<p class="thick">This is thick</p>

<p class="green">This is green</p>

<p class="thick green">This is thick and green</p>
</body>
</html>
This will produce following result:

This is red

This is thick

This is green

This is thick and green

Inline Style Sheet

You can apply style sheet rules directly to any HTML element using style attribute of the relevant tag. This should be done only when you are interested to make a particular change in any HTML element only.

Rules defined inline with the element overrides the rules defined in an external CSS file as well as the rules defined in <style> element.

Example

Let's re-write above example once again, but here we will write style sheet rules along with the HTML elements using style attribute of those elements.

<!DOCTYPE html>
<html>
<head>
<title>HTML Inline CSS</title>
</head>
<body>
<p style="color:red;">This is red</p>

<p style="font-size:20px;">This is thick</p>

<p style="color:green;">This is green</p>

<p style="color:green;font-size:20px;">This is thick and green</p>
</body>
</html>
This will produce following result:

This is red

This is thick

This is green

This is thick and green

HTML Header

HTML Header



We have learnt that a typical HTML document will have following structure:

Document declaration tag
<html>
   <head>
       Document header related tags
   </head>

   <body>
       Document body related tags
   </body>
</html>
This chapter will give a little more detail about header part which is represented by HTML <head> tag. The <head> tag is a container of various important tags like <title>, <meta>, <link>, <base>, <style>, <script>, and <noscript> tags.

The HTML <title> Tag

The HTML <title> tag is used for specifying the title of the HTML document. Following is an example to give a title to an HTML document:

<!DOCTYPE html>
<html>
<head>
<title>HTML Title Tag Example</title>
</head>
<body>
<p>Hello, World!</p>
</body>
</html>
This will produce following result:

Hello, World!

The HTML <meta> Tag

The HTML <meta> tag is used to provide metadata about the HTML document which includes information about page expiry, page author, list of keywords, page description etc.

Following are few of the important usages of <meta> tag inside an HTML document:

<!DOCTYPE html>
<html>
<head>
<title>HTML Meta Tag Example</title>

<!-- Provide list of keywords -->
<meta name="keywords" content="C, C++, Java, PHP, Perl, Python">

<!-- Provide description of the page -->
<meta name="description" content="Simply Easy Learning by Tutorials Point">

<!-- Author information -->
<meta name="author" content="Tutorials Point">

<!-- Page content type -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!-- Page refreshing delay -->
<meta http-equiv="refresh" content="30">

<!-- Page expiry -->
<meta http-equiv="expires" content="Wed, 21 June 2006 14:25:27 GMT">

<!-- Tag to tell robots not to index the content of a page -->
<meta name="robots" content="noindex, nofollow">

</head>
<body>
<p>Hello, World!</p>
</body>
</html>
This will produce following result:

Hello, World!

The HTML <base> Tag

The HTML <base> tag is used for specifying the base URL for all relative URLs in a page, which means all the other URLs will be concatenated into base URL while locating for the given item.

For example, all the given pages and images will be searched after prefixing the given URLs with base URL http://www.tutorialspoint.com/ directory:

<!DOCTYPE html>
<html>
<head>
<title>HTML Base Tag Example</title>
<base href="http://www.tutorialspoint.com/" />
</head>
<body>

<img src="/images/logo.png" alt="Logo Image"/>
<a href="/html/index.htm" title="HTML Tutorial"/>HTML Tutorial</a>

</body>
</html>
This will produce following result:

HTML Tutorial

But if you change base URL to something else, for example, if base URL is http://www.tutorialspoint.com/home then image and other given links will become like http://www.tutorialspoint.com/home/images/logo.png and http://www.tutorialspoint.com/home/html/index.htm

The HTML <link> Tag

The HTML <link> tag is used to specify relationships between the current document and external resource. Following is an example to link an external style sheet file available in css sub-directory within web root:

<!DOCTYPE html>
<html>
<head>
<title>HTML link Tag Example</title>
<base href="http://www.tutorialspoint.com/" />
<link rel="stylesheet" type="text/css" href="/css/style.css">
</head>
<body>
<p>Hello, World!</p>
</body>
</html>
This will produce following result:

Hello, World!

The HTML <style> Tag

The HTML <style> tag is used to specify style sheet for the current HTML document. Following is an example to define few style sheet rules inside <style> tag:

<!DOCTYPE html>
<html>
<head>
<title>HTML style Tag Example</title>
<base href="http://www.tutorialspoint.com/" />
<style type="text/css">
.myclass{
   background-color: #aaa;
   padding: 10px;
}
</style>
</head>
<body>
<p class="myclass">Hello, World!</p>
</body>
</html>
This will produce following result:
Hello, World!

The HTML <script> Tag

The HTML <script> tag is used to include either external script file or to define internal script for the HTML document. Following is an example where we are using Javascript to define a simple Javascript function:

<!DOCTYPE html>
<html>
<head>
<title>HTML script Tag Example</title>
<base href="http://www.tutorialspoint.com/" />
<script type="text/javascript">
function Hello(){
   alert("Hello, World");
}
</script>
</head>
<body>
<input type="button" onclick="Hello();" name="ok" value="OK"  />
</body>
</html>
This will produce following result, where you can try to click on the given button:

OK

HTML Marquees

HTML Marquees



An HTML marquee is a scrolling piece of text displayed either horizontally across or vertically down your webpage depending on the settings. This is created by using HTML <marquees> tag.

Note: The HTML <marquee> tag may not be supported by various browsers so its not recommended to rely on this tag, instead you can use Javascript and CSS to create such effects.

Syntax
A simple syntax to use HTML <marquee> tag is as follows:

<marquee attribute_name="attribute_value"....more attributes>

One or more lines or text message or image

</marquee>

The <marquee> Tag Attributes
Following is the list of important attributes which can be used with <marquee> tag.

Attribute
Description

width
This specifies the width of the marquee. This can be a value like 10 or 20% etc.
height
This specifies the height of the marquee. This can be a value like 10 or 20% etc.
direction
This specifies the direction in which marquee should scroll. This can be a value like up, down, left or right.
behavior
This specifies the type of scrolling of the marquee. This can have a value like scroll, slide and alternate.
scrolldelay
This specifies how long to delay between each jump. This will have a value like 10 etc.
scrollamount
This specifies the speed of marquee text. This can have a value like 10 etc.
loop
This specifies how many times to loop. The default value is INFINITE, which means that the marquee loops endlessly.
bgcolor
This specifies background color in terms of color name or color hex value.
hspace
This specifies horizontal space around the marquee. This can be a value like 10 or 20% etc.
vspace
This specifies vertical space around the marquee. This can be a value like 10 or 20% etc.


Below are few examples to demonstrate the usage of marquee tag.

Examples - 1

<!DOCTYPE html>
<html>
<head>
<title>HTML marquee Tag</title>
</head>
<body>
<marquee>This is basic example of marquee</marquee>
</body>
</html>
This will produce following result:

The Basic Example of Marquee

Examples - 2

<!DOCTYPE html>
<html>
<head>
<title>HTML marquee Tag</title>
</head>
<body>
<marquee width="50%">This example will take only 50% width</marquee>
</body>
</html>
This will produce following result:

This example will take only 50% width

Examples - 3

<!DOCTYPE html>
<html>
<head>
<title>HTML marquee Tag</title>
</head>
<body>
<marquee direction="right">This text will scroll from left to right</marquee>
</body>
</html>
This will produce following result:

This text will scroll from left to right

Examples - 4

<!DOCTYPE html>
<html>
<head>
<title>HTML marquee Tag</title>
</head>
<body>
<marquee direction="up">This text will scroll from bottom to up</marquee>
</body>
</html>
This will produce following result:

This text will scroll from bottom to up