<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/get-the-screen-width-height-without-javascript-ugq3rqgjv" -->

---
title: Get the screen width & height without JavaScript | daily.dev
description: Learn how to obtain screen width and height as pixel values using only CSS, avoiding JavaScript. This method leverages @property and trigonometric functions,...
canonical: https://daily.dev/posts/get-the-screen-width-height-without-javascript-ugq3rqgjv
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Get the screen width & height without JavaScript | daily.dev
og:description: Learn how to obtain screen width and height as pixel values using only CSS, avoiding JavaScript. This method leverages @property and trigonometric functions,...
og:url: https://daily.dev/posts/get-the-screen-width-height-without-javascript-ugq3rqgjv
og:image: https://api.daily.dev/og/posts/ugq3rQGJv.png
og:image:alt: Get the screen width & height without JavaScript
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Get the screen width & height without JavaScript

**[CSS Tip](https://daily.dev/sources/csstip)** · 1 min read · 211 upvotes · 12 comments

## Summary

Learn how to obtain screen width and height as pixel values using only CSS, avoiding JavaScript. This method leverages @property and trigonometric functions, providing unitless values that update in real-time upon screen resize.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://css-tip.com/screen-dimension/>

## Community discussion

Top comments from developers on daily.dev.

**@bomber943** · 3 upvotes

> Nice but complex to understand lol

**@webry** · 1 upvotes

> I was confused for a second on how you can obtain a screen width by math. But the author didn't mean the screen width but the viewport width in pixels.
>
> With the `tan(atan(abc, 1px))` you simply convert the 100vw into the pixel amount without a unit so it can be used with counters to display the numbers on the page. There is no math going on here, we are just abusing those css functions to get rid of the unit and use pixels.

**@macx** · 1 upvotes

> Awesome. I don't know to use the new math functions yet, but this is cool. But here comes the downside of the link: There is no explanation, how this is working.

**@tcx** · 1 upvotes

> Yoo yippee

**@dlozimthethwa** · 1 upvotes

> Brilliant. Thank you for sharing.

---

Tags: [#webdev](https://daily.dev/tags/webdev), [#css](https://daily.dev/tags/css), [#frontend](https://daily.dev/tags/frontend), [#ui-design](https://daily.dev/tags/ui-design)

[View this post on daily.dev](https://daily.dev/posts/get-the-screen-width-height-without-javascript-ugq3rqgjv)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Get the screen width \u0026 height without JavaScript","url":"https://daily.dev/posts/get-the-screen-width-height-without-javascript-ugq3rqgjv","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/get-the-screen-width-height-without-javascript-ugq3rqgjv"},"datePublished":"2024-07-16T10:31:22.285Z","dateModified":"2024-08-23T15:57:41.446Z","description":"Learn how to obtain screen width and height as pixel values using only CSS, avoiding JavaScript. This method leverages @property and trigonometric functions,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7124644e51b3cf87552c2dd3d6774296?_a=AQAEuiZ","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7124644e51b3cf87552c2dd3d6774296?_a=AQAEuiZ","isAccessibleForFree":true,"articleSection":"CSS Tip","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"CSS Tip","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/5d335233e7894c2ea997aa89e1724200","url":"https://daily.dev/sources/csstip"},"commentCount":12,"discussionUrl":"https://daily.dev/posts/get-the-screen-width-height-without-javascript-ugq3rqgjv","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":211},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":12}],"keywords":"webdev,css,frontend,ui-design","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"CSS Tip","item":"https://daily.dev/sources/csstip"},{"@type":"ListItem","position":3,"name":"Get the screen width \u0026 height without JavaScript"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/get-the-screen-width-height-without-javascript-ugq3rqgjv","comment":[{"@type":"Comment","text":"Nice but complex to understand lol","datePublished":"2024-07-16T11:03:41.261Z","url":"https://daily.dev/posts/ugq3rQGJv#c-uG1vpeBE2","author":{"@type":"Person","name":"Tom MURPHY","url":"https://daily.dev/bomber943","image":"https://avatars.githubusercontent.com/u/158026986?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3}},{"@type":"Comment","text":"I was confused for a second on how you can obtain a screen width by math. But the author didn’t mean the screen width but the viewport width in pixels.\nWith the tan(atan(abc, 1px)) you simply convert the 100vw into the pixel amount without a unit so it can be used with counters to display the numbers on the page. There is no math going on here, we are just abusing those css functions to get rid of the unit and use pixels.","datePublished":"2024-07-17T10:13:05.040Z","url":"https://daily.dev/posts/ugq3rQGJv#c-emW1u8jjo","author":{"@type":"Person","name":"Samuel Braun","url":"https://daily.dev/webry","image":"https://media.daily.dev/image/upload/v1683105442/avatars/avatar_KjrWzAyEMnN7TAr8iPV9O.jpg"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"Awesome. I don’t know to use the new math functions yet, but this is cool. But here comes the downside of the link: There is no explanation, how this is working.","datePublished":"2024-07-17T07:21:11.647Z","dateModified":"2024-07-17T07:21:54.727Z","url":"https://daily.dev/posts/ugq3rQGJv#c-O5tamxfFo","author":{"@type":"Person","name":"David Maciejewski","url":"https://daily.dev/macx","image":"https://media.daily.dev/image/upload/s--Bi6LcUU2--/f_auto/v1718260606/avatars/avatar_NJRHj92N7WyhHvNU6BfCM"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"Yoo yippee","datePublished":"2024-07-27T03:15:00.653Z","url":"https://daily.dev/posts/ugq3rQGJv#c-8PRo6xtz9","author":{"@type":"Person","name":"Tochukwu","url":"https://daily.dev/tcx","image":"https://lh3.googleusercontent.com/a/ACg8ocK6ka0fWhdNyPWEcOtl7QE6Zqh_yfY2ugCo3qgSdg-3suxBT4Wn=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"Brilliant. Thank you for sharing.","datePublished":"2024-09-06T07:23:47.728Z","url":"https://daily.dev/posts/ugq3rQGJv#c-uPK6J4yaw","author":{"@type":"Person","name":"Dlozi Mthethwa","url":"https://daily.dev/dlozimthethwa","image":"https://media.daily.dev/image/upload/s--SujEeDm7--/f_auto/v1772706234/avatars/avatar_btf3oLdrePMldOYVtiAFE?_a=BAMAMiiu0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}}]}
```

