# Blurry elements in HTML5

**URL:** <https://forum.kirupa.com/t/blurry-elements-in-html5/667997>\
**Category:** web dev\
**Created:** [July 4, 2024, 9:23pm UTC](https://forum.kirupa.com/t/blurry-elements-in-html5/667997 "2024-07-04T21:23:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AleCGames](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AleCGames](https://forum.kirupa.com/u/AleCGames)\
**Post date:** [July 4, 2024, 9:23pm UTC](https://forum.kirupa.com/t/blurry-elements-in-html5/667997/1 "2024-07-04T21:23:57Z")

</div>

Hi there,

I’m new to this forum. I create my games using Solar2D, but a disadvantage in HTML5 is that the images and text appear blurry. I’ve found some solutions online, but the main issue is that they all use a ‘2d’ context, while Solar2D uses WebGL (webgl or webgl2). I’m unsure how to adapt the following code:

```auto

function fix_dpi() {
          //get DPI
          let dpi = window.devicePixelRatio;
          //get canvas
          let canvas = document.getElementById('canvas');
          //get context
          let ctx = canvas.getContext('2d');
          //get CSS height
          //the + prefix casts it to an integer
          //the slice method gets rid of "px"
          let style_height = +getComputedStyle(canvas).getPropertyValue("height").slice(0, -2);
          //get CSS width
          let style_width = +getComputedStyle(canvas).getPropertyValue("width").slice(0, -2);
          //scale the canvas
          canvas.setAttribute('height', style_height * dpi);
          canvas.setAttribute('width', style_width * dpi);
        }

```

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [July 5, 2024, 2:41am UTC](https://forum.kirupa.com/t/blurry-elements-in-html5/667997/2 "2024-07-05T02:41:00Z")

</div>

Hi @AleCGames - here is an easier example:

> **[Ensuring our Canvas Looks Good on Retina/High-DPI Screens](https://www.kirupa.com/canvas/canvas_high_dpi_retina.htm)**
>
> Learn how to implement some sweet downsampling techniques to ensure what we create on the canvas looks sharp and crisp even on high-DPI screens.

The way to fix the blurriness is to scale the visuals down. When you do that, everything gets smaller. The solution then is to scale everything up first, draw what you need to draw, and then scale things back down again. It’s very primitive, but it does get the job done.

Does that help?

🙂
