2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Images in HTML
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Introduction
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								You can define images by using the `<img>`  tag. It does not have a closing tag since it can contain only attributes.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								To insert an image you define the source and an alternative text wich is displayed when the image can not be rendered.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-15 20:10:32 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`src`  - This attribute provides the url to image present either on your desktop/laptop or to be included from some other website. Remember the link provided should not be broken otherwise the image will not be produced on your webpage. 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-03-21 12:43:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`alt`  - This attribute is used to overcome the problem of a broken image or the incapability of your browser not being able to produce the image on the webpage. This attribute, as the name suggests, provides an "alternative" to the image which is some text describing the image. 
						 
					
						
							
								
									
										
										
										
											2018-10-19 20:45:13 +07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-13 21:58:53 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Example
  
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< img  src = "URL of the Image"  alt = "Descriptive Title"  / >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### To define height and width of an image you can use the height and width attribute:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< img  src = "URL of the Image"  alt = "Descriptive Title"  height = "100"  width = "150" / >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-13 21:58:53 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Define border thickness (0 means no border):
  
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< img  src = "URL of the Image"  alt = "Descriptive Title"  border = "2" / >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Align an image:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< img  src = "URL of the Image"  alt = "Descriptive Title"  align = "left" / >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-13 21:58:53 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Use styles within a style attribute:
  
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< img  src = "URL of the Image"  alt = "Descriptive Title"  style = "width: 100px; height: 150px;" / >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-13 21:58:53 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Make a rounded image:
  
						 
					
						
							
								
									
										
										
										
											2018-10-19 20:45:13 +07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< img  src = "URL of the Image"  alt = "Descriptive Title"  style = "border-radius: 50%;" / >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-12-13 21:58:53 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Use image as link:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< a  href = "#" > < img  src = "URL of the Image"  alt = "Descriptive Title" . " > < / a >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-10-19 20:45:13 +07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### More Information
  
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-15 20:10:32 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  See the freeCodeCamp page on the `<img>`  tag [here ](https://guide.freecodecamp.org/html/elements/img-tag ) 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								-  To get more details on images in HTML, check out the [MDN Docs ](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Img )