Lessons 20 · 1 lessons · N. I. Taylaqov (general editor), A. B. Akhmedov, M. D. Pardayeva, A. A. Abdug‘aniyev, U. M. Mirsanov. Informatics and Information Technologies, Grade 11, 1st edition. “Extremum-press”, Tashkent, 2018
20
Placing and decorating pictures and graphics on web pages
Textbook: pp. 73–76
GoalPlaces a picture on a web page (the img tag, src, alt, size), chooses the picture format and size for a page, and decorates the page with colours, borders and fonts using CSS.
New words
<img> tag: puts a picture on the page; src gives the file and alt gives a text description · <img> tegialt text: a short description of a picture for screen readers and for when the picture does not load · alt matnCSS: the language that sets colours, fonts, sizes and layout of HTML elements · CSScontrast: the difference in brightness between text and background; low contrast is hard to read · kontrast
Explanation
On a web page pictures are placed with the <img> tag of HTML: the src attribute gives the file path, alt gives a short text description of the picture, and width and height give its size (in pixels). If the picture file is in the same folder as the page, the path is just the file name; in another folder it is written like “images/club.jpg”. For the web, JPEG (photographs), PNG (transparency and crisp lines), SVG (vector, sharp even when enlarged) and the modern WebP are convenient. The file size of a picture affects page speed: to show a 4000×3000 pixel photo in a 300-pixel box it is wasteful to upload it as it is; before uploading it should be reduced to the needed size (in PhotoShop, Image → Image Size) and compressed. The look of the page is set with CSS: color – text colour, background – background, border – border, padding – inner space, margin – outer space, font-family – font, text-align – alignment; the rules are written inside <style> or in a separate .css file. Colours are given by a #RRGGBB (hexadecimal) code. The contrast between text and background must be sufficient: at least 4.5:1 is recommended for ordinary text (white text on #0b5cad is about 6.7:1, on #1e90ff only about 3.2:1, which suits only very large headings). Do not copy a picture from another site: respect copyright and use your own picture or one with a free licence.
Worked examples
A club page: <!DOCTYPE html> ⏎ <html lang="uz"> ⏎ <head> ⏎ <meta charset="utf-8"> ⏎ <title>Maktab klubi</title> ⏎ <style> ⏎ body { font-family: Arial, sans-serif; background: #f4f8ff; margin: 0; } ⏎ header { background: #0b5cad; color: #ffffff; padding: 16px; text-align: center; } ⏎ .karta { width: 300px; margin: 20px auto; background: #ffffff; padding: 12px; } ⏎ img { max-width: 100%; height: auto; border: 3px solid #0b5cad; } ⏎ </style> ⏎ </head> ⏎ <body> ⏎ <header><h1>Informatika klubi</h1></header> ⏎ <div class="karta"> ⏎ <img src="klub.jpg" alt="Klub a’zolari kompyuter oldida" width="300" height="200"> ⏎ <p>Klub har juma kuni soat 15:00 da yig‘iladi.</p> ⏎ </div> ⏎ </body> ⏎ </html> “klub.jpg” must be in the same folder as the page; if the picture is missing, the alt text is shown. max-width: 100% makes the picture fit even on a phone screen.
A size calculation: if a page has 5 pictures of 2 MB each, the total is 10 MB = 80 Mbit; at 10 Mbit/s it loads in 80:10 = 8 seconds. If the pictures are reduced to 400 KB each, the total is 2 MB = 16 Mbit and loading takes 1.6 seconds.
Class activity
“A fast and good-looking page”: pairs reduce one large photo for the web in PhotoShop (800 pixels wide), save it as JPEG, compare its size with the original and place it on a page with alt text.
Practice
1
What do the src, alt, width and height attributes of the <img> tag mean?
src – the file path; alt – the text description; width and height – the width and height (pixels).
2
A page has 3 pictures of 1.5 MB each (4.5 MB in all). How many seconds does it take to load at 9 Mbit/s (1 byte = 8 bits)?
4
3
Write the HTML line that places “gul.png” 200 pixels wide with the alt text “Qizil gul”.
<img src="gul.png" alt="Qizil gul" width="200">
4
Why is it better to shrink the file itself rather than only show a large photo smaller with width?
The browser still downloads the whole large file, which increases data use and loading time; a reduced file loads faster.