Images in HTML. Images in HTML Graphic image formats

In the life of every copywriter, there comes a stage of becoming familiar with html tags. Usually this happens spontaneously and looks like a request from the customer to “prepare the text for publication.” This means that in the article you need to highlight headings, paragraphs, significant places and lists, but not with Word capabilities, but with special code html language. Will help with this tags for copywriter. The list required for work is usually small, but it is enough to format text with standard requirements. What is included in the html tags necessary for a copywriter? (If you are too lazy to read, then scroll down - there is a simple and clear thematic infographic about html tags!)

The copywriter asks traditional questions. And they all start with the wording “what tag is used to specify...”:

  • title;
  • paragraph;
  • thumbnail;
  • italics;
  • list bulleted/unlabeled/

All this adds spice to the technical task and stimulates the acquisition of new knowledge. The situation gets worse when the task is to use a bold text tag to increase the attractiveness of the key in the PS. But all this can be solved very simply, which we will deal with now.

Tags for creating titles

Tags for creating headings are represented by elements h1-h6. They got their letter from the English Header (heading). To set required type header and emphasize its significance for the PS, use the following code:

Heading h1

Heading h2

Heading h3

Heading h4

Heading h5
Heading h6

On the website it will look like this.

Heading h1

Heading h2

Heading h3

Heading h4

Heading h5
Heading h6

The h1 heading has the most significance - and visibility -. It is used as the title of a post and is used only once. For subheadings in the text, h2 and h3 are recommended. They help to emphasize the significance of the material under consideration and divide the article into information levels.

Headers h4-h6 are practically not used, but they are in demand for highlighting logical blocks and important fragments.

For large articles it is best to use headings h1-h3, for small ones - h1 and h2.

Lists: bulleted and unlabeled

Structured good text always has one or even several lists. In my own way appearance lists are:

  1. marked - they have numbering;
  2. unmarked – elements are highlighted with symbols.

But all Word design is not suitable for publications on the site, so it’s worth learning how to properly format lists in HTML tags.
Tag bulleted list looks like that:

Unbulled list tag So:

Moreover, each list element has its own HTML frame:

It turns out that in order to highlight a bulleted list in the text using html code, you will need to combine both types of elements used. It will look like this:

  1. List item
  2. List item
  3. List item
  4. List item

For an unmarked list, similarly:

  • List item
  • List item
  • List item
  • List item

We've sorted out the lists. We can move on.

Text emphasis tags: bold and italic

When figuring out which tag allows you to correctly format the text, you almost immediately come across two code options for each case. This causes confusion among non-programmers and the question: what tag exactly does the customer need.

Everything is very simple! Tags offer physical and logical formatting options. The first ones are needed for users, the second ones are needed for search engines. “Search engines”, seeing the html code suitable for themselves, take into account the selected area and use the information received when ranking, so highlighting text using logical formatting will not be a mistake.

Using html tags makes it possible to please search engines and visually highlight the text for the user. What is more priority, decide for yourself:

Highlighting a phrase in bold for PS and users Bold phrase for users Italicizing phrases for PS and users Italicize a phrase for users

I have a large and very controversial article on the topic of bold tags, which is called.

If suddenly one of the programmers looks into the topic, then I hasten to note once again that the review is for copywriters: how to put tags, what they are and what is important to consider when choosing. And finally, one more popular html code required to highlight paragraphs. This

The opening tag is placed before the beginning of the paragraph, and the closing tag is placed at the end. If a paragraph ends with a list, then
is placed after all tags used for the list.

Well, some simple thematic infographics at the end:

When the discussion of the topic began in the comments, in the Club of Successful Copywriters an interesting answer was given for the info-graphics and article Feedback. Here is a screenshot of the opinion of an authoritative participant in the discussion.

Read: 6,687

Before answering the question " how to insert a picture in HTML?“, it should be noted that it is not worth overloading web pages with a huge amount of graphic material, since this will not only improve the visual perception of the resource by the user, but will also increase the page loading time.

When creating websites, the most commonly used graphic formats are PNG, GIF and JPEG, and for design work with images - graphics editor Adobe Photoshop, which has rich capabilities for compressing and resizing images without losing quality, which is incredibly important for web development.

How to insert an image in HTML?

To insert an image into an HTML page, use a single simple tag:

,

where xxx is the image address. If the image is in the same directory as the page, the tag will look like:

However, high-speed and stable internet has not yet reached all corners of the globe, and it happens that the image on the website simply does not load. For such cases, there is the concept of alternative text.

It is shown in place of the picture when it is unavailable, loading, or in the browser operating mode “without pictures”. It is added using the alt tag attribute .

Example of adding alternative text to a graphic file:

Alternative text

Assigning image sizes in HTML

In order to change the display dimensions of a graphic file, use the height and width tags, where height is the height and width is the width, measured in pixels.

When using these attributes, the browser first allocates space for graphic content, prepares the overall page layout, displays text, and then loads the image itself.

The picture is placed in a rectangle with the specified dimensions, and if the parameters are smaller or larger than the original ones, the picture is stretched or compressed.

If the height and width attributes are not used, the browser loads the image immediately, delaying the display of text and other page elements.

These parameters can be specified both in pixels (the size of the picture is constant and does not depend on the user’s screen resolution) and in percentages (the size of the picture depends on the screen resolution).

For example:

It should be remembered that at the moment when you change the original size of the image, it is necessary to maintain its proportions.

To do this, it is enough to specify the value of only one of the parameters ( width or height), and the browser will calculate the value of the second one automatically.

Image location in HTML

As with many HTML tags, Apply the align attribute, which aligns the image:

- the picture is located above the text;

- the picture is located below the text;

- the picture is located to the left of the text;

- the picture is located to the right of the text.

Picture link

This is done as follows:

As you can see, graphic insert can be a link and, when clicked, redirect to any address written in full or abbreviated form.

How can I make an image a background in HTML?

The image can not only be inserted onto the page as a visible object, but also made into the background. To define an image as a background, you need to specify the background=”xxx” attribute in the tag, where xxx is the address of the image, specified in the same way as in the examples above.

For example, let's set the following texture image as a background image:

Save the image in a folder with a prepared page and write the following lines:

Page with <a href="https://bmwworkshop.ru/en/html-kak-izobrazhenie-sdelat-fonom-kak-zadat-cvet-fona-v-html-absolyutnyi-i/">background picture</a></head>

Background with text.

The background image on the page is set.

Hello dear blog readers! In this article you will learn everything about how to insert an image into an html page. Do you have several images that you want to put on your page or do you want to put a logo on your site? All this is easy. After reading this article, you will be able to insert pictures into your html pages without any difficulties. To do this, we will talk in detail about img tag and its attributes, we'll take a quick look at graphic file formats such as gif, jpeg and png, and also look at new HTML5 features that make it easier to insert video and audio into your site.

Due to the fact that graphic data and html text cannot be combined in one file; to display them on the site, a different approach is used than with other elements of html pages. First of all, graphic images and other multimedia data are stored in separate files. And to embed them into a web page, special tags are used that contain links to these individual files. In particular, such a tag is img tag. Having encountered such a tag with an address, the browser first requests the corresponding file with an image, audio or video from the Web server, and only then displays it on the Web page.

All graphic images and, in general, any data that is stored in files separate from the web page are called implemented page elements.

Before inserting pictures and looking at the “img” tag in detail, it’s worth learning a little about graphic formats.

Graphic image formats.

There are many different graphic formats, but browsers only support a few. Let's look at three of them.

1. JPEG format(Joint Photographic Experts Group). Quite a popular format used for storing images. Supports 24-bit color and keeps all halftones in photos unchanged. But jpeg does not support transparency and distorts small details and text in images. JPEG is used primarily for storing photographs. Files in this format have the extensions jpg, jpe, jpeg.

2. GIF format(Graphics Interchange Format). The main advantage of this format is the ability to store several images at once in one file. This allows you to create entire animated videos. Secondly, it supports transparency. The main drawback is that it supports only 256 colors, which is not suitable for storing photos. GIF is mainly used to store logos, banners, images with transparent areas and containing text. Files in this format have the extension gif.

3. PNG format(Portable Network Graphics). This format was developed as a replacement for the legacy GIF and, to some extent, JPEG. Supports transparency, but does not allow animation. This format has a png extension.

When creating websites, they usually use images in JPEG or GIF format, but sometimes they use PNG. The main thing is to understand in which cases which format is better to use. In short:

    JPEG is best used for storing photographs or grayscale images that do not contain text;

  • GIF is used primarily for animation;
  • PNG is the format for everything else (icons, buttons, etc.).

Inserting images into html pages

So, how do you insert an image onto a web page? You can insert an image using a single img tag. The browser places the image at the location on the web page where it encounters the img tag.

Code for inserting a picture in html the page looks like this:

This html code will place on the web page an image stored in the image.jpg file, which is located in the same folder as the web page. As you may have noticed, the address of the picture is indicated in src attribute. I already told you what it is. So, the src attribute is a required attribute that serves to indicate the address of the file with the image. Without the src attribute, the img tag is meaningless.

Here are a few more examples of specifying the address of a file with an image:

This html code will insert an image on the page called image.jpg, which is stored in the images folder located at the root of the website.

The src attribute can contain more than just relative links to images. Since images are stored online along with html pages, so each image file has its own url. Therefore, you can insert the image url into the src attribute. For example:

This code will insert an image from the site mysite.ru onto the page. A URL is typically used when you are pointing to an image on another site. For images stored on your site, it is better to use relative links.

The img tag is an inline element, so it is better to place it inside a block element, for example inside the “P” tag - paragraph:

Let's practice and insert an image from previous articles about html onto our page. I will create a folder “images” next to the html file of my page and place a file with the image “bmw.jpg” there, which looks like this:

Then the html code of the page with the inserted image will be like this:

And look at the display result in the browser:

As we see, there is nothing complicated about placing images on web pages. Next, let's look at a few other important attributes of the "img" tag.

The alt attribute is a fallback option

Because image files are stored separately from web pages, the browser has to make separate requests to retrieve them. But what if there are a lot of images on the page and the network connection speed is low, then it will take a significant amount of time to download additional files. And it’s even worse if the image was deleted from the server without your knowledge.

In these cases, the web page itself will load successfully, only white rectangles will be displayed instead of images. Therefore, to tell the user what the image is, . Using this attribute, you specify the so-called replacement text, which will be displayed in an empty rectangle until the image is loaded:

And this is roughly what it looks like:

Set the dimensions of the image

There are still a couple of img tag attributes you should know about. This is a couple of attributes width And height. You can use these to specify the image dimensions:

Both attributes indicate the size in pixels. The width attribute tells the browser how wide the image should be, and the height attribute how tall it should be. These two attributes can be used together or separately. For example, if you specify only the width attribute, then the browser will automatically select the height in proportion to the specified width and also in the case of using only the height attribute. If you do not specify these attributes at all, the browser will automatically determine the size of the image before displaying it on the screen. It is only worth noting that specifying the image sizes will slightly speed up the browser when displaying the page.

That’s all about inserting images onto pages for now, then we’ll look at how to insert audio or video onto a website...

Inserting video and audio using HTML 5

The new html5 specification introduces several new tags that make it very easy to embed media files. This primarily applies to video and audio.

To insert audio HTML5 provides a paired tag AUDIO. The address of the file in which the audio clip is stored is indicated using the src attribute that is already familiar to us:

The "audio" tag creates on the page block element. By default, the browser will not play the audio clip. For it to do this, you need to specify a special attribute in the audio tag autoplay. Special because it doesn't matter. The mere presence of this attribute in the tag is enough for it to take effect.

By default, the audio clip is not displayed on the web page. But if you put an attribute without a value in the “audio” tag controls, the browser will display controls for playing the audio clip in the place on the web page where the audio tag is placed. They include a play/pause button, a playback bar, and a volume control.

the body of the table is located. The body consists of rows and columns. The table is filled in line by line.

Each tag creates new line. Further in nested columns are created. You can create multiple columns. In this case, you need to monitor the number of columns in each row. For example, if the first row had 5 columns, then the following rows should also have 5 columns. Otherwise the table will float. It is possible to merge cells.

How to make a table in html

Let's give an example, html code:

Example table
Column 1 Column 2

Pay attention to the cell . We use the special colspan attribute to span cells horizontally. Its numeric value indicates the number of columns to be merged. There is also an analogue of this attribute: tag (table header), where you also need to enter colspan. The result will be the same. But often they use regular td.

Now let's take a closer look at all the tag attributes

.

Tag Attributes and Properties

To opening tag

You can specify various attributes.

1. Property align="parameter" - sets the table alignment. Can take the following values:

In the example above, we aligned the table to the center align="center" .

This attribute can be applied not only to the table, but also to individual table cells

. Thus, the alignment will be different in different cells.

For example

, , , or
  • cols - line is displayed between columns
  • none - all borders are hidden
  • rows - a border is drawn between table rows created through the tag
  • 12. Property width="number" - sets the width of the table: either in pixels or in percentages.

    13. Property class="class_name" - you can specify the name of the class to which the table belongs.

    14. Property style="styles" - styles can be set individually for each table.

    Now it's time to dive inside the table and look at the attributes of the table cells. These attributes should be written in the opening tag

    And The same options are available as for will be hierarchically applied to all
    or lines
    ... ... ...

    2. Property background="URL" - sets background picture. Instead of the URL, the address of the background image should be written.

    Example

    Example table
    Column 1 Column 2

    Converts to the following on the page:

    In the example considered, our background image is located in the img folder (which is in the same directory as the html page), and the image is called fon.gif . Please note that in the tag we added style="color:white;" . Since the background is almost black, to prevent the text from blending into the background, we made the text white.

    3. Property bgcolor="color" - sets the background color of the table. You can choose any color from the entire palette (see codes and names of html colors)

    4. Property border="number" - sets the thickness of the table border. In previous examples, we specified border="1" , which means the border thickness is 1 pixel.

    5. Property bordercolor="color" - sets the color of the border. If border="0" then there will be no border and the border color will have no meaning.

    6. Property cellpadding="number" - indent from the frame to the cell contents in pixels.

    7. Property cellspacing="number" - the distance between cells in pixels.

    8. Property cols="number" - number of columns. If you do not set it, the browser itself will determine the number of columns. The only difference is that specifying this parameter will most likely speed up the loading of the table.

    9. Property frame="parameter" - how to display borders around the table. Can take the following values:

    • void - do not draw borders
    • border - border around the table
    • above - border along the top edge of the table
    • below - border at the bottom of the table
    • hsides - add only horizontal borders (top and bottom of table)
    • vsides - draw only vertical borders (to the left and right of the table)
    • rhs - border only on the right side of the table
    • lhs - border only on the left side of the table

    10. Property height="number" - sets the height of the table: either in pixels or in percentages.

    11. Property rules="parameter" - where to display borders between cells. Can take the following values:

    • all - a line is drawn around each table cell
    • groups - a line is displayed between groups formed by tags
    .

    Attributes and Properties

    1. Property align="parameter" - sets the alignment of an individual table cell. Can take the following values:

    • left - left alignment
    • center - center alignment
    • right - right alignment

    2. Property background="URL" - sets the background image of the cell. Instead of the URL, the address of the background image should be written.

    3. Property bgcolor="color" - sets the background color of the cell.

    4. Property bordercolor="color" - sets the color of the cell border.

    5. Property char="letter" - specifies the letter from which the alignment should be made. The value of the align attribute must be set to char.

    6. Property colspan="number" - sets the number of horizontal cells to be merged.

    7. Property height="number" - sets the height of the table: either in pixels or as a percentage.

    8. Property width="number" - sets the width of the table: either in pixels or as a percentage.

    9. Property rowspan="number" - sets the number of vertical cells to be merged.

    10. Property valign="parameter" - vertical alignment of the cell contents.

    • top - align cell contents to the top edge of the row
    • middle - middle alignment
    • bottom - alignment to the bottom edge
    • baseline - alignment to the baseline
    Note 1

    For tag

    . Parameters for one tag
    inside him

    How to prevent cell borders in a table from sticking together

    If you use a border (cell border) and zero padding between cells, they are still stuck together and you get a double border . To avoid this, you need to specify border-collapse: collapse in the table styles:

    ...

    Dear reader, now you have learned much more about html tag table. Now I advise you to move on to the next lesson.

    To insert images in HTML The two main formats used are GIF and JPEG. The GIF format can store the simplest animation (dynamic banners), JPEG is great for images with big amount flowers, such as photographs. The third format for web graphics is PNG, but it is not widely used in web design. Any image in GIF or JPEG formats is inserted onto a web page using the tag < img > , there is no closing tag.

    SRC attribute

    Via attribute src the address (URL) of the image file is specified, i.e. the browser finds the desired image in the site directory using the path (URL) specified in this attribute. For convenience, all site images are in separate folder, usually with a name image. For example, take any image, preferably a small format, and save it in the created folder image, with the name primer.jpg. Next we will refer to it for training.

    Well, let's try to insert a picture on the page? We write the code (path - URL, written depending on the location of the folder with images):

    < img src="image/primer.jpg">

    Alternative text. ALT attribute

    Why is alternative text specified? Let's go in order. Every browser has a function to disable images, so a user using such a function can see the description specified in the tag alt, which represents the image. This may not be relevant today, since preference is given to unlimited tariffs, but still this is considered a rule of good manners. Let's look at the code example:

    You can see this only by turning off the display of images in the browser.

    Set the size. WIDTH and HEIGHT attributes

    Let me note right away that width and height are very important parameters, so you shouldn’t ignore them. Judge for yourself, with unspecified image sizes, and with images disabled in the browser, when images do not load, small empty squares may be located in a completely different place from where you planned to place them. This will not add beauty to the page. Therefore, do not be lazy and always write down the dimensions in the HTML code.

    Image sizes are set using tags width- width and height— height, values ​​are set both in pixels and as a percentage of the screen width (with percentages, be very careful). Let's look at the code:

    Conclusion

    Images attract site visitors, carry a lot of visual information, are easy to use, but you still need to follow some recommendations if you want to create a good, popular site.

    You should not use too large image file sizes, as this will affect page loading speed. Believe me, this is far from the last indicator.

    The ALT attribute is very important and must be added to every IMG tag. Content text message must describe the image very accurately, and briefly.

    Images on a web page must correspond to the text content.

    After studying this section, you can already try yourself as a webmaster and create a full-fledged HTML page. And then let's move on to inserting multimedia.