HTML - Forms
HTML - Forms
HTML - Forms
HTML Forms are required, when you want to collect some data from the site visitor. For example, during
user registration you would like to collect information such as name, email address, credit card, etc.
A form will take input from the site visitor and then will post it to a back-end application such as CGI, ASP
Script or PHP script etc. The back-end application will perform required processing on the passed data
based on defined business logic inside the application.
There are various form elements available like text fields, textarea fields, drop-down menus, radio buttons,
checkboxes, etc.
The HTML <form> tag is used to create an HTML form and it has following syntax −
Form Attributes
Apart from common attributes, following is a list of the most frequently used form attributes −
https://www.tutorialspoint.com/html/html_forms.htm 1/14
2/4/2020 HTML - Forms - Tutorialspoint
1
action
2
method
Method to be used to upload data. The most frequently used are GET and POST methods.
3
target
Specify the target window or frame where the result of the script will be displayed. It takes
values like _blank, _self, _parent etc.
4
enctype
You can use the enctype attribute to specify how the browser encodes the data before it sends
it to the server. Possible values are −
Note − You can refer to Perl & CGI for a detail on how form data upload works.
There are different types of form controls that you can use to collect data using HTML form −
Text Input Controls
Checkboxes Controls
Radio Box Controls
Select Box Controls
File Select boxes
Hidden Controls
Clickable Buttons
Submit and Reset Button
https://www.tutorialspoint.com/html/html_forms.htm 2/14
2/4/2020 HTML - Forms - Tutorialspoint
Single-line text input controls − This control is used for items that require only one line of user
input, such as search boxes or names. They are created using HTML <input> tag.
Password input controls − This is also a single-line text input but it masks the character as
soon as a user enters it. They are also created using HTMl <input> tag.
Multi-line text input controls − This is used when the user is required to give details that may
be longer than a single sentence. Multi-line input controls are created using HTML <textarea>
tag.
Example
Here is a basic example of a single-line text input used to take first name and last name −
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Text Input Control</title>
</head>
<body>
<form >
First name: <input type = "text" name = "first_name" />
<br>
Last name: <input type = "text" name = "last_name" />
</form>
</body>
</html>
First name:
Last name:
Attributes
Following is the list of attributes for <input> tag for creating text field.
https://www.tutorialspoint.com/html/html_forms.htm 3/14
2/4/2020 HTML - Forms - Tutorialspoint
1
type
Indicates the type of input control and for text input control it will be set to text.
2
name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
3
value
4
size
5
maxlength
Allows to specify the maximum number of characters a user can enter into the text box.
This is also a single-line text input but it masks the character as soon as a user enters it. They are also
created using HTML <input>tag but type attribute is set to password.
Example
Here is a basic example of a single-line password input used to take user password −
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Password Input Control</title>
</head>
<body>
<form >
User ID : <input type = "text" name = "user_id" />
<br>
Password: <input type = "password" name = "password" />
</form>
</body>
https://www.tutorialspoint.com/html/html_forms.htm 4/14
2/4/2020 HTML - Forms - Tutorialspoint
</html>
User ID :
Password:
Attributes
Following is the list of attributes for <input> tag for creating password field.
1
type
Indicates the type of input control and for password input control it will be set to password.
2
name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
3
value
4
size
5
maxlength
Allows to specify the maximum number of characters a user can enter into the text box.
This is used when the user is required to give details that may be longer than a single sentence. Multi-line
input controls are created using HTML <textarea> tag.
Example
Here is a basic example of a multi-line text input used to take item description −
https://www.tutorialspoint.com/html/html_forms.htm 5/14
2/4/2020 HTML - Forms - Tutorialspoint
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Multiple-Line Input Control</title>
</head>
<body>
<form>
Description : <br />
<textarea rows = "5" cols = "50" name = "description">
Enter description here...
</textarea>
</form>
</body>
</html>
Description:
Attributes
Following is the list of attributes for <textarea> tag.
1
name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
2
rows
3
cols
https://www.tutorialspoint.com/html/html_forms.htm 6/14
2/4/2020 HTML - Forms - Tutorialspoint
Checkbox Control
Checkboxes are used when more than one option is required to be selected. They are also created using
HTML <input> tag but type attribute is set to checkbox..
Example
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Checkbox Control</title>
</head>
<body>
<form>
<input type = "checkbox" name = "maths" value = "on"> Maths
<input type = "checkbox" name = "physics" value = "on"> Physics
</form>
</body>
</html>
Maths Physics
Attributes
https://www.tutorialspoint.com/html/html_forms.htm 7/14
2/4/2020 HTML - Forms - Tutorialspoint
1
type
Indicates the type of input control and for checkbox input control it will be set to checkbox..
2
name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
3
value
The value that will be used if the checkbox is selected.
4
checked
Example
Here is example HTML code for a form with two radio buttons −
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Radio Box Control</title>
</head>
<body>
<form>
<input type = "radio" name = "subject" value = "maths"> Maths
<input type = "radio" name = "subject" value = "physics"> Physics
</form>
</body>
</html>
https://www.tutorialspoint.com/html/html_forms.htm 8/14
2/4/2020 HTML - Forms - Tutorialspoint
Maths Physics
Attributes
Following is the list of attributes for radio button.
1
type
Indicates the type of input control and for checkbox input control it will be set to radio.
2
name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
3
value
4
checked
Set to checked if you want to select it by default.
A select box, also called drop down box which provides option to list down various options in the form of
drop down list, from where a user can select one or more options.
Example
Here is example HTML code for a form with one drop down box
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Select Box Control</title>
</head>
<body>
https://www.tutorialspoint.com/html/html_forms.htm 9/14
2/4/2020 HTML - Forms - Tutorialspoint
<form>
<select name = "dropdown">
<option value = "Maths" selected>Maths</option>
<option value = "Physics">Physics</option>
</select>
</form>
</body>
</html>
Maths
Attributes
1
name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
2
size
This can be used to present a scrolling list box.
3
multiple
If set to "multiple" then allows a user to select multiple items from the menu.
https://www.tutorialspoint.com/html/html_forms.htm 10/14
2/4/2020 HTML - Forms - Tutorialspoint
1
value
The value that will be used if an option in the select box box is selected.
2
selected
Specifies that this option should be the initially selected value when the page loads.
3
label
Example
Here is example HTML code for a form with one file upload box −
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>File Upload Box</title>
</head>
<body>
<form>
<input type = "file" name = "fileupload" accept = "image/*" />
</form>
</body>
</html>
https://www.tutorialspoint.com/html/html_forms.htm 11/14
2/4/2020 HTML - Forms - Tutorialspoint
Attributes
1
name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
2
accept
Button Controls
There are various ways in HTML to create clickable buttons. You can also create a clickable button using
<input>tag by setting its type attribute to button. The type attribute can take the following values −
1
submit
2
reset
This creates a button that automatically resets form controls to their initial values.
3
button
This creates a button that is used to trigger a client-side script when the user clicks that button.
4
image
This creates a clickable button but we can use an image as background of the button.
Example
Here is example HTML code for a form with three types of buttons −
Live Demo
<!DOCTYPE html>
<html>
https://www.tutorialspoint.com/html/html_forms.htm 12/14
2/4/2020 HTML - Forms - Tutorialspoint
<head>
<title>File Upload Box</title>
</head>
<body>
<form>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
<input type = "button" name = "ok" value = "OK" />
<input type = "image" name = "imagebutton" src = "/html/images/logo.png" />
</form>
</body>
</html>
Submit Reset OK
Example
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>File Upload Box</title>
</head>
<body>
<form>
<p>This is page 10</p>
<input type = "hidden" name = "pagename" value = "10" />
https://www.tutorialspoint.com/html/html_forms.htm 13/14
2/4/2020 HTML - Forms - Tutorialspoint
</html>
This is page 10
Submit Reset
https://www.tutorialspoint.com/html/html_forms.htm 14/14
2/4/2020 HTML - Embed Multimedia - Tutorialspoint
Sometimes you need to add music or video into your web page. The easiest way to add video or sound to
your web site is to include the special HTML tag called <embed>. This tag causes the browser itself to
include controls for the multimedia automatically provided browser supports <embed> tag and given
media type.
You can also include a <noembed> tag for the browsers which don't recognize the <embed> tag. You
could, for example, use <embed> to display a movie of your choice, and <noembed> to display a single
JPG image if browser does not support <embed> tag.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML embed Tag</title>
</head>
<body>
<embed src = "/html/yourfile.mid" width = "100%" height = "60" >
<noembed><img src = "yourimage.gif" alt = "Alternative Media" ></noembed>
</embed>
</body>
</html>
Note −The align and autostart attributes deprecated in HTML5. Do not use these attributes.
https://www.tutorialspoint.com/html/html_embed_multimedia.htm 1/5
2/4/2020 HTML - Embed Multimedia - Tutorialspoint
1
align
Determines how to align the object. It can be set to either center, left or right.
2
autostart
This boolean attribute indicates if the media should start automatically. You can set it either true
or false.
3
loop
Specifies if the sound should be played continuously (set loop to true), a certain number of
times (a positive value) or not at all (false)
4
playcount
Specifies the number of times to play the sound. This is alternate option for loop if you are
usiong IE.
5
hidden
Specifies if the multimedia object should be shown on the page. A false value means no and
true values means yes.
6
width
Width of the object in pixels
7
height
Height of the object in pixels
8
name
A name used to reference the object.
9
src
URL of the object to be embedded.
10
volume
Controls volume of the sound. Can be from 0 (off) to 100 (full volume).
https://www.tutorialspoint.com/html/html_embed_multimedia.htm 2/5
2/4/2020 HTML - Embed Multimedia - Tutorialspoint
You can use various media types like Flash movies (.swf), AVI's (.avi), and MOV's (.mov) file types inside
embed tag.
.swf files − are the file types created by Macromedia's Flash program.
.wmv files − are Microsoft's Window's Media Video file types.
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML embed Tag</title>
</head>
<body>
<embed src = "/html/yourfile.swf" width = "200" height = "200" >
<noembed><img src = "yourimage.gif" alt = "Alternative Media" ></noembed>
</embed>
</body>
</html>
Background Audio
You can use HTML <bgsound> tag to play a soundtrack in the background of your webpage. This tag is
supported by Internet Explorer only and most of the other browsers ignore this tag. It downloads and plays
an audio file when the host document is first downloaded by the user and displayed. The background
sound file also will replay whenever the user refreshes the browser.
https://www.tutorialspoint.com/html/html_embed_multimedia.htm 3/5
2/4/2020 HTML - Embed Multimedia - Tutorialspoint
Note − The bgsound tag is deprecated and it is supposed to be removed in a future version of HTML. So
they should not be used rather, it's suggested to use HTML5 tag audio for adding sound. But still for
learning purpose, this chapter will explain bgsound tag in detail.
This tag is having only two attributes loop and src. Both these attributes have same meaning as explained
above.
Here is a simple example to play a small midi file −
<!DOCTYPE html>
<html>
<head>
<title>HTML embed Tag</title>
</head>
<body>
<bgsound src = "/html/yourfile.mid">
<noembed><img src = "yourimage.gif" ></noembed>
</bgsound>
</body>
</html>
This will produce the blank screen. This tag does not display any component and remains hidden.
Internet Explorer can also handle only three different sound format files − wav, the native format for PCs;
au, the native format for most Unix workstations; and MIDI, a universal music-encoding scheme.
HTML 4 introduces the <object> element, which offers an all-purpose solution to generic object inclusion.
The <object> element allows HTML authors to specify everything required by an object for its
presentation by a user agent.
Example - 1
Here alt attribute will come into picture if browser does not support object tag.
Example - 2
https://www.tutorialspoint.com/html/html_embed_multimedia.htm 4/5
2/4/2020 HTML - Embed Multimedia - Tutorialspoint
Example - 3
You can specify some parameters related to the document with the <param> tag. Here is an example to
embed a wav file −
Example - 4
Example - 5
The classid attribute identifies which version of Java Plug-in to use. You can use the optional codebase
attribute to specify if and how to download the JRE.
https://www.tutorialspoint.com/html/html_embed_multimedia.htm 5/5
2/4/2020 HTML - Marquees - Tutorialspoint
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 <marquee> tag deprecated in HTML5. Do not use this element, instead you can use
JavaScript and CSS to create such effects.
Syntax
Following is the list of important attributes which can be used with <marquee> tag.
https://www.tutorialspoint.com/html/html_marquees.htm 1/4
2/4/2020 HTML - Marquees - Tutorialspoint
1
width
This specifies the width of the marquee. This can be a value like 10 or 20% etc.
2
height
This specifies the height of the marquee. This can be a value like 10 or 20% etc.
3
direction
This specifies the direction in which marquee should scroll. This can be a value like up, down,
left or right.
4
behavior
This specifies the type of scrolling of the marquee. This can have a value like scroll, slide and
alternate.
5
scrolldelay
This specifies how long to delay between each jump. This will have a value like 10 etc.
6
scrollamount
This specifies the speed of marquee text. This can have a value like 10 etc.
7
loop
This specifies how many times to loop. The default value is INFINITE, which means that the
marquee loops endlessly.
8
bgcolor
This specifies background color in terms of color name or color hex value.
9
hspace
This specifies horizontal space around the marquee. This can be a value like 10 or 20% etc.
10
vspace
This specifies vertical space around the marquee. This can be a value like 10 or 20% etc.
https://www.tutorialspoint.com/html/html_marquees.htm 2/4
2/4/2020 HTML - Marquees - Tutorialspoint
Examples - 1
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML marquee Tag</title>
</head>
<body>
<marquee>This is basic example of marquee</marquee>
</body>
</html>
Examples - 2
Live Demo
<!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 e
https://www.tutorialspoint.com/html/html_marquees.htm 3/4
2/4/2020 HTML - Marquees - Tutorialspoint
Examples - 3
Live Demo
<!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>
Examples - 4
Live Demo
<!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>
Thi t t ill ll f b tt t
https://www.tutorialspoint.com/html/html_marquees.htm 4/4
2/4/2020 HTML - Header - Tutorialspoint
HTML - Header
We have learnt that a typical HTML document will have following structure −
<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 is used for specifying the title of the HTML document. Following is an example to
give a title to an HTML document −
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML Title Tag Example</title>
</head>
<body>
<p>Hello, World!</p>
</body>
</html>
https://www.tutorialspoint.com/html/html_header.htm 1/6
2/4/2020 HTML - Header - Tutorialspoint
Hello, World!
Following are few of the important usages of <meta> tag inside an HTML document −
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML Meta Tag Example</title>
<!-- 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>
https://www.tutorialspoint.com/html/html_header.htm 2/6
2/4/2020 HTML - Header - Tutorialspoint
Hello, World!
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 −
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML Base Tag Example</title>
<base href = "https://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>
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/html/index.htm
https://www.tutorialspoint.com/html/html_header.htm 3/6
2/4/2020 HTML - Header - Tutorialspoint
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 −
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML link Tag Example</title>
<base href = "https://www.tutorialspoint.com/" />
<link rel = "stylesheet" type = "text/css" href = "/css/style.css">
</head>
<body>
<p>Hello, World!</p>
</body>
</html>
Hello, World!
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML style Tag Example</title>
<base href = "https://www.tutorialspoint.com/" />
<body>
https://www.tutorialspoint.com/html/html_header.htm 4/6
2/4/2020 HTML - Header - Tutorialspoint
</html>
Hello, World!
Note − To learn about how Cascading Style Sheet works, kindly check a separate tutorial available at css
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
−
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML script Tag Example</title>
<base href = "http://www.tutorialspoint.com/" />
<body>
<input type = "button" onclick = "Hello();" name = "ok" value = "OK" />
</body>
</html>
This will produce the following result, where you can try to click on the given button −
OK
Note − To learn about how JavaScript works, kindly check a separate tutorial available at javascript
https://www.tutorialspoint.com/html/html_header.htm 5/6
2/4/2020 HTML - Header - Tutorialspoint
https://www.tutorialspoint.com/html/html_header.htm 6/6
2/4/2020 HTML - Layouts - Tutorialspoint
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.
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 −
Live Demo
<!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>
https://www.tutorialspoint.com/html/html_layouts.htm 1/5
2/4/2020 HTML - Layouts - Tutorialspoint
</td>
</tr>
<tr>
<td colspan = "2" bgcolor = "#b5dcb3">
<center>
Copyright © 2007 Tutorialspoint.com
</center>
</td>
</tr>
</table>
</body>
</html>
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
Live Demo
<!DOCTYPE html>
<html>
https://www.tutorialspoint.com/html/html_layouts.htm 2/5
2/4/2020 HTML - Layouts - Tutorialspoint
<head>
<title>Three Column HTML Layout</title>
</head>
<body>
<table width = "100%" border = "0">
<table>
</body>
</html>
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.
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML Layouts using DIV, SPAN</title>
</head>
<body>
<div style = "width:100%">
https://www.tutorialspoint.com/html/html_layouts.htm 4/5
2/4/2020 HTML - Layouts - Tutorialspoint
</div>
</div>
</body>
</html>
You can create better layout using DIV, SPAN along with CSS. For more information on CSS, please refer
to CSS Tutorial.
https://www.tutorialspoint.com/html/html_layouts.htm 5/5
2/4/2020 HTML - Backgrounds - Tutorialspoint
HTML - Backgrounds
By default, your webpage background is white in color. You may not like it, but no worries. HTML provides
you following two good ways to decorate your webpage background.
HTML Background with Colors
HTML Background with Images
Now let's see both the approaches one by one using appropriate examples.
Note − The bgcolor attribute deprecated in HTML5. Do not use this attribute.
Following is the syntax to use bgcolor attribute with any HTML tag.
Example
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML Background Colors</title>
https://www.tutorialspoint.com/html/html_backgrounds.htm 1/5
2/4/2020 HTML - Backgrounds - Tutorialspoint
</head>
<body>
<!-- Format 1 - Use color name -->
<table bgcolor = "yellow" width = "100%">
<tr>
<td>
This background is yellow
</td>
</tr>
</table>
</html>
The background attribute can also be used to control the background of an HTML element, specifically
page body and table backgrounds. You can specify an image to set background of your HTML page or
table.
Note − The background attribute deprecated in HTML5. Do not use this attribute.
https://www.tutorialspoint.com/html/html_backgrounds.htm 2/5
2/4/2020 HTML - Backgrounds - Tutorialspoint
Following is the syntax to use background attribute with any HTML tag.
Note − The background attribute is deprecated and it is recommended to use Style Sheet for
background setting.
The most frequently used image formats are JPEG, GIF and PNG images.
Example
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML Background Images</title>
</head>
<body>
<!-- Set table background -->
<table background = "/images/html.gif" width = "100%" height = "100">
<tr><td>
This background is filled up with HTML image.
</td></tr>
</table>
</body>
</html>
https://www.tutorialspoint.com/html/html_backgrounds.htm 3/5
2/4/2020 HTML - Backgrounds - Tutorialspoint
You might have seen many pattern or transparent backgrounds on various websites. This simply can be
achieved by using patterned image or transparent image in the background.
It is suggested that while creating patterns or transparent GIF or PNG images, use the smallest
dimensions possible even as small as 1x1 to avoid slow loading.
Example
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML Background Images</title>
</head>
<body>
<!-- Set a table background using pattern -->
<table background = "/images/pattern1.gif" width = "100%" height = "100">
<tr>
<td>
This background is filled up with a pattern image.
</td>
</tr>
</table>
</html>
https://www.tutorialspoint.com/html/html_backgrounds.htm 4/5
2/4/2020 HTML - Backgrounds - Tutorialspoint
https://www.tutorialspoint.com/html/html_backgrounds.htm 5/5
2/4/2020 HTML - Colors - Tutorialspoint
HTML - Colors
Colors are very important to give a good look and feel to your website. You can specify colors on page
level using <body> tag or you can set colors for individual tags using bgcolor attribute.
The <body> tag has following attributes which can be used to set different colors −
bgcolor − sets a color for the background of the page.
vlink − sets a color for visited links − that is, for linked text that you have already clicked on.
There are following three different methods to set colors in your web page −
Color names − You can specify color names directly like green, blue or red.
Hex codes − A six-digit code representing the amount of red, green, and blue that makes up the
color.
Color decimal or percentage values − This value is specified using the rgb( ) property.
You can specify direct a color name to set text or background color. W3C has listed 16 basic color names
that will validate with an HTML validator but there are over 200 different color names supported by major
browsers.
Here is the list of W3C Standard 16 Colors names and it is recommended to use them.
https://www.tutorialspoint.com/html/html_colors.htm 1/7
2/4/2020 HTML - Colors - Tutorialspoint
Example
Here are the examples to set background of an HTML tag by color name −
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML Colors by Name</title>
</head>
</html>
A hexadecimal is a 6 digit representation of a color. The first two digits(RR) represent a red value, the next
two are a green value(GG), and the last are the blue value(BB).
A hexadecimal value can be taken from any graphics software like Adobe Photoshop, Paintshop Pro or
MS Paint.
Each hexadecimal code will be preceded by a pound or hash sign #. Following is a list of few colors using
hexadecimal notation.
https://www.tutorialspoint.com/html/html_colors.htm 2/7
2/4/2020 HTML - Colors - Tutorialspoint
#000000
#FF0000
#00FF00
#0000FF
#FFFF00
#00FFFF
#FF00FF
#C0C0C0
#FFFFFF
Example
Here are the examples to set background of an HTML tag by color code in hexadecimal −
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML Colors by Hex</title>
</head>
</html>
https://www.tutorialspoint.com/html/html_colors.htm 3/7
2/4/2020 HTML - Colors - Tutorialspoint
This color value is specified using the rgb( ) property. This property takes three values, one each for red,
green, and blue. The value can be an integer between 0 and 255 or a percentage.
Note − All the browsers does not support rgb() property of color so it is recommended not to use it.
rgb(0,0,0)
rgb(255,0,0)
rgb(0,255,0)
rgb(0,0,255)
rgb(255,255,0)
rgb(0,255,255)
rgb(255,0,255)
rgb(192,192,192)
rgb(255,255,255)
Example
Here are the examples to set background of an HTML tag by color code using rgb() values −
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>HTML Colors by RGB code</title>
</head>
</table>
</body>
</html>
Here is the list of 216 colors which are supposed to be safest and computer independent colors. These
colors very from hexa code 000000 to FFFFFF and they will be supported by all the computers having
256 color palette.
https://www.tutorialspoint.com/html/html_colors.htm 5/7
2/4/2020 HTML - Colors - Tutorialspoint
https://www.tutorialspoint.com/html/html_colors.htm 6/7
2/4/2020 HTML - Colors - Tutorialspoint
https://www.tutorialspoint.com/html/html_colors.htm 7/7
2/4/2020 HTML - Fonts - Tutorialspoint
HTML - Fonts
Fonts play a very important role in making a website more user friendly and increasing content readability.
Font face and color depends entirely on the computer and browser that is being used to view your page
but you can use HTML <font> tag to add style, size, and color to the text on your website. You can use a
<basefont> tag to set all of your text to the same size, face, and color.
The font tag is having three attributes called size, color, and face to customize your fonts. To change any
of the font attributes at any time within your webpage, simply use the <font> tag. The text that follows will
remain changed until you close with the </font> tag. You can change one or all of the font attributes within
one <font> tag.
Note −The font and basefont tags are deprecated and it is supposed to be removed in a future
version of HTML. So they should not be used rather, it's suggested to use CSS styles to manipulate
your fonts. But still for learning purpose, this chapter will explain font and basefont tags in detail.
You can set content font size using size attribute. The range of accepted values is from 1(smallest) to
7(largest). The default size of a font is 3.
Example
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Setting Font Size</title>
</head>
<body>
<font size = "1">Font size = "1"</font><br />
<font size = "2">Font size = "2"</font><br />
<font size = "3">Font size = "3"</font><br />
<font size = "4">Font size = "4"</font><br />
<font size = "5">Font size = "5"</font><br />
<font size = "6">Font size = "6"</font><br />
<font size = "7">Font size = "7"</font>
</body>
</html>
https://www.tutorialspoint.com/html/html_fonts.htm 1/6
2/4/2020 HTML - Fonts - Tutorialspoint
Example
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Relative Font Size</title>
</head>
<body>
<font size = "-1">Font size = "-1"</font><br />
<font size = "+1">Font size = "+1"</font><br />
<font size = "+2">Font size = "+2"</font><br />
<font size = "+3">Font size = "+3"</font><br />
<font size = "+4">Font size = "+4"</font>
</body>
</html>
https://www.tutorialspoint.com/html/html_fonts.htm 2/6
2/4/2020 HTML - Fonts - Tutorialspoint
Example
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Font Face</title>
</head>
<body>
<font face = "Times New Roman" size = "5">Times New Roman</font><br />
<font face = "Verdana" size = "5">Verdana</font><br />
<font face = "Comic sans MS" size =" 5">Comic Sans MS</font><br />
<font face = "WildWest" size = "5">WildWest</font><br />
<font face = "Bedrock" size = "5">Bedrock</font><br />
</body>
</html>
https://www.tutorialspoint.com/html/html_fonts.htm 3/6
2/4/2020 HTML - Fonts - Tutorialspoint
A visitor will only be able to see your font if they have that font installed on their computer. So, it is
possible to specify two or more font face alternatives by listing the font face names, separated by a
comma.
When your page is loaded, their browser will display the first font face available. If none of the given fonts
are installed, then it will display the default font face Times New Roman.
You can set any font color you like using color attribute. You can specify the color that you want by either
the color name or hexadecimal code for that color.
Note − You can check a complete list of HTML Color Name with Codes .
Example
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Setting Font Color</title>
</head>
<body>
<font color = "#FF00FF">This text is in pink</font><br />
<font color = "red">This text is red</font>
</body>
</html>
https://www.tutorialspoint.com/html/html_fonts.htm 4/6
2/4/2020 HTML - Fonts - Tutorialspoint
The <basefont> tag also takes color, size and face attributes and it will support relative font setting by
giving size a value of +1 for a size larger or −2 for two sizes smaller.
Example
Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Setting Basefont Color</title>
</head>
<body>
<basefont face = "arial, verdana, sans-serif" size = "2" color = "#ff0000">
<p>This is the page's default font.</p>
<h2>Example of the <basefont> Element</h2>
</html>
https://www.tutorialspoint.com/html/html_fonts.htm 5/6
2/4/2020 HTML - Fonts - Tutorialspoint
https://www.tutorialspoint.com/html/html_fonts.htm 6/6