<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Taskin Mohammad Mubassir</title>
    <description>The latest articles on Forem by Taskin Mohammad Mubassir (@taskin_mohammadmubassir_).</description>
    <link>https://forem.com/taskin_mohammadmubassir_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3448167%2F2a285471-7021-4b1b-b610-15022a47d17b.jpg</url>
      <title>Forem: Taskin Mohammad Mubassir</title>
      <link>https://forem.com/taskin_mohammadmubassir_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/taskin_mohammadmubassir_"/>
    <language>en</language>
    <item>
      <title>How Viewport Units Solve CSS Problems I Used to Have</title>
      <dc:creator>Taskin Mohammad Mubassir</dc:creator>
      <pubDate>Mon, 27 Oct 2025 11:35:32 +0000</pubDate>
      <link>https://forem.com/taskin_mohammadmubassir_/how-viewport-units-solve-css-problems-i-used-to-have-252l</link>
      <guid>https://forem.com/taskin_mohammadmubassir_/how-viewport-units-solve-css-problems-i-used-to-have-252l</guid>
      <description>&lt;p&gt;&lt;em&gt;The goal: fluid, predictable layouts that just work. It took me a while to get here.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Frustration is Real&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I’ve been there, staring at my screen, utterly frustrated. I wanted a simple hero section that was exactly the height of the screen. I’d set height: 100%; on everything—html, body, the div, its parent—and nothing. Or I’d try height: 100vh; and high-five myself, only to check it on my phone later and find the math was all wrong because of the stupid address bar.&lt;/p&gt;

&lt;p&gt;For the longest time, my toolkit was px for control and % for relativity. They’re great, but they have limits. I felt like I was constantly fighting the CSS to make it do what I wanted.&lt;/p&gt;

&lt;p&gt;Then I actually sat down to understand viewport units. And friends, it wasn't about learning new syntax. It was about finally finding the right tool to solve the layout problems that had been frustrating me for years. This is the practical guide I wish I’d had.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. My New Toolbox: Meet vh, vw, vmin, and vmax&lt;/strong&gt;&lt;br&gt;
Let's get the basics out of the way. I think of these as the powerful, context-aware siblings of the percentage.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1vh = 1% of what I’m actually looking through—the viewport's height&lt;/li&gt;
&lt;li&gt;1vw = 1% of the viewport's width&lt;/li&gt;
&lt;li&gt;1vmin = 1% of the viewport's smaller dimension (so helpful on mobile!)&lt;/li&gt;
&lt;li&gt;1vmax = 1% of the viewport's larger dimension&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F006wx1q31t2d5b03wp10.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F006wx1q31t2d5b03wp10.png" alt=" " width="800" height="730"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s the lightbulb moment I had: Percentages are relative to a parent element. Viewport units are relative to the browser window itself. This was the game-changer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Solving My Real Problems: Practical Use Cases&lt;/strong&gt;&lt;br&gt;
This is the good stuff. This is how I use these units to solve actual, daily layout issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem 1:&lt;/strong&gt; "I need a dang full-screen section."&lt;br&gt;
My Old Fight: The fragile chain of height: 100%; on every single parent element. It broke if you looked at it wrong.&lt;br&gt;
My Viewport Solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.hero {
  min-height: 100vh; /* My reliable fallback */
  min-height: 100dvh; /* The modern solution that finally works (I'll explain!) */
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why it works: It bypasses the entire DOM tree drama. It just asks the browser: "Make this element at least as tall as the viewport." Direct. Simple. I love it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem 2:&lt;/strong&gt; "I want my spacing to feel fluid, not jumpy."&lt;br&gt;
My Old Fight: A tangled mess of media queries for font-size, margin, and padding at different breakpoints. It felt so clunky.&lt;br&gt;
My Viewport Solution: Fluid Everything&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* My favorite trick: fluid text that scales smoothly */
h1 {
  font-size: clamp(1.5rem, 1rem + 2vw, 2.5rem); /* No more media queries for font size! */
}

/* Margins that feel right on any screen */
.container {
  margin: 5vmin; /* Uses the smaller dimension. It just works! */
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why it works: It creates a truly fluid, responsive design without me having to micromanage every single breakpoint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem 3:&lt;/strong&gt; "Centering this thing is a nightmare."&lt;br&gt;
My Old Fight: Negative margins, complex flexbox/grid contortions, all just to center one div.&lt;br&gt;
My Viewport Solution: The Classic Trick, Finally Understood&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.centered-box {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%); /* This part is the magic */
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why it works: I finally got it. top: 50% and left: 50% move the element's top-left corner to the center of the viewport. The transform: translate(-50%, -50%) then shifts it back by half of its own size. It’s viewport units doing the heavy lifting to find the center.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The Gotcha That Almost Made Me Quit (And How I Fixed It)&lt;/strong&gt;&lt;br&gt;
This is the part that, in my opinion, most articles don't talk about enough. This was my biggest "Aha!" moment.&lt;/p&gt;

&lt;p&gt;The Problem: Mobile Browsers Hate 100vh&lt;br&gt;
I built my perfect full-screen hero with min-height: 100vh;. It looked perfect on desktop. I opened it on my phone, scrolled down, the address bar hid, and the content jumped. I was devastated.&lt;/p&gt;

&lt;p&gt;Why? Because 100vh is the height of the viewport when the address bar is visible. So when the bar hides, you have extra space you didn't account for, causing a scrollbar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fddv9woiurpren1jhteod.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fddv9woiurpren1jhteod.png" alt=" " width="800" height="645"&gt;&lt;/a&gt;&lt;br&gt;
The classic 100vh problem that ruined my afternoon.&lt;br&gt;
My Old (Hacky) Solution:&lt;br&gt;
I’d see people using JavaScript to calculate window.innerHeight and set a CSS variable. It worked, but it felt wrong. It was a script fix for a CSS problem.&lt;/p&gt;

&lt;p&gt;My New (Native CSS) Savior: dvh&lt;br&gt;
I remember reading the spec and getting so excited. They gave us Dynamic Viewport Units.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;100dvh (Dynamic Viewport Height) automatically adjusts as the browser’s UI (like the address bar) slides in and out.&lt;/li&gt;
&lt;li&gt;It’s the tool I’d been begging for.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Code I Use Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.hero {
  min-height: 100vh; /* Fallback for older browsers. They get the 'good enough' version. */
  min-height: 100dvh; /* The modern, correct, "it-just-works" way for all modern browsers. */
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Browser Support: It’s in all the browsers I care about (Chrome, Firefox, Safari, Edge). Using it with a vh fallback is safe and responsible. This fixed my single biggest frustration with CSS layout.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. When I Don't Reach for Viewport Units&lt;/strong&gt;&lt;br&gt;
A good craftsman knows their tools. I’ve learned when not to use these.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For Text Accessibility: I never use vw alone for font sizes. It can break browser zoom. I always pair it with clamp() and a base rem size to keep it accessible.&lt;/li&gt;
&lt;li&gt;For Component Layouts: If I want an image to be 50% the width of its parent article, I use width: 50%;. That's a job for percentages. If I want it to be 50% of the browser window no matter where it is, I use width: 50vw;. I use the right tool for the job.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;My Workflow is So Much Smoother Now&lt;/strong&gt;&lt;br&gt;
I don't see viewport units as just another thing to remember. I see them as practical problem-solvers that made my life easier.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I use dvh for full-height sections that finally work everywhere.&lt;/li&gt;
&lt;li&gt;I use vw/vmin for fluid scaling that feels natural.&lt;/li&gt;
&lt;li&gt;I use vmin/vmax for context-aware sizing that responds perfectly to screen orientation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I embraced them not because they were new, but because they solved my actual problems.&lt;/p&gt;

&lt;p&gt;What's the most creative way you've used viewport units? What problems did they solve for you? Share your stories in the comments—I’d love to learn from you!&lt;/p&gt;

</description>
      <category>viewport</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>tailwindcss</category>
    </item>
    <item>
      <title>Understanding Hoisting in JavaScript: A Simple Guide</title>
      <dc:creator>Taskin Mohammad Mubassir</dc:creator>
      <pubDate>Mon, 27 Oct 2025 10:27:36 +0000</pubDate>
      <link>https://forem.com/taskin_mohammadmubassir_/understanding-hoisting-in-javascript-a-simple-guide-574k</link>
      <guid>https://forem.com/taskin_mohammadmubassir_/understanding-hoisting-in-javascript-a-simple-guide-574k</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;JavaScript Hoisting&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;🔹 &lt;strong&gt;What is Hoisting?&lt;/strong&gt;&lt;br&gt;
Hoisting is JavaScript's default behavior of moving declarations of functions and variables to the top of their scope before the code is executed. This means you can use a function or variable before it has been physically declared in the code. However, it's important to understand that only the declarations are hoisted, not the initializations (the assignment of a value).&lt;/p&gt;

&lt;p&gt;In simple terms:&lt;br&gt;
JavaScript scans the entire code first, remembers all variable and function declarations, and then starts running the code.&lt;br&gt;
Variable Hoisting&lt;br&gt;
How hoisting works with variables depends on whether you use var, let, or const.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fza0sh0p9mpgo4aqzvwzo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fza0sh0p9mpgo4aqzvwzo.png" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using var
Variables declared with var are hoisted to the top of their scope and are initialized with a value of undefined.
This means you can access the variable before its declaration without an error, but its value will be undefined until the assignment is made.
Example:
code:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(myVar);         // Outputs: undefined 
var myVar = "Hello, World!"; 
console.log(myVar);         // Outputs: "Hello, World!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;How JavaScript sees it: &lt;br&gt;
Code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var myVar;      // Declaration is hoisted and                          initialized as undefined          
console.log(myVar); 
myVar = "Hello, World!";    // Initialization happens here 
console.log(myVar);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Using let and const
Variables declared with let and const are also hoisted, but they are not initialized with a default value.
Accessing a let or const variable before it is declared will result in a &lt;em&gt;ReferenceError.&lt;/em&gt;
This is due to the Temporal Dead Zone (TDZ), which is the time from the start of the block until the variable declaration is processed.
Example:
Code
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(myLet);             // Throws ReferenceError: Cannot access                       'myLet' before initialization 
let myLet = "This will not work";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Function Hoisting&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Function Declarations
Function declarations are fully hoisted, meaning both the function's name and its entire logic are moved to the top.
This allows you to call a function before it is declared in your code.
Example:
code
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sayHello();             // Outputs: "Hello there!" 
function sayHello() { 
  console.log("Hello there!"); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Function Expressions
Function expressions, where a function is assigned to a variable, are not hoisted in the same way.
If the variable is declared with the var keyword, the declaration is hoisted and initialized to undefined. Trying to call it before the assignment will result in a TypeError.
If declared with let or const, it will be subject to the Temporal Dead Zone and throw a ReferenceError.
Example (with var):
code
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sayGoodbye();       // Throws TypeError: sayGoodbye is not a function 
var sayGoodbye = function() { 
  console.log("Goodbye!"); 
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 Example Code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(a);
console.log(b);
console.log(c);

let a = 10;
const b = 20;
var c = 30;

hoistingFunction();
notHostingFunction();

function hoistingFunction() {
  console.log('hi');
}
const notHostingFunction = () =&amp;gt; {
  console.log('hello');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 Step-by-Step Explanation&lt;br&gt;
During the compilation phase, JavaScript hoists declarations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var c;                 // Hoisted and initialized with undefined
let a;                 // Hoisted but NOT initialized (TDZ)
const b;               // Hoisted but NOT initialized (TDZ)
function hoistingFunction(){console.log('hi');} // Fully hoisted
const notHostingFunction;         // Declared but not initialized
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;During execution, code runs line by line:&lt;br&gt;
console.log(a) → ❌ Error: Cannot access 'a' before initialization&lt;br&gt;
console.log(b) → Not reached (script already stopped)&lt;br&gt;
console.log(c) → Not reached&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Variables with let and const are in the Temporal Dead Zone (TDZ) until their declaration line is executed.&lt;/li&gt;
&lt;li&gt;
var is accessible before initialization but holds undefined.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔹 Function Hoisting&lt;br&gt;
✅ Function Declarations&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sayHi();
function sayHi() {
  console.log('Hello');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Works perfectly because function declarations are fully hoisted (both name and body).&lt;br&gt;
❌ Function Expressions / Arrow Functions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sayHello();  // Error
const sayHello = () =&amp;gt; console.log('Hello');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🚫 Error: Cannot access 'sayHello' before initialization&lt;br&gt;
 Reason: Only the variable declaration (const sayHello) is hoisted, not the function value.&lt;/p&gt;

&lt;p&gt;🔹 Variable Hoisting Summary&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhckn1ix4fqxj4engsa5u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhckn1ix4fqxj4engsa5u.png" alt=" " width="632" height="327"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔹 Temporal Dead Zone (TDZ)&lt;br&gt;
The TDZ is the time between the start of the scope and the line where a let or const variable is declared.&lt;br&gt;
 Accessing these variables during the TDZ results in a ReferenceError.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(x);  // ❌ ReferenceError
let x = 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 Corrected Version of the Example Code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 10;
const b = 20;
var c = 30;

console.log(a); // 10
console.log(b); // 20
console.log(c); // 30

hoistingFunction(); // ✅ Prints 'hi'

function hoistingFunction() {
  console.log('hi');
}


notHostingFunction(); // ❌ ReferenceError (Cannot access 'ok' before                          initialization)
const notHostingFunction = () =&amp;gt; {
  console.log('hello');
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 Key Takeaways&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Only declarations are hoisted, not initializations.&lt;/li&gt;
&lt;li&gt;var variables are hoisted and initialized with undefined.&lt;/li&gt;
&lt;li&gt;let and const are hoisted but remain in the Temporal Dead Zone until their line of declaration.&lt;/li&gt;
&lt;li&gt;Function declarations are fully hoisted (can be called before they appear).&lt;/li&gt;
&lt;li&gt;Function expressions (arrow or anonymous) behave like variables—not callable before initialization.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>hoisting</category>
      <category>functions</category>
      <category>variables</category>
    </item>
  </channel>
</rss>
