Difference between <figure> & <img> tags in HTML - GeeksforGeeks (2024)

Last Updated : 27 Feb, 2024

Summarize

Comments

Improve

In this article, we will learn about the <figure> & <img> tag along with its implementation. We will also learn the differences between them. Let’s begin the discussion with the figure tag in HTML.

Table of Content

  • HTML <figure> Tag:
  • HTML <img> Tag:
  • Difference between <figure> and <img> tags:

HTML <figure> Tag

The <figure> tag in HTML5 is used to add self-contained content like illustrations, diagrams, photos, or codes listing in a document. It is related to the main flow, but it can be used in any position of a document and the figure goes with the flow of the document and if remove it then it should not affect the flow of the document. In simple words, the figure tag is used to semantically organize the content of images, videos, audios or even charts or tables, block of codes in the HTML document.

Syntax:

<figure> <img src="url"> <figcaption>content</figcaption></figure>

Attributes: It contains mostly two tags which are given below:

Attribute Value

Description

mg src

This tag is used to add an image source in the document.

figcaption

This tag is used to set the caption to the image. It is optional to use.

Example: This example illustrates the use of the <figure> tag along with src, width, height & alt attributes.

HTML

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8" />

<meta http-equiv="X-UA-Compatible"

content="IE=edge" />

<meta name="viewport"

content="width=device-width, initial-scale=1.0" />

<title>Document</title>

<style>

figure {

border: 2px solid black;

padding: 5px;

}

</style>

</head>

<body>

<figure>

<img src=

"https://media.geeksforgeeks.org/wp-content/uploads/20210827151326/gfg-200x200.png"

alt="image"

width="200px" height="200px" />

<figcaption>Geeks For Geeks</figcaption>

</figure>

</body>

</html>

Output: In this case the <figure> tag, it has made all the changes, as the image with caption is properly aligned with some space away from the margin. The image and caption are part of each other. The border is added to both <figure> tag and <figcaption> tag, both have occupied the border. <figure> tag is inline element.

Difference between <figure> & <img> tags in HTML - GeeksforGeeks (1)

<figure> tag

HTML <img> Tag:

HTML <img> tag is used to add image or to set the background in the webpage/website. Nowadays website does not directly add images to a web page, as the images are linked to web pages by using the <img> tag which holds space for the image.

Syntax :

<img src="url" alt="some_text">

Attributes:

Attribute value

Description

src

It is used to specifies the URL path of the source image.

alt

It is used to specifies an alternate text for the image if the image for some reason cannot be displayed.

Example: In this example, we are using the <img> tag along with src, width, height, and alt attributes.

HTML

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<meta name="viewport"

content="width=device-width, initial-scale=1.0" />

<title>Document</title>

<style>

img {

border: 2px solid black;

padding: 5px;

}

</style>

</head>

<body>

<img src=

"https://media.geeksforgeeks.org/wp-content/uploads/20210827151326/gfg-200x200.png"

alt="image"

width="200px" height="200px" />

<p>Geeks For Geeks</p>

</body>

</html>

Output: In the case of the <img> tag, it is not properly aligned and is very close to the margin, and the caption is away from the image. The image and caption are not part of each other. The border is not the part of both image and caption. <img> tag is an inline element but when we specify width and height it becomes a block element.

Difference between <figure> & <img> tags in HTML - GeeksforGeeks (2)

tag

S.No.

<figure> Tag

<img> Tag

1.The figure tag is used to semantically organize the content of images, videos, audios or even charts or tables, block of codes in the HTML document.The image tag is used to add an image to an HTML page. <img> tag can only insert image.
2.<figure> tag is a container tag.<img> tag is a void tag.
3.This tag provides a container for content that is equivalent to a figure or diagram in a book.The HTML <img> tag is used for embedding images into an HTML document.
4.This tag is inline element.It is an inline element but when we specify width and height it becomes a block element.
5.You can use the figure element in conjunction with the figcaption element to provide a caption for the contents of your figure element.In image tag there’s no special tag for caption rather we can use <p> tag or <span> tag to add pseudo captions.
6.It makes it easy for the machine to understand the code. Easy to get on search engines.It is difficult for machines to understand.
7.The <figure> element itself may contain multiple other child elements be it a block of code, images, audios, video etc.The <img> tag can not have multiple elements inside it only images can be added in <img> tag.
8.The figure tag contains default alignment and styling.The image tag does not contain any default alignment and styling.


C

codeutin

Difference between <figure> & <img> tags in HTML - GeeksforGeeks (3)

Improve

Next Article

Difference between <i> and <em> tag of HTML

Please Login to comment...

Difference between <figure> & <img> tags in HTML - GeeksforGeeks (2024)
Top Articles
How to Invest in Socially Responsible Companies while Timing the Market
19-Year-Old Demands Payback for Mom's Debts: Will She Get Her Due? 😲💸
#ridwork guides | fountainpenguin
Overton Funeral Home Waterloo Iowa
Wizard Build Season 28
What happened to Lori Petty? What is she doing today? Wiki
Women's Beauty Parlour Near Me
Phenix Food Locker Weekly Ad
30% OFF Jellycat Promo Code - September 2024 (*NEW*)
Routing Number 041203824
Https Www E Access Att Com Myworklife
Espn Expert Picks Week 2
Bubbles Hair Salon Woodbridge Va
Valentina Gonzalez Leaked Videos And Images - EroThots
litter - tłumaczenie słowa – słownik angielsko-polski Ling.pl
fltimes.com | Finger Lakes Times
2016 Hyundai Sonata Price, Value, Depreciation & Reviews | Kelley Blue Book
Aktuelle Fahrzeuge von Autohaus Schlögl GmbH & Co. KG in Traunreut
Washington Poe en Tilly Bradshaw 1 - Brandoffer, M.W. Craven | 9789024594917 | Boeken | bol
Q Management Inc
Convert 2024.33 Usd
St Maries Idaho Craigslist
Accuweather Mold Count
Uconn Health Outlook
Marion City Wide Garage Sale 2023
Japanese Mushrooms: 10 Popular Varieties and Simple Recipes - Japan Travel Guide MATCHA
Renfield Showtimes Near Paragon Theaters - Coral Square
2000 Ford F-150 for sale - Scottsdale, AZ - craigslist
Sorrento Gourmet Pizza Goshen Photos
Rek Funerals
R/Mp5
The Venus Flytrap: A Complete Care Guide
Rocksteady Steakhouse Menu
Pnc Bank Routing Number Cincinnati
Wow Quest Encroaching Heat
Blue Beetle Movie Tickets and Showtimes Near Me | Regal
Hermann Memorial Urgent Care Near Me
Tal 3L Zeus Replacement Lid
Grapes And Hops Festival Jamestown Ny
Spn-523318
Publictributes
Telugu Moviez Wap Org
Low Tide In Twilight Manga Chapter 53
Weather Underground Cedar Rapids
Trivago Anaheim California
Tattoo Shops In Ocean City Nj
Does Target Have Slime Lickers
Oklahoma City Farm & Garden Craigslist
Doe mee met ons loyaliteitsprogramma | Victoria Club
7 Sites to Identify the Owner of a Phone Number
Latest Posts
Article information

Author: Frankie Dare

Last Updated:

Views: 6629

Rating: 4.2 / 5 (73 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Frankie Dare

Birthday: 2000-01-27

Address: Suite 313 45115 Caridad Freeway, Port Barabaraville, MS 66713

Phone: +3769542039359

Job: Sales Manager

Hobby: Baton twirling, Stand-up comedy, Leather crafting, Rugby, tabletop games, Jigsaw puzzles, Air sports

Introduction: My name is Frankie Dare, I am a funny, beautiful, proud, fair, pleasant, cheerful, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.