Created
February 24, 2025 16:52
-
-
Save luizbills/79393b217a65fcb7e87e3046a30b43d9 to your computer and use it in GitHub Desktop.
How to make an html5 canvas center horizontally and vertically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width" /> | |
<style> | |
html, | |
body { | |
height: 100%; | |
} | |
body { | |
margin: 0; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
} | |
</style> | |
</head> | |
<body> | |
<canvas width="480" height="320" style="background: tomato;"></canvas> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example with Litecanvas