In the realm of modern web development, responsiveness is not just an advantage but a necessity. Google Apps Script, a JavaScript-based scripting language, allows us to create web applications that can adapt to different screen sizes and devices, making them responsive. In this article, we delve into the world of Google Apps Script web apps and explore how to make them responsive.

Firstly, let's understand what we mean by 'responsive' in the context of web apps. A responsive web app is one that can adapt its layout and user interface to fit various screen sizes, from desktop monitors to tablets and smartphones. This ensures a better user experience, regardless of the device being used.

Understanding the canvas().getHeight() and canvas().getWidth() Methods
To create a responsive Google Apps Script web app, we first need to understand how to detect the height and width of the user's screen. Google Apps Script provides the `canvas()` function for this purpose. The `getHeight()` and `getWidth()` methods return the height and width of the canvas, respectively.

Here's a simple example demonstrating their usage:
```javascript function doGet() { return HtmlService.createHtmlOutputFromFile('Index'); } function getCanvasSize() { var canvasHeight = canvas().getHeight(); var canvasWidth = canvas().getWidth(); Logger.log('Canvas height: ' + canvasHeight + ', Canvas width: ' + canvasWidth); } ```
Setting the Canvas Size

If you want to set your canvas size to a specific dimension, you can use the `setHeight()` and `setWidth()` methods. However, note that these methods do not actually resize the canvas; they only set the maximum size of the canvas. The actual size of the canvas is determined by the size of the parent element.
Here's how you can set the canvas height and width:
```javascript canvas().setHeight('500px'); canvas().setWidth('800px'); ```
Using CSS Media Queries

CSS media queries allow us to apply different styles for different screen sizes. They are invaluable when it comes to making Google Apps Script web apps responsive. Media queries use the `max-width` property to apply styles when the viewport is at or below a specified width.
For instance, you can target smartphones by using the following query:
```css @media only screen and (max-width: 480px) { /* Your styles for screens 480px or below go here */ } ```
dziaĆanie Media Queries w Google Apps Script Web Apps

Media queries work similarly in Google Apps Script web apps as they do in other web applications. You can write them in your CSS files and use them to change the layout and styling of your web app based on the user's screen size.
To use CSS in your Google Apps Script web app, you can include it in your `doGet()` function and return it along with your HTML. Here's an example:







```javascript function doGet() { return HtmlService.createHtmlOutput(`
By leveraging the `canvas().getHeight()` and `canvas().getWidth()` methods, and utilizing CSS media queries, you can create Google Apps Script web apps that are responsive and provide a great user experience across various devices.