Showing posts with label Adding image in HTML. Show all posts
Showing posts with label Adding image in HTML. Show all posts

ADDING IMAGE IN HTML

 A web page should be designed in such a way that a user can easily understand its contents and it should look attractive too. For this we can add  graphics, images, photographs etc in our web pages. Not only these elements enhance the presentation of the web pages for its items but also it allures and attracts the users to browse the particular web page. 

HTML supports static and animated both kinds of images. HTML accepts the image as GIF(Graphic Interchange Format), JPEG(Joint Photographic Experts Group) or BMP(Bitmap).

<IMG> Tag : <IMG> tag is used to add an image to the web page. It is an empty tag. It may start with <P> tag which is a container tag. When we enclose the <IMG> tag between  <P> and </P> tags, a blank line is inserted before and after the image. The SRC (Source) attribute is used with <IMG> tag to specify the name and location of the image.

For example:

<P> <IMG Src = "flower.gif"></P>

Attributes of <IMG> tags :

  • SRC
  • ALIGN
  • BORDER
  • WIDTH
  • HEIGHT
  • HSPACE
  • VSPACE
  • ALT
SRC Attribute : This attribute specifies the location (source) of the image file. Syntax to use SRC attribute is as follow :
<IMG SRC = "Image file with URL">
For Example 
<IMG Src = "C:\flower.gif">

ALIGN Attribute : This attribute is used to align the text and the image in a web page according to the specified alignment given with this attribute Align.

For the alignment of text we can use the following alignments.
TOP - It align the text to be displayed at the top, above the image
MIDDLE - It aligns the text to be displayed in the middle, with the image
BOTTOM - It aligns the text to be displayed at the bottom, below the page.

For the alignment of image we can use the following alignments.
LEFT - It aligns the image towards the left of the screen.
RIGHT - It aligns the image towards the right of the screen. 
Syntax to use Align attribute is as follow :
<IMG Align = "top"/"middle"/"bottom"/"left"/"right">
For example :
<IMG SRC = "C:\flower.gif" Align = "middle">
                                     or

<IMG SRC = "C:\flower.gif" Align = "right">

Right alignment


Left Alignment

BORDER Attribute : This attribute is used to specify the width of the border around the image. By default border is not set in the image but when we specify it with Border attribute, then it appears around the image. Width of the border depends on the value which we give with the Border attribute. Syntax to use Border attribute is as follow: 
<IMG SRC = "C:\flower.gif" Align = "top" border = "2">

If we want more thick border then we can increase the number more than "2" in that ratio in which the thickness is desired and if we want thin border then option is "1" because less than 2 is 1 only.
In Notepad++

In Browser


WIDTH Attribute : This attribute is used to specify the width of the image in pixels or percentage, in comparison to its original size. The syntax is
<IMG WIDTH = "Value/Percentage">
For example :  <IMG SRC =  "C:\flower.gif" Width = "50%">
                                               or
                        <IMG SRC =  "C:\flower.gif" Width = "300"> 

HEIGHT Attribute : This attribute is used to specify the height of the image in pixels or percentage, in comparison to its original size. The syntax to use Height attribute is
<IMG HEIGHT= "Value/Percentage">
For example :  <IMG SRC =  "C:\flower.gif" Height= "75%">
                                               or
                        <IMG SRC =  "C:\flower.gif" Height= "350">
HSPACE Attribute : This attribute is used to set the space towards left or right margin of the image. It specify the horizontal space between the text and image in numbers. Syntax to use HSPACE Attribute is 
<IMG SRC =  "C:\flower.gif" HSPACE= "2"> 

VSPACE Attribute : This attribute is used to set the space towards top or bottom margin of the image. It specify the vertical space between the text and image in numbers. Syntax to use VSPACE Attribute is 
<IMG SRC =  "C:\flower.gif" VSPACE= "3"> 

ALT Attribute : This attribute is used to assign an alternative text that will be displayed over the image when take the mouse on the image. The text given with Alt attribute is displayed on the image. (some browser may not support this feature). The syntax to use ALT Attribute is as follows :
<IMG SRC =  "C:\flower.gif" ALT = "Flower"> 
In notepad++


In Browser

    Try the above codes in Try it Editor

    TOP
    Try it yourself editor
     
    Code
    Output












    Introduction to HTML


    We surf many websites everyday to find out the information required that time. We find our solutions too by using these websites. But have you ever thought how these amazing websites are made and how does a link work ?
    Yes, this is the subject we will discuss here and the name of the topic is HTML. HTML stands for Hypertext Markup Language.
    A markup language is used to mark the content that helps in designing the web pages. These related web pages make a website.
     
    Hypertext is the way of creating documents that can be displayed on the web and helps to establish link between themselves and cross link to other pages on the web.
    Markup  means identifying or marking the text by applying different formatting features in web documents and producing different types of effect when the document is displayed on web page.
    Language This is the common syntax and rules for writing or marking the text.

    Features of HTML
    i. HTML is not a programming language or any word processing program, rather it is a markup language.
    ii. It is a platform independent language, it can run on any type of operating system like Macintosh, IBM computer etc.
    iii. It is not a case sensitive, we can write tag in any upper or lower case.
    iv. it allows to format text, graphics, audios, videos and save in an ASCII code.

    Requirement to work with HTML
    We need only two things to work in HTML :
    i. Text Editor and             ii. Web browser.

    i. Text Editor : It provides the space where we write text in proper HTML syntex to create a web page.  Some examples are Notepad, Wordpad, Word perfect, KWrite, Front page etc
    After completing the writing text for a web page we save this file with extension .htm or .html.

    ii. Web browser : It is an application software used to display the coded content in text editor in a web page on World wide web or on a local area network. A web page may contain hypertext and the web browser allows to open it in other web page. Examples Google chrome, Internet explorer etc.

    Now we will know some basic terminologies used in HTML.
    1. Tags : These are the keywords of HTML used to define how text, images, audios and videos will appear in a web page. This is the fundamental unit of coded document in HTML and surrounded by angular brackets (<  >). Like <title>, <body> etc. If the tags are not surrounded by angular brackets, HTML takes it as normal text. 
    Tags are of two types. 
    Container Tag and 
    Empty Tag
    A container tag used in pair a opening tag and a closing tag. It defines where or how the structure of the text will appear written under  opening tag and closing tag.
    For example : <title> my first webpage </title>
    Here <title> is an opening tag, </title> is a closing tag  and these two tags defines the text present between both 'my first webpage' will be appeared as title of webpage (Title appears in the title bar of the web  browser). A closing tag is same as opening tag but starts with a back slash.

    An Empty Tag is not used in pairs. It is enough to use it single only. Means it defines the property of the text or document. For example <br> .
    <br> tag is used to give a line break at a particular place in a web page. When a line break appear at a particular place, the afterward texts will appear in next line so no need to give a closing tag.

    2. Element : Elements are the different sections of HTML document, like head, body etc. It is the fundamental component of the structure in an HTML document that includes many different components like title, body, paragraph or list.
    For Ex. <title> my first webpage </title>
    The above whole line is called an element. An element includes
    i. An opening tag
    ii. An closing tag
    iii. The text between the opening and the closing tag.

    3. Attribute : An attribute is the property of a tag, which defines some additional information about that tag. It always specified inside the opening tag. All attributes consist of two parts - a name and a value.
    Here name is the particular property of a tag and
    value is the category of that property.
    For Ex <body bgcolor="red">
    Here body is the tag, bgcolor  (background color) is the attribute and property of the body tag and "red" is the category of background color.
    Means the background color of the body text in a web page should be in red color.
    Now we start coding in HTML so that we can easily understand the structure.

    Fundamental Structure of HTML Document.

    An HTML document consists of text that comprises the content of the document and the tags that defines the structure and the appearance of the document. The basic structure of a HTML document can be classified into different sections called elements.
    HTML Coding Structure


    See the above coding again
    <html>
    <head>
    <title>
    My first web page 
    </title>
    </head>
    <body>
    Welcome to my first web page.
    </body>
    Footer
    </html>
    Here tags <html> and </html> are opening and closing html tags and it includes all the tags and text written  in this page. It shows this is an html document.
    Now <head> and </head> tags are opening and closing head tags. It includes the tags <title> and </title>. The text written with head tag will be displayed above the page as a heading and the text written in between the tags <title> and </title> will be displayed in title bar of the browser.
    Tags <title> and </title> includes the text which will be displayed in title bar.
    Now head section is finished and body section will start from here.
    The text written between <body> and </body> tags are displayed in web page as a content.
    After body tag section you can give the footer information like date of creating this page, time, name of the author(your) etc. But it is an  optional, you can ignore this if you want. 
    Now at last the </html> closing HTML tag is given which means now the page is finished.
    Coding in text editor Notepad++


    Saving an HTML Document.
    After coding as above in any text editor like 'notepad' in Windows or 'gedit' in BOSS Linux, now the time is to save the file.

    Following are the steps to save the file in HTML.

    i. Click file tab -- save as option
    ii. Save as dialog box opens up, in File Name box type any name
    iii. The most important step is after typing the name give a dot (.) and type 'html' or 'htm' as a extension of file.
    iv. Now click 'save' button. The file will look now in form of browser.
    saving of notepad file as my first webpage.html

    Viewing the web page in web browser.
    i. Navigate to the location where you have saved the html file.
    ii. Double click that file (look like a browser). Now the html file opens in default web browser of your computer.
    Here you can see the file, but if you need any change in your html file, then close the file and point that browser with mouse and right click.
    Click 'open with' option select the editor name (like notepad) in which you have typed all coding.
    Now it appears again in text editor form. Do the desired changes and this time click only file tab -- save option. (File name is already given). 

    Running in browser
    Try the above code in Try it Editor
    Try it yourself editor
     
    Code
    Output

    TOP 
















    Python: Functions