Skip to content

Instantly share code, notes, and snippets.

@luizbills
Created February 24, 2025 16:52
Show Gist options
  • Save luizbills/79393b217a65fcb7e87e3046a30b43d9 to your computer and use it in GitHub Desktop.
Save luizbills/79393b217a65fcb7e87e3046a30b43d9 to your computer and use it in GitHub Desktop.
How to make an html5 canvas center horizontally and vertically
<!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>
@luizbills
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment