{"id":20082,"date":"2022-10-05T12:14:59","date_gmt":"2022-10-05T12:14:59","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=9234"},"modified":"2022-10-05T12:14:59","modified_gmt":"2022-10-05T12:14:59","slug":"html-images","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/10\/05\/html-images\/","title":{"rendered":"HTML Images"},"content":{"rendered":"\n<p>To embed an image to a web page use the\u00a0&lt;img>\u00a0tag.<\/p>\n\n\n\n<p>The &lt;img&gt; tag supports a number of required and optional attributes, which give additional information about it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"syntax-2\">Syntax<\/h2>\n\n\n\n<p>The &lt;img> tag is empty, which means that the closing tag isn\u2019t required. It contains only attributes. But in\u00a0XHTML, the (&lt;img>) tag must be closed (&lt;img\/>).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"required-image-attributes-span-class-attribute-src-span-and-span-class-attribute-alt-span-4\">Required Image Attributes &#8211;&nbsp;src&nbsp;and&nbsp;alt<\/h2>\n\n\n\n<p>The&nbsp;src&nbsp;(source) attribute specifies the name or the location of the image to be displayed. The value of&nbsp;src&nbsp;attribute should contain the name of the image file or its URL.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;img src=\"example.jpg\" \/&gt;\n or\n&lt;img src=\"https:\/\/www.example.com\/images\/example.jpg\" \/&gt;<\/code><\/pre>\n\n\n\n<p>The&nbsp;alt&nbsp;attribute is also required for the&nbsp;<strong>&lt;img&gt;<\/strong>&nbsp;tag. It is used to provide browsers with an alternate text in case when the image cannot be displayed (in case of slow connection, when a screen reader is used, etc). Browsers often display the alternative text of the image as a pop-up when you put your mouse over it.<\/p>\n\n\n\n<p>Syntax of the &lt;img&gt; tag with required&nbsp;src&nbsp;and&nbsp;alt&nbsp;attributes will look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;img src=\"https:\/\/www.w3docs.com\/learn-html\/\" alt=\"HTML tutorial\" \/&gt;<\/code><\/pre>\n\n\n\n<p>Use&nbsp;alt&nbsp;attribute for all your images to provide keyword-rich description for search engines to improve rankings of your web pages.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"recommended-image-attributes-span-class-attribute-width-span-and-span-class-attribute-height-span-10\">Recommended Image Attributes &#8211;&nbsp;width&nbsp;and&nbsp;height<\/h2>\n\n\n\n<p>The&nbsp;width&nbsp;and&nbsp;height&nbsp;attributes are strongly recommended to use with &lt;img&gt; tag. If these attributes are used, the browser reserves the place for the image when loading the content, and this speeds up rendering the page.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;img src=\"https:\/\/www.w3docs.com\/learn-html\" alt=\"HTML tutorial\" width=\"200\" height=\"120\" \/&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-of-the-html-lt-img-gt-tag-with-the-span-class-attribute-src-span-span-class-attribute-alt-span-span-class-attribute-width-span-and-span-class-attribute-height-span-attributes-13\">Example of the HTML &lt;img&gt; tag with the&nbsp;src,&nbsp;alt,&nbsp;width&nbsp;and&nbsp;height&nbsp;attributes:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;Title of the document&lt;\/title&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;h1&gt;Place for your heading &lt;\/h1&gt;\n    &lt;p&gt;This is Aleq's photo&lt;\/p&gt;\n    &lt;img src=\"\/uploads\/media\/default\/0001\/01\/25acddb3da54207bc6beb5838f65f022feaa81d7.jpeg\" alt=\"Aleq\" width=\"200\" height=\"185\"\/&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"result-15\">Result<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/mdr.foobrdigital.com\/wp-content\/uploads\/2022\/10\/image-26.png\" alt=\"\" class=\"wp-image-9235\"\/><\/figure>\n\n\n\n<p>Instead of using the width and height dimensions, you could set the size using CSS\u00a0max-width\u00a0or\u00a0max-height\u00a0properties to get extra flexibility. This can prevent large images from ruining your layout on a device with a small screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"image-floating-18\">Image Floating<\/h2>\n\n\n\n<p>Generally, the text is above an image, by default. But the position of the image and text can easily be changed with the\u00a0CSS float property\u00a0. This property specifies how the image should float, or how the text should be wrapped around it.<\/p>\n\n\n\n<p>To show the picture on the left side, and text on the right side, add&nbsp;style=&#8221;float:left&#8221;&nbsp;to the &lt;img&gt; tag.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-of-the-lt-img-gt-tag-and-the-css-float-property-for-floating-an-image-to-the-left-20\">Example of the &lt;img&gt; tag and the CSS float property for floating an image to the left:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;Title of the document&lt;\/title&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;h1&gt;Place for your heading &lt;\/h1&gt;\n    &lt;img src=\"\/uploads\/media\/default\/0001\/01\/25acddb3da54207bc6beb5838f65f022feaa81d7.jpeg\" alt=\"Aleq\" width=\"200\" height=\"185\" style=\"float:left\"\/&gt;\n    &lt;p&gt;Aleq's photo&lt;\/p&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>Adding&nbsp;style=&#8221;float:right&#8221;&nbsp;attribute to the &lt;img&gt; tag positions the text to the left, and the image to the right.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-of-the-lt-img-gt-tag-and-the-css-float-property-for-floating-an-image-to-the-right-23\">Example of the &lt;img&gt; tag and the CSS float property for floating an image to the right:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;Title of the document&lt;\/title&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;h1&gt;Place for your heading &lt;\/h1&gt;\n    &lt;img src=\"\/uploads\/media\/default\/0001\/01\/25acddb3da54207bc6beb5838f65f022feaa81d7.jpeg\" alt=\"Aleq\" width=\"200\" height=\"185\" style=\"float:right\"\/&gt;\n    &lt;p&gt;Aleq's photo&lt;\/p&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"result-strong-25\">Result<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/mdr.foobrdigital.com\/wp-content\/uploads\/2022\/10\/image-28.png\" alt=\"\" class=\"wp-image-9237\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-add-hyperlink-to-an-image-27\">How to add hyperlink to an image<\/h2>\n\n\n\n<p>As the\u00a0&lt;a>\u00a0tag is used for inserting hyperlinks, you just need to put the image in the &lt;a> tag to make your image clickable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-of-the-lt-a-gt-and-lt-img-gt-tags-for-adding-a-hyperlink-to-an-image-29\">Example of the &lt;a&gt; and &lt;img&gt; tags for adding a hyperlink to an image:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;Title of the document&lt;\/title&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;a href=\"https:\/\/www.w3docs.com\/\" aria-label=\"w3docs homepage\"&gt;\n    &lt;img src=\"\/uploads\/media\/default\/0001\/01\/0710cad7a1017902166203def268a0df2a5fd545.png\" width=\"190\" height=\"45\" alt=\"logo\"\/&gt;\n    &lt;\/a&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-image-format-to-choose-for-web-31\">What image format to choose for web<\/h2>\n\n\n\n<p>There are three main types of image formats supported by browsers:<\/p>\n\n\n\n<ul><li>GIF (Graphics Interchange Format)<\/li><li>JPG \/ JPEG (Joint Photographic Experts Group)<\/li><li>PNG (Portable Network Graphics)<\/li><\/ul>\n\n\n\n<p><strong>GIF<\/strong>&nbsp;has 256 unique colors that make simple and fast-loading graphics. You can use GIF for small drawings, diagrams, charts, buttons, and other simple graphics, that won\u2019t prevent your page from loading fast.<\/p>\n\n\n\n<p><strong>JPEG<\/strong>&nbsp;being a 16-bit format can blend red, blue and green light to display millions of colors. Thus it is used mainly for photographs. This format gives you the flexibility to choose how much to compress your image \u2013 from 0% (heavy compression) to 100% (no compression). You can choose this format if you don\u2019t mind giving up some quality for a reduction in size. Avoid using JPEG for images with text, shapes, or large color blocks, because when the file is compressed, the lines will blur and colors will shift.<\/p>\n\n\n\n<p><strong>PNG<\/strong>&nbsp;format combines all the benefits both the JPEG and GIF formats have, it has millions of colors and allows to compress the file with no loss in quality. You can use PNG for web graphics that require transparency, color heavy, and complex graphics or photographs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"modern-image-formats-33\">Modern image formats<\/h2>\n\n\n\n<p>Today, several modern image formats are used for the web to have smaller, richer, and faster-loading images.<\/p>\n\n\n\n<p><strong>WebP<\/strong>\u00a0designed by Google provides lossless and lossy compression for images on the web. Its main goal is to become the primary format for photographs on the web replacing JPEG. (WebP &#8211; Wikipedia)<\/p>\n\n\n\n<p>Another format designed to replace JPEG format is&nbsp;<strong>BPG<\/strong>&nbsp;(Better Portable Graphics), which also boasts high compression ratio (files are smaller than JPEG with the same quality).<\/p>\n\n\n\n<p><strong>HEIC<\/strong>&nbsp;is a new image format that Apple uses instead of JPEG in iOS 11. This format utilizes modern compression methods, which make it possible to have higher image quality in smaller files.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To embed an image to a web page use the\u00a0&lt;img>\u00a0tag. The &lt;img&gt; tag supports a number of required and optional attributes, which give additional information about it. Syntax The &lt;img> tag is empty, which means that the closing tag isn\u2019t required. It contains only attributes. But in\u00a0XHTML, the (&lt;img>) tag must be closed (&lt;img\/>). Required [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[480],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/20082"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=20082"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/20082\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=20082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=20082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=20082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}