

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML5 Canvas Font Size Based on Canvas Size
To scale fonts, let us see an example.
Canvas: 800px Font Size: 60px
You need to use the following code for our example to scale font size based on canvas −
var fontBase = 800; var fontSize = 60; function getFont() { var ratio = fontSize / fontBase; var cSize = canvas.width * ratio; return (cSize |0) + 'px sans-serif'; }
- Related Questions & Answers
- HTML5 Canvas Text Stroke for Large Font Size
- How to draw large font on HTML5 Canvas?
- Fractional font sizes for HTML5 Canvas?
- How to set the font size of a Tkinter Canvas text item?
- addEventListener for keydown on HTML5 Canvas
- Update HTML5 canvas rectangle on hover
- Translating HTML5 canvas
- HTML5 Canvas distorted
- HTML5 Canvas Transformation
- How to detect point on canvas after canvas rotation in HTML5
- Play video on canvas and preserve the last frame/image on HTML5 Canvas
- World Map on HTML5 Canvas or SVG
- HTML5 Canvas Transformation Matrix
- HTML5 Canvas Circle Text
- HTML5 Canvas Degree Symbol
Advertisements