FWT
FWT
Adding images on a webpage: The <img> tag is used to add or embed the images
to a webpage/website. The “img” tag is an empty tag, which means it can contain
only a list of attributes and it has no closing tag. The addition of the images improves
the quality along with enhancing the design structure, appearance of the webpage.
Nowadays, a website does not directly add images to a web page, as the images are
linked to web pages by using the <img> tag which holds space for the image.
Syntax:
<img src="url" alt="some_text" width="" height="">
Example 1: This simple example illustrates the use of the <img> tag in HTML that is
used to embed the image into the webpage.
• HTML
<!DOCTYPE html>
<html>
<head>
<title>Welcome To GFG</title>
</head>
<body>
<h2>GeeksforGeeks</h2>
<p>This is the demo of <img> tag.</p>
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20210915115837/gfg3-
300x300.png"
alt="GFG image" />
</body>
</html>
Output:
<body>
<p>inserted image using <img> tag:</p>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-
uploads/20190710102234/download3.png"/>
</body>
</html>
Output:
alt: If the image cannot be displayed then the alt attribute acts as an alternative
description for the image. The value of the alt attribute is a user-defined text. It
generally happens when the user, for some reason, cannot view it due to a slow
internet connection or an error in the src attribute, or if the user uses a screen reader.
Example 3: The example illustrates the use of the alt attribute in the <img> tag.
• HTML
<!DOCTYPE html>
<html>
<head>
<title>Alt Attribute Example</title>
</head>
<body>
<p>inserted image using <img> tag:</p>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-
uploads/20190710102234/download3.png"
alt="This is GeeksforGeeks logo" />
</body>
</html>
Output:
Setting width and height of Image: The width and height attributes are used to
specify the height and width of an image. The attribute values are specified in pixels
by default. The width and height attributes are always declared in pixels. Please refer
to the How to set the width and height of an image using HTML? article for further
details.
Example 4: The example illustrates the use of the width & height attribute in the
<img> tag.
• HTML
<!DOCTYPE html>
<html>
<head>
<title>Setting width and height of image</title>
</head>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-
uploads/20190710102234/download3.png"
alt="GeeksforGeeks logo" width="300"
height="300" />
</body>
</html>
Output:
Example 5: The example illustrates the use of the title attribute in the <img> tag.
• HTML
<!DOCTYPE html>
<html>
<head>
<title>Inserting an image using "img" tag</title>
</head>
<body>
<p>inserted image using <img> tag:</p>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-
uploads/20190710102234/download3.png"
alt="GeeksforGeeks logo"
width="200"
height="200"
title="Logo of GeeksforGeeks" />
</body>
</html>
Output:
Example 6: This example illustrates the use of style property inside the <img> tag
in HTML.
• HTML
<!DOCTYPE html>
<html>
<head>
<title>Setting border to image</title>
</head>
<body>
<p>inserted image using <img> tag:</p>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-
uploads/20190710102234/download3.png"
alt="GeeksforGeeks logo"
width="200"
height="200"
border="5" />
</body>
</html>
Output:
Setting the border of the image
Aligning an Image: By default, an image is aligned on the left side of the page, but
it can be aligned to the centre or right using the align attribute. Please refer to the
HTML | <img> align Attribute for further details.
Example 7: This example illustrates the use of align property in the <img> tag whose
value is set to right.
• HTML
<!DOCTYPE html>
<html>
<head>
<title>Aligning an image</title>
</head>
<body>
<p>inserted image using <img> tag:</p>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-
uploads/20190710102234/download3.png"
alt="GeeksforGeeks logo"
align="right" />
</body>
</html>
Output:
Adding Image as a Link: An image can work as a link with a URL embedded in it. It
can be done by using the “img” tag inside an “a” tag. We need to specify the file path
in order to render the image on the webpage. File paths are used to link external
resources such as images, videos, style sheets, JavaScript, displaying other web
pages, etc. To insert a file on a web page its source must be known.
• Absolute File Paths: It always contains the root element along with the
complete directory list required to locate the file.
• Relative File Paths: It is the hierarchical path representation that locates the
file or folder on a file system beginning from the current directory.
Example 8: This example illustrates the use of link property in the <img> tag. Here,
we have used the absolute path link in order to provide the link to the image. Please
refer to the HTML | File Paths & How to turn an Image into a Link in HTML? article
for further details.
• HTML
<!DOCTYPE html>
<html>
<head>
<title>Adding image as link</title>
</head>
<body>
<h3>GeekforGeeks</h3>
<p>inserted image using <img> tag:</p>
<a href="https://ide.geeksforgeeks.org/tryit.php">
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-
uploads/20190710102234/download3.png"
alt="GeeksforGeeks logo" />
</a>
</body>
</html>
Output:
Adding the image as a link
Adding animated Image: Animated images in .gif format can also be added using
the “img” tag.
Example 9: This example explains the addition of an image in the GIF format in
HTML.
• HTML
<!DOCTYPE html>
<html>
<body>
<h3>Adding a gif file on a webpage</h3>
<img src="smiley.gif"
alt="smiley"
style="width: 200px; height: 200px" />
</body>
</html>
Output:
Adding an image in GIF format
Example 10: This example illustrates the use of body background property in the
<img> tag.
• HTML
<!DOCTYPE html>
<html>
</html>
Output:
Common Image Format: Here is the commonly used image file format that is
supported by all the browsers.
S.No. Abbreviation File Type Extension
Joint Photographic
JPEG. .jpg, .jpeg, .jfif,
2. Expert Group
.pjpeg, .pjp
image.
Graphics
4. GIF Interchange .gif
Format.
Supported Browsers:
Creating Frames: Instead of using body tag, use frameset tag in HTML to use
frames in web browser. But this Tag is deprecated in HTML 5. The frameset tag is
used to define how to divide the browser. Each frame is indicated by frame tag and
it basically defines which HTML document shall open into the frame. To define the
horizontal frames use row attribute of frame tag in HTML document and to define
the vertical frames use col attribute of frame tag in HTML document.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Example of HTML Frames using row attribute</title>
</head>
Output: The above example basically used to create three horizontal frames: top,
middle and bottom using row attribute of frameset tag and the noframe tag is used
for those browser who doesn’t support noframe.
<!DOCTYPE html>
<html>
<head>
<title>Example of HTML Frames Using col Attribute</title>
</head>
• cols: The cols attribute is used to create vertical frames in web browser. This
attribute is basically used to define the no of columns and its size inside the
frameset tag.
The size or width of the column is set in the frameset in the following ways:
• Use absolute value in pixel
Example:<frameset cols = "300, 400, 300">
• Use percentage value
Example:<frameset cols = "30%, 40%, 30%">
• Use wild card values:
Example:<frameset cols = "30%, *, 30%">
• In the above example * will take the remaining percentage for creating
vertical frame.
• rows: The rows attribute is used to create horizontal frames in web browser.
This attribute is used to define no of rows and its size inside the frameset
tag.
The size of rows or height of each row use the following ways:
• Use absolute value in pixel
Example:
• <frameset rows = "300, 400, 300">
• Use percentage value
Example:<frameset rows = "30%, 40%, 30%">
• Use wild card values
Example:<frameset rows = "30%, *, 30%">
• In the above example * will take the remaining percentage for creating
horizontal frame.
• border: This attribute of frameset tag defines the width of border of each
frames in pixels. Zero value is used for no border.
Example:<frameset border="4" frameset>
• frameborder: This attribute of frameset tag is used to specify whether the
three-dimensional border should be displayed between the frames or not for
this use two values 0 and 1, where 0 defines for no border and value 1
signifies for yes there will be border.
• framespacing: This attribute of frameset tag is used to specify the amount of
spacing between the frames in a frameset. This can take any integer value as
an parameter which basically denotes the value in pixel.
Example:<framespacing="20">
It means there will be 20 pixel spacing between the frames
• name: This attribute is used to give names to the frame. It differentiate one
frame from another. It is also used to indicate which frame a document
should loaded into.
Example: <frame name = "top" src =
"C:/Users/dharam/Desktop/attr1.png" />
<frame name = "main" src =
"C:/Users/dharam/Desktop/gradient3.png" />
<frame name = "bottom" src =
"C:/Users/dharam/Desktop/col_last.png" />
• Here we use three frames with names as left center and right.
• src: This attribute in frame tag is basically used to define the source file that
should be loaded into the frame.The value of src can be any url.
Example:<frame name = "left" src = "/html/left.htm" />
• In the above example name of frame is left and source file will be loaded
from “/html/left.htm” in frame.
• marginwidth: This attribute in frame tag is used to specify width of the
spaces in pixels between the border and contents of left and right frame.
Example:<frame marginwidth="20">
Advantages:
• It allows the user to view multiple documents within a single Web page.
• It load pages from different servers in a single frameset.
• The older browsers that do not support frames can be addressed using the
tag.
Disadvantages: Due to some of its disadvantage it is rarely used in web browser.
What is SGML?
This is Standard Generalized Markup Language (SGML) application
conforming to International Standard ISO 8879. HTML is widely regarded
as the standard publishing language of the World Wide Web.
This is a language for describing markup languages, particularly those
used in electronic document exchange, document management, and
document publishing. HTML is an example of a language defined in SGML.
What is XML?
XML stands for EXtensible Markup Language. XML is a markup language
much like HTML and it was designed to describe data. XML tags are not
predefined. You must define your own tags according to your needs.
HTML XHTML
Flexible framework requiring lenient HTML Restrictive subset of XML which needs to
specific parser be parsed with standard XML parsers
Types of CSS
CSS (Cascading Style Sheet) describes the HTML elements which are displayed on screen,
paper, or in other media. It saves a lot of time. It controls the layout of multiple web pages
at one time. It sets the font-size, font-family, color, background color on the page.
It allows us to add effects or animations to the website. We use CSS to display animations
like buttons, effects, loaders or spinners, and also animated backgrounds.
Without using CSS, the website will not look attractive. There are 3 types of CSS which are
below:
• Inline CSS
• Internal/ Embedded CSS
• External CSS
1. Internal CSS
The Internal CSS has <style> tag in the <head> section of the HTML document. This CSS style is an
effective way to style single pages. Using the CSS style for multiple web pages is time-consuming
because we require placing the style on each web page.
1. <style type="text/css">
3. Add the rules of CSS in the new line.
Example:
2. body {
3. background-color: black;
4. }
5. h1 {
6. color: white;
7. padding: 50px;
8. }
4. Close the style tag.
9. </style>
After adding the internal CSS, the complete HTML file looks like the following:
28. .class {
29. property1 : value1;
30. property2 : value2;
31. property3 : value3;
32. }
33.
34. #id {
35. property1 : value1;
36. property2 : value2;
37. property3 : value3;
38. }
Pros of Internal CSS
• Internal CSS cannot upload multiple files when we add the code with the HTML page.
Cons of Internal CSS:
• Adding code in the HTML document will reduce the page size and loading time of
the webpage.
2. External CSS
In external CSS, we link the web pages to the external .css file. It is created by text editor.
The CSS is more efficient method for styling a website. By editing the .css file, we can change
the whole site at once.
To use the external CSS, follow the steps, given below:
1. Create a new .css file with text editor, and add Cascading Style Sheet rules too.
For example:
39. .xleftcol {
40. float: right;
41. width: 35%;
42. background:#608800;
43. }
44. .xmiddlecol {
45. float: right;
46. width: 35%;
47. background:#eff3df;
48. }
2. Add a reference to the external .cssfile right after <title> tag in the <head> section of
HTML sheet:
49. <link rel="stylesheet" type="text/css" href="style.css" />
Pros of External CSS:
• The pages cannot be delivered correctly before the external CSS is loaded.
• In External CSS, uploading many CSS files can increase the download time of a
website.
3. Inline CSS
Inline CSS is used to style a specific HTML element. Add a style attribute to each HTML tag
without using the selectors. Managing a website may difficult if we use only inline CSS.
However, Inline CSS in HTML is useful in some situations. We have not access the CSS files
or to apply styles to element.
In the following example, we have used the inline CSS in <p> and <h1> tag.
• Inline CSS, adding CSS rules to HTML elements is time-consuming and messes up
the HTML structure.
• It styles multiple elements at the same time which can affect the page size and
download time of the page.
CSS Syntax
A CSS rule set contains a selector and a declaration block.
Selector: Selector indicates the HTML element you want to style. It could be any tag like
<h1>, <title> etc.
Declaration Block: The declaration block can contain one or more declarations separated
by a semicolon. For the above example, there are two declarations:
Property: A Property is a type of attribute of HTML element. It could be color, border etc.
Value: Values are assigned to CSS properties. In the above example, value "yellow" is
assigned to color property.
Notable points:
1. Functions are considered as one of the fundamental building blocks in Javascript.
2. To use a function, it must be defined somewhere in the scope from which it will be
called.
3. A javascript function is composed of a sequence of statements called the function body.
4. JavaScript function can take one or more inputs and can return output also. However,
both taking input and returning an output are optional.
5. Every function in JavaScript is a function object.
Explanation: This is a function, which on being called alerts "Hello World!". We have not added any return
statement in this code, because it is not required.
The following image shows the structure of a JavaScript function:
Explanation:
We have a "function" keyword in JavaScript functions, followed by the "function name".
There is a parameter list in the function that takes some input. The parameter list in any function is
optional, for example:
Example:
function demo(){
alert("Good Morning!")
}
The above function does not take any input and has an empty parameter list. It may also be called a non-
parameterized function. 3. There is a set of code statements enclosed in parentheses, also known as the
function body. 4. We have an optional "return" statement that returns some output from the function.
Function expressions
A function expression is very similar to a function declaration. Their syntax, too, is almost similar. The
main difference between a function expression and a function declaration is the function name, which can
be omitted(not mandatory though) in function expressions to create an anonymous function. For example,
the above add function can now be defined as --
const add = function (a,b){ //function expression
return a+b;
}
console.log(add(3, 4));
// expected output: 7
Output:- 7