How to insert a picture in html?

How to insert a picture in html?

If you create a website and want to make it really interesting, lively and clear, you will certainly need to add to their pages the text of the image.In this article we look at how to insert an image in html and xhtml.

Tags images

tag, which is responsible for the output image on the site, is universal for all versions of html.This is the & lt;img & gt ;.It can be a little different to take shape, but the essence remains the same.

example, in html, you can just use a single tag & lt;img & gt ;.The xhtml all tags must be closed.Therefore, at the end of the tag, you have to put the right slash: & lt;img / & gt ;.


tag pictures When you insert the image using multiple attributes.Let's look at them in sequence.

  • key attribute - src.It indicates the address of the image you want to upload to the web page.Example html will look like this: & lt;img src = 'http: // / picture.png '& gt;Example xhtml will be as follows: & lt;img src = "http: // / picture.png "/ & gt;
  • Another two attributes relate to the image size.Namely, the width attribute offers to determine the width and height, respectively, the height of the image.Example html: & lt;img src = 'picture.png 'width =' 300 'height =' 100 '& gt;For the xhtml: & lt;img src = "picture.png 'width = "300" height = "100" / & gt;Further attributes advisable to register for any one programming language, because everywhere there is a clear analogy.
  • alt attribute should include a brief description of the image.This text appears if the picture is not loaded, or if a user searches for information through the search engine in the "Pictures".An example line of code: & lt;img src = 'picture.png 'alt =' interesting picture '& gt;
  • Title gives the title picture.It is also important when users search for the information you need.& Lt;img src = 'picture.png 'title =' Picture '& gt;
  • vspace attribute specifies the indentation between vertical images and other layout elements (such as text).Value is measured in pixels.
  • hspace attribute sets the same padding, but horizontally.The value is also measured in pixels.An example for the last two attributes: & lt;img src = 'picture.png 'vspace =' 5 'hspace =' 5 '& gt;
  • With the border attribute is outlined picture frame.If not specifically set, the default appears 0. Example: & lt;img src = 'picture.png 'border =' 1 '& gt;

Additional opportunities for

pictures a picture you can not only insert into the text of a web page, but also make the background.Picture background is an attribute of the body tag or a style css.For more information about how to insert a picture in the background of your site, you will find in the article How to make a background in html.

You can insert a picture into a table.Then the picture is not the background for the whole page, but only for a specific area.And at the same image location will be recorded, regardless of the surrounding text.To do this, you must create an html table.Recall table tag - table, tag line - tr (row), the column tag - td.

insert a picture after a td tag.Here's how it would look:

  • & lt;table border = '0' & gt;
  • & lt;tr align = 'left' & gt;
  • & lt;td & gt; & lt;img src = 'picture.png '& gt; & lt; / td & gt;
  • & lt;td & gt;2nd cell & lt; / td & gt;
  • & lt; / tr & gt;
  • & lt;tr align = "right" & gt;
  • & lt;td & gt;3rd cell & lt; / td & gt;
  • & lt;td & gt;4th cell & lt; / td & gt;
  • & lt; / tr & gt;
  • & lt; / table & gt;