# \[p5.js\] Is it possible to edit the 'initial-scale' of 'meta\[name=viewport\]'?

**URL:** https://discourse.processing.org/t/p5-js-is-it-possible-to-edit-the-initial-scale-of-meta-name-viewport/34087
**Category:** Coding Questions
**Created:** [December 13, 2021, 3:44am UTC](https://discourse.processing.org/t/p5-js-is-it-possible-to-edit-the-initial-scale-of-meta-name-viewport/34087 "2021-12-13T03:44:33Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)
#### Post date: [December 13, 2021, 3:44am UTC](https://discourse.processing.org/t/p5-js-is-it-possible-to-edit-the-initial-scale-of-meta-name-viewport/34087/1 "2021-12-13T03:44:33Z")

</div>

Is it possible to edit the ‘initial-scale’ of ‘meta[name=viewport]’?

through ‘js’

\*link: [html - Change initial scale with javascript - Stack Overflow](https://stackoverflow.com/questions/15010503/change-initial-scale-with-javascript)

```auto
  if (document.documentElement.clientWidth < 480) {
     document.querySelector("meta[name=viewport]").setAttribute(
           'content',
           'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0');
  }

```

through ‘p5.js’

```auto
   cbox= select('meta[name=viewport]');
   cbox.ele.initial-scale=1.0; // <- This error.

```

Any solution?

---

<div class="post-metadata">

### Author: ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)
#### Post date: [December 13, 2021, 4:47am UTC](https://discourse.processing.org/t/p5-js-is-it-possible-to-edit-the-initial-scale-of-meta-name-viewport/34087/2 "2021-12-13T04:47:23Z")

</div>

1. `cbox.ele.initial-scale = 1.0` is invalid JavaScript because you can’t have a hyphen (`-`) in an identifier.
2. Even if you used correct syntax: `cbox.ele['initial-scale'] = '1.0'` this would have no effect because you would be setting a property on the `HTMLElement` which would not do anything meaningful to the DOM, as `initial-scale` isn’t as supported attribute on the meta tag.
3. The equivalent `p5.js` code would set the `content` attribute of the element in question:

```auto
   cbox= select('meta[name=viewport]');
   // EDIT: removed typo: cbox.ele
   cbox.attribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0');

```

See [p5.Element.attribute()](https://p5js.org/reference/#/p5.Element/attribute)

---

<div class="post-metadata">

### Author: ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)
#### Post date: [December 13, 2021, 5:14am UTC](https://discourse.processing.org/t/p5-js-is-it-possible-to-edit-the-initial-scale-of-meta-name-viewport/34087/3 "2021-12-13T05:14:57Z")

</div>

Dear KumuPaul / @KumuPaul

[P5.JS]

```auto
function setup() {

  createCanvas(600, 1100); 
  
  cbox= select('meta[name=viewport]');
  cbox.ele.attribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0');
  
  background(0);
  
}
function draw() {   
  
}

```

[HTML]

```auto
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <!-- PLEASE NO CHANGES BELOW THIS LINE (UNTIL I SAY SO) -->
  <script language="javascript" type="text/javascript" src="libraries/p5.min.js"></script>
  <script language="javascript" type="text/javascript" src="TEST_SIZE_EXAMPLE.js"></script>
  <!-- OK, YOU CAN MAKE CHANGES BELOW THIS LINE AGAIN -->

  <!-- This line removes any default padding and style.
       You might only need one of these values set. -->
  <style> body { padding: 0; margin: 0; } </style>
</head>
<body>
</body>
</html>

```

It doesn’t work.

`cbox.ele.attribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0');`

doesn’t seem to be working.

---

<div class="post-metadata">

### Author: ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)
#### Post date: [December 13, 2021, 5:41am UTC](https://discourse.processing.org/t/p5-js-is-it-possible-to-edit-the-initial-scale-of-meta-name-viewport/34087/4 "2021-12-13T05:41:51Z")

</div>

Sorry there was a typo in my code:

```auto
   cbox= select('meta[name=viewport]');
   // Note: calling attribute on cbox, not cbox.ele
   cbox.attribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0');

```

---

<div class="post-metadata">

### Author: ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)
#### Post date: [December 13, 2021, 7:43am UTC](https://discourse.processing.org/t/p5-js-is-it-possible-to-edit-the-initial-scale-of-meta-name-viewport/34087/5 "2021-12-13T07:43:17Z")

</div>

@KumuPaul

very very Thank you.

but,  
I have one question.

case 1  
`<meta name="viewport" content="width=device-width, initial-scale=1">`

case 2  
`<meta name="viewport" content="width=200px, initial-scale=0.5">`

case 3  
`<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">`

No matter how much I change the html, is it the same as what I see on a real smartphone?  
I can’t understand.

---

<div class="post-metadata">

### Author: ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)
#### Post date: [December 13, 2021, 7:58am UTC](https://discourse.processing.org/t/p5-js-is-it-possible-to-edit-the-initial-scale-of-meta-name-viewport/34087/6 "2021-12-13T07:58:01Z")

</div>

I suggest you read [this page on MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag) for an overview of how this setting is used. If you’re still struggling you should make a separate post outlining the specific layout you are trying to achieve on mobile, and sharing code with your best attempt.

---

<div class="post-metadata">

### Author: ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)
#### Post date: [December 13, 2021, 8:02am UTC](https://discourse.processing.org/t/p5-js-is-it-possible-to-edit-the-initial-scale-of-meta-name-viewport/34087/7 "2021-12-13T08:02:29Z")

</div>

A very basic example would be:

[https://testing.free-side.net/test-initial-scale.html](https://testing.free-side.net/test-initial-scale.html)

vs.

[https://testing.free-side.net/test-initial-scale.html?mobile=true](https://testing.free-side.net/test-initial-scale.html?mobile=true)

The former uses the default viewport width, and as a result renders the text very small. The later uses device-width (via the p5.js code to dynamically set the veiwport settings) and should show the text zoomed in to a more natural size and scrollable horizontally.

---

<div class="post-metadata">

### Author: ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)
#### Post date: [December 13, 2021, 8:33am UTC](https://discourse.processing.org/t/p5-js-is-it-possible-to-edit-the-initial-scale-of-meta-name-viewport/34087/8 "2021-12-13T08:33:44Z")

</div>

@KumuPaul

- TEST SITE : [http://goldstarit7.iptime.org:12005/testcode/index.html](http://goldstarit7.iptime.org:12005/testcode/index.html)

- index.html

```auto
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <!-- PLEASE NO CHANGES BELOW THIS LINE (UNTIL I SAY SO) -->
  <script language="javascript" type="text/javascript" src="libraries/p5.min.js"></script>
  <script language="javascript" type="text/javascript" src="TEST_ARRAY_TEXT.js"></script>
  <!-- OK, YOU CAN MAKE CHANGES BELOW THIS LINE AGAIN -->

  <!-- This line removes any default padding and style.
       You might only need one of these values set. -->
  <style> body { padding: 0; margin: 0; } </style>
</head>

<body>
</body>
</html>

```

`initial-scale=1.0`

Even if you change ‘initial-scale=1.0’ and access the site with a smartphone, the displayed screen is the same.

I don’t know why.

---

<div class="post-metadata">

### Author: ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)
#### Post date: [December 13, 2021, 9:16am UTC](https://discourse.processing.org/t/p5-js-is-it-possible-to-edit-the-initial-scale-of-meta-name-viewport/34087/9 "2021-12-13T09:16:29Z")

</div>

@KumuPaul

I think you’re right.

It seems it’s an internet ‘cash memory’ issue that ‘initial-scale=1.0’ doesn’t change.

Thank you for answer.
