Open In App

Graphics Explanation in HTML5

In this article, we will explain the concept of graphics in HTML5. Graphics are representations used to make web-page or applications visually appealing and also for improving user experience and user interaction. Some examples of graphics are photographs, flowcharts, bar graphs, maps, engineering drawings, constructional blueprints, etc. Usually, the following technologies are used in web graphics with HTML5 Canvas API, WebCGM, CSS, SVG, PNG, JPG, etc.

SVG (Scalable Vector Graphics)



Example: The following demonstrates the SVG in markup form.




<!DOCTYPE html>
<body>
   <svg width="550" height="50" viewBox="0 0 550 50"
        fill="green" xmlns="http://www.w3.org/2000/svg">
        <text x="0" y="20">I love GeeksforGeeks</text>
    <svg>
</body>
</html>

Output:



SVG text

 

PNG (Portable Network Graphics)

Example:




<!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">
</head>
<body>
    <img src=
    >
    </img>
</body>
</html>

Output:

JPG or JPEG (Joint Photographic Experts Group)

Example:




<!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">   
</head>
<body>
    <img src=
    >
    </img>
</body>
</html>

Output:

CSS (Cascading Style Sheets):

Example: 




<!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">
    <link rel="stylesheet" href="styles.css"></link>
</head>
<body>
   <div class="star"></div>
</body>
</html>

 styles.css: The following code is used in the above HTML file.

body {
  position: relative;
}

.star {
  position: absolute;
  width: 423px;
  height: 384px;
  left: 456.7px;
  top: 80.34px;
  background: #346d33;
  transform: rotate(18.69deg);
}

Output:

Canvas API:

Example:




<!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">  
</head>
<body>
<canvas id="canvas1" width="400" height="200"
        style="border:2px solid green; border-radius:35px">
    Your browser does not support the canvas element.
</canvas>
</body>
</html>

Output:

WebCGM (Web Computer Graphics Metafile)

So, the graphics are used to make a web page, application, or any digital element that need visual interaction especially HTML5 based, need Graphics for the best User Experience.


Article Tags :