Tejas Rana
  • Home
  • About
  • Experience
  • Skills
  • Blogs
  • Technology
  • Contact
August 5 2016

Responsive / screen size wise font-size using CSS

tejas CSS, Tips & Tricks

Since there are lots of improvements is happening in CSS3 and still most of developer and designer are unaware of it.
So, Now let me present the new tag they introduce in CSS3 for Responsive font-size is : vw, vh, vmin, vmax
With this font size type, it will increase and decrease font size according to screen or browser size. This is very helpful as generally we use px but with px there is an issue when user opens it on large screen then they are not able to see proper font size so to fix this issue we increase that font in px and then the main issue occur for small screen devices because they see very big font on their tiny screen. to prevent this issue we add media query but my question is that how many media query you will write. so to save this extra effort we can use new font size type.
With the help of vw, vh, vmin, vmax we define font size and with this, we don’t have to write media queries for each screen.
Example:
vw:
Divs with color shade:

<div class="grid">
  <div class="grid__item"></div>
  <div class="grid__item"></div>
  <div class="grid__item"></div>
  <div class="grid__item"></div>
  <div class="grid__item"></div>
  <div class="grid__item"></div>
  <div class="grid__item"></div>
  <div class="grid__item"></div>
</div>
.grid::before,
.grid::after {
  clear: both;
  content: '';
  display: block;
}
.grid__item {
  box-sizing: border-box;
  float: left;
  height: 50vw;
  padding: 2em;
  width: 50vw;
}
.grid__item:nth-child(1) {
  background-color: #ff4433;
}
.grid__item:nth-child(2) {
  background-color: #ff5533;
}
.grid__item:nth-child(3) {
  background-color: #ff6633;
}
.grid__item:nth-child(4) {
  background-color: #ff7733;
}
.grid__item:nth-child(5) {
  background-color: #ff8833;
}
.grid__item:nth-child(6) {
  background-color: #ff9933;
}
.grid__item:nth-child(7) {
  background-color: #ffaa33;
}
.grid__item:nth-child(8) {
  background-color: #ffbb33;
}

Output: https://codepen.io/timseverien/pen/uhzgo
 
Screen wise font size:

<div class="container">
  <h1>My special headline</h1>
  <p>Re-size the viewport and see the headline magically resize!</p>
</div>
.container { text-align: center; }
h1 { font-size: 5vw; }

Output: https://codepen.io/timseverien/pen/rkhgo
In this, you can also use vmax instead of vw.
This is very helpful but the major drawback is that it is supported by only modern web browsers.

Hunting Down Memory Issues In Ruby: A Definitive Guide Why Should Java Developers Give Grails a Chance?

Related Posts

001

Tips & Tricks

Anatomy of A Coronavirus-Proof Business[Infographic]

1-

Tips & Tricks

AWS EC2 alternative

Backdrop-Logo-Vertical_0

Drupal, Tips & Tricks

10 reasons why choose BackdropCMS instead of Drupal

Categories

  • .NET
  • Android
  • Angular
  • CakePHP
  • CSS
  • Devops
  • Drupal
  • Infi MVC
  • iOS
  • Javascript
  • Magento
  • Meteor
  • MongoDB
  • Opencart
  • Other
  • PHP
  • Python
  • Ruby
  • Tips & Tricks
  • WordPress

Recent Posts

  • Simplify Product Filtering by Category and Store ID in the Admin Panel with Our Powerful OpenCart 3.x Free Extension
  • Opencart 3.x Set currency based on user’s IP [Free Extension]
  • Anatomy of A Coronavirus-Proof Business[Infographic]
  • Opencart 3 Social Login Extension [FREE]
  • What is NGRX and Use of NGRX

Recent Comments

  • Nilesh on What is State Management in Angular? How to improve Performance?
  • Dinesh on Use Magento If You're Serious About eCommerce
  • Virendra on Use Magento If You're Serious About eCommerce
  • Tejas Rana on Show limited words in PHP from string with HTML tags
  • nadim on Show limited words in PHP from string with HTML tags
Tejas Rana
© Tejas Rana 2025