Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

503
Views
Media Queries or JavaScript to hide an element on certain screens

We have a section on the page that needs to be hidden on small phone screens, and appear on larger screens.

The easiest way to do it would be to use CSS media queries.

.section {
  display: none;
}

@media (min-width: 900px) {
  .section {
    display: block;
  }
} 

However, this would keep the section in the DOM, thus potentially making it less efficient.

Alternatively, we could toggle the existence of the section using a state in our JavaScript framework (React in our case, but not important for the question).

My Question is: When is it better to use one, and when is it fine to use the other?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!