Open In App

HTML canvas font Property

The HTML canvas font Property is used to change the present font family of the Text content of the <canvas> element. The font Property has a Default Property i.e 10px sans-serif

Syntax:



  context.font="italic small-caps bold 12px arial"; 

Property Values:

Example:




<!DOCTYPE html>
<html>
  
<head>
    <title>
      HTML canvas font Property
  </title>
</head>
  
<body style="text-align:center">
  
    <h1 style="color:green">
      GeeksForGeeks
  </h1>
    <h2 style="color:green">
      HTML canvas font Property
  </h2>
    <canvas id="sudo" 
            width="300"
            height="150"
            style="border:2px solid">
  </canvas>
  
    <script>
        var c = document.getElementById("sudo");
        var ctx = c.getContext("2d");
        ctx.font = "40px Arial";
        ctx.fillText("GeeksForGeeks", 10, 50);
    </script>
  
</body>
  
</html>

Output:



Supported Browsers: The browsers supported by HTML canvas font Property are listed below:


Article Tags :