Panduan Viewport Meta Tag

What viewport meta tag melakukan, why ini membuat responsive design berfungsi pada mobile, correct configuration, attribute reference, dan umum mistakes.

Pertama kali diterbitkan: 2 Jul 2026 · Terakhir diperbarui: 3 Agu 2026 · Advanced
Bahasa

viewport meta tag — <meta name="viewport" content="width=device-width, initial-scale=1"> — hints untuk browser untuk size layout viewport untuk device's width di CSS pixels alih-alih sebuah legacy ~980px fallback beberapa mobile browser gunakan. Without ini, phones dapat render halaman di itu wider fallback dan shrink ini, producing tiny text, horizontal scroll, dan responsive breakpoints itu dapat not apply sebagai intended. ini adalah not sebuah peringkat factor itself, tetapi -nya presence adalah one dari things Google documents sebagai indicating mobile-friendliness, dan -nya absence adalah sebuah classic mobile usability failure. tidak pernah force pengguna-scalable=no atau sebuah restrictive maximum-scale — ini fails W3C's accessibility conformance aturan untuk zoom dan dapat lock out rendah-vision pengguna, though browser dapat override ini (iOS 10+ ignores ini oleh default). Test ini dengan Lighthouse atau PageSpeed Insights: Search Console's Mobile Usability report dan Mobile-Friendly Test adalah retired December 1, 2023.

TL;DR — viewport meta tag — <meta name="viewport" content="width=device-width, initial-scale=1"> — hints browser untuk size layout viewport untuk device’s width di CSS pixels alih-alih sebuah legacy ~980px fallback beberapa mobile browser gunakan, which adalah what lets responsive CSS media kueri evaluate terhadap device’s nyata width pada mobile. Missing atau misconfigured, ini adalah sebuah classic mobile usability failure (tiny text, horizontal scroll). ini adalah not sebuah peringkat factor — Google documents -nya presence sebagai one thing -nya mobile-friendliness evaluation memeriksa untuk, dan no more daripada itu. tidak pernah force user-scalable=no / restrictive maximum-scale: ini fails W3C’s ACT accessibility aturan untuk zoom, though browser overrides exist (iOS 10+ ignores ini oleh default). Google dan Bing recommend identical tag. Test dengan Lighthouse / PageSpeed Insights — Search Console’s Mobile Usability report dan Mobile-Friendly Test adalah retired December 1, 2023.

Evidence for this claim The viewport meta tag lets authors control viewport width and scaling so responsive layouts render at device width. Scope: Browser viewport behavior. Confidence: high · Verified: MDN: Viewport meta tag Evidence for this claim Pages should not disable browser zoom because users must be able to enlarge content for accessibility. Scope: WCAG resize-text requirement and viewport guidance. Confidence: high · Verified: W3C WAI: Understanding Resize Text

masalah ini solves: ~980px virtual viewport

untuk memahami tag Anda memiliki untuk memahami what ini adalah overriding. When mobile browser adalah baru, lack dari sebuah viewport tag dimaksudkan beberapa dari them akan fall back untuk sebuah fixed layout width dari roughly 980px dan render di itu size — sebuah deliberate accommodation so desktop-sized, pre-responsive situs wouldn’t completely break pada early smartphones. browser lalu scaled hasil down untuk physical screen. MDN’s own framing: “If the site isn’t designed to work well on small viewports and this tag is omitted, some mobile browsers render the site using a fixed initial containing block width, typically 980px.” (terjemahan) “jika situs isn’t designed untuk berfungsi well pada kecil viewports dan ini tag adalah omitted, beberapa mobile browser render situs menggunakan sebuah fixed initial containing block width, typically 980px.” — ini adalah sebuah browser-spesifik fallback, not sebuah universal spec constant.

consequence, di Google’s own kata: “Without a viewport meta tag, mobile devices render pages at typical desktop screen widths and then scale the pages down, making them difficult to read.” (terjemahan) “Without sebuah viewport meta tag, mobile devices render halaman di typical desktop screen widths dan lalu scale halaman down, membuat them difficult untuk read.” Anda get unreadable text, forced pinch-zooming, dan horizontal scrolling — textbook symptoms dari sebuah halaman flagged “not mobile-friendly.” (terjemahan) “not mobile-friendly.”

Setting tag “lets you control the width and scaling of the viewport so that it’s sized correctly on all devices.” (terjemahan) “lets Anda control width dan scaling dari viewport so itu ini adalah sized correctly pada semua devices.”

Layout viewport vs. visual viewport (di bawah hood)

Two “viewports” (terjemahan) “viewports” adalah di play, dan ini adalah worth keeping them straight:

  • layout viewport adalah area halaman lays out ke dan itu fixed-position elements attach untuk. width=device-width sets ini untuk device’s screen width di CSS pixels.
  • visual viewport adalah what pengguna adalah currently looking di — which perubahan when mereka pinch-zoom. Zooming perubahan visual viewport tanpa mengubah layout viewport.

alasan ini penting untuk SEO dan CSS: Anda responsive media kueri (@media (max-width: 600px) dan friends) adalah evaluated terhadap layout viewport. jika layout viewport adalah stuck di sebuah legacy ~980px fallback because there’s no viewport tag, sebuah phone dapat match Anda desktop breakpoints alih-alih Anda narrow ones. MDN puts ini plainly: “Without it, your responsive design with breakpoints and media queries may not work as intended on mobile browsers.” (terjemahan) “Without ini, Anda responsive design dengan breakpoints dan media kueri dapat not berfungsi sebagai intended pada mobile browser.” tag adalah what membuat device-width layout viewport so Anda intended breakpoints evaluate correctly.

Evidence for this claim Without an appropriate viewport hint, narrow responsive breakpoints may not match as intended against the wider virtual layout viewport; it is too absolute to say CSS media queries never fire. Scope: production HTML and HTTP responses Confidence: high · Verified: Responsive web design

correct tag, dan where ini goes

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- ...the rest of your head... -->
</head>

Put ini tinggi di <head>, near charset, sebelum konten-dependent tags. ini adalah nilai Google, Bing, dan Lighthouse semua recommend — verbatim, ini adalah fix Lighthouse itself suggests. Don’t overthink nilai: width=device-width, initial-scale=1 adalah jawaban untuk essentially setiap responsive situs.

Attribute reference

content attribute adalah sebuah comma-separated list dari directives. MDN adalah canonical attribute-oleh-attribute reference; here’s what setiap one melakukan:

DirectiveWhat ini melakukanNotes
widthControls (minimum) pixel width dari viewportsebuah whole angka 1–10000, atau special nilai device-width ( screen width di CSS pixels). gunakan device-width.
initial-scalezoom ratio antara device width dan viewport pada muatsebuah angka 0.010.0. gunakan 1.
minimum-scaleminimum zoom tingkat allowedharus menjadi ≤ maximum-scale. iOS 10+ ignores ini oleh default.
maximum-scalemaximum zoom-di allowedharus menjadi ≥ minimum-scale. iOS 10+ ignores ini oleh default. Don’t restrict ini.
user-scalableWhether pengguna dapat zoom (yes/no, default yes)iOS 10+ ignores ini oleh default. Setting no adalah sebuah accessibility anti-pattern — leave ini.
interactive-widgetHow interactive UI (e.g. virtual keyboards) affect viewportnilai: resizes-visual (default), resizes-content, overlays-content. Newer; sebagian besar SEO konten omits ini.
viewport-fitHow viewport handles display cutouts (notches)nilai: auto (default), contain (fits inside largest rectangle itu menghindari cutout), cover (fills display — pair dengan CSS env() safe-area-inset variables so konten doesn’t land di bawah cutout).

viewport-fit dan interactive-widget adalah both browser-layout edge cases — display-cutout dan virtual-keyboard handling, respectively — not SEO directives; sebagian besar SEO-focused guides skip them entirely.

sebuah kecil tetapi nyata gotcha dari Lighthouse’s own docs: setting initial-scale below 1 dapat trigger sebuah legacy double-tap-untuk-zoom perilaku itu menambahkan interaction delay — lainnya alasan untuk stick dengan initial-scale=1 alih-alih getting clever.

tidak pernah disable zoom: user-scalable=no adalah sebuah anti-pattern

Anda’ll masih temukan user-scalable=no (atau maximum-scale=1) copy-pasted ke old theme boilerplate, biasanya dari sebuah developer who didn’t ingin pinch-zoom “messing up” (terjemahan) “messing up” mereka layout. ini adalah wrong pada two counts:

  1. ini fails web’s own accessibility conformance test untuk zoom, dan ini berfungsi terhadap WCAG’s intent. W3C’s ACT aturan “Meta viewport allows for zoom” (terjemahan) “Meta viewport allows untuk zoom” (aturan b4f0c3) applies untuk apa pun viewport tag itu sets user-scalable atau maximum-scale, dan -nya expectation adalah explicit: tag harus not set user-scalable=no, dan maximum-scale harus not menjadi set below 2. ( aturan carries stated assumptions — ini doesn’t apply jika halaman memiliki no terlihat konten, offers lainnya cara untuk resize text, atau tidak pernah perlu untuk reflow past sebuah 320×256 CSS-pixel area — tetapi sebuah typical responsive halaman doesn’t meet itu exceptions.) Per MDN: “Disabling zooming capabilities by setting user-scalable to a value of no prevents people experiencing low vision conditions from being able to read and understand page content. Additionally, WCAG requires a minimum of 2× scaling; however, the best practice is to enable a 5× zoom.” (terjemahan) “Disabling zooming capabilities oleh setting undefined untuk sebuah nilai dari undefined mencegah people experiencing rendah vision conditions dari menjadi able untuk read dan memahami halaman konten. Additionally, WCAG memerlukan sebuah minimum dari 2× scaling; however, best practice adalah untuk enable sebuah 5× zoom.” Blocking zoom locks out exact pengguna who perlu ini sebagian besar.
  2. ini adalah juga browser-spesifik, not universal. iOS Safari 10 dan later ignore user-scalable=no dan restrictive maximum-scale oleh default — itu’s sebuah iOS override, not sebuah perubahan untuk ACT aturan atau untuk WCAG’s intent. So pada sebuah besar share dari mobile traffic setting accomplishes nothing, while pada browser itu melakukan masih honor ini (older Android WebViews, beberapa di-app browser) ini actively fails accessibility test above. Zero upside, nyata downside — dan don’t treat “iOS ignores it” (terjemahan) “iOS ignores ini” sebagai proof markup adalah accessible everywhere.
Evidence for this claim `user-scalable=no` and `maximum-scale` below 2 fail the cited ACT rule's expectation under its assumptions, and disabling zoom harms low-vision users; an automated ACT failure is not by itself a complete universal WCAG conformance determination. Scope: production HTML and HTTP responses Confidence: high · Verified: Viewport meta tag

aturan adalah sederhana: don’t touch zoom. width=device-width, initial-scale=1 dan nothing else.

adalah ini sebuah peringkat factor?

menjadi precise here, because sebuah lot dari SEO konten overstates ini. Here’s exactly what Google documents, dan where line untuk industry inference sits.

What Google documents: viewport tag adalah not sebuah direct peringkat factor. Google’s own didukung-meta-tags doc says plainly itu “presence of this tag indicates to Google that the page is mobile friendly” (terjemahan) “presence dari ini tag indicates untuk Google itu halaman adalah mobile friendly” — itu’s whole documented claim: presence signals mobile-friendliness. Google doesn’t document tag sebagai scored, sebagai sebuah rendering guarantee, atau sebagai proof sebuah halaman’s responsive design adalah actually baik.

Evidence for this claim Google documents that viewport-meta presence indicates a page is mobile friendly, but that statement does not establish that the tag itself is a ranking factor, a display guarantee or sufficient evidence of responsive quality. Scope: production HTML and HTTP responses Confidence: high · Verified: Meta tags and attributes that Google supports

Where practitioners connect dots (industry inference, not sebuah Google citation): sebuah missing atau misconfigured viewport tag adalah sebuah umum root cause dari mobile-usability failures (tiny text, horizontal scroll, unusable tap targets) itu SEOs umumnya memahami untuk degrade mobile pengalaman halaman. itu connection adalah reasonable dan widely held di industry, tetapi ini adalah sebuah practitioner inference tentang why tag penting — not something Google’s docs state sebagai sebuah peringkat chain.

So honest framing: tag itself isn’t scored, dan fix ini because sebuah halaman without ini renders badly pada phones — not because Google documents ini sebagai sebuah peringkat lever, direct atau indirect. pertahankan ini separate dari pengindeksan mobile-pertama too: itu’s sebuah distinct Google Search concept tentang which versi dari Anda halaman Google primarily menggunakan untuk pengindeksan dan peringkat; viewport tag adalah tentang how itu mobile HTML renders di sebuah browser, full stop.

Evidence for this claim Mobile-first indexing means Google primarily uses the mobile content for indexing and ranking; it is a separate Google Search concept from the browser's viewport rendering contract. Scope: production HTML and HTTP responses Confidence: high · Verified: Mobile-first indexing best practices

cara test ini — tooling changed di 2023

ini adalah where sebagian besar older guides adalah stale. pada December 1, 2023, Google retired Search Console’s Mobile Usability report, Mobile-Friendly Test alat, dan Mobile-Friendly Test API (announced April 2023, confirmed complete itu December). Google’s reasoning adalah itu lainnya alat memiliki matured — “many other robust resources for evaluating mobile usability have emerged, including Lighthouse from Chrome.” (terjemahan) “banyak lainnya robust resources untuk evaluating mobile usability memiliki emerged, including Lighthouse dari Chrome.” So jika sebuah tutorial tells Anda untuk open Search Console → Mobile Usability untuk periksa Anda viewport, itu report no longer exists.

Layer ini memeriksa alih-alih relying pada one alat: confirm tag exists di raw disajikan HTML (not hanya setelah JavaScript runs), confirm Anda responsive breakpoints actually apply di phone widths, test zooming untuk 200% without layout breaking ( resize perilaku WCAG’s intent adalah dibangun sekitar), dan spot-periksa di more daripada one browser — sebuah iOS Safari-hanya periksa dapat hide sebuah zoom-restriction bug itu Android atau di-app browser masih enforce.

Anda saat ini toolkit:

  • Lighthouse (di Chrome DevTools). relevant audit historically read “Does not have a <meta name="viewport"> tag with width or initial-scale(terjemahan) “melakukan not memiliki sebuah undefined tag dengan undefined atau undefined” — ini fails unless <head> memiliki sebuah meta name="viewport" whose content mencakup width=. sebagai dari Lighthouse 13 ini adalah folded ke “Optimize viewport for mobile” (terjemahan) “mengoptimalkan viewport untuk mobile” insight.
  • PageSpeed Insights — runs Lighthouse plus field Core Web Vitals data.
  • Chrome DevTools device toolbar — emulate phone dimensions dan eyeball ini.
  • Bing’s Mobile Friendliness Test alat — Bing memeriksa viewport dan zoom-control configuration too, dan recommends yang sama tag Google melakukan.
  • View source / nyata-device periksa — sometimes fastest test adalah untuk hanya look di <head> pada Anda phone.

umum mistakes

  • No tag di semua (“viewport not set” (terjemahan) “viewport not set”) — halaman renders di legacy desktop-ish width dan shrinks.
  • sebuah hardcoded pixel width like width=1024 alih-alih device-width — sebuah tag exists, tetapi ini masih doesn’t match halaman untuk device. Lighthouse dan nyata mobile-friendliness both ingin sebuah usable width= nilai, not hanya apa pun tag.
  • initial-scale below 1 — dapat trigger legacy double-tap-zoom delay.
  • user-scalable=no / restrictive maximum-scale — copy-pasted dari old boilerplate; accessibility anti-pattern, ignored pada iOS anyway.

untuk where ini sits di broader mobile berfungsi — configuration, konten parity, speed — see mobile SEO hub, mobile SEO checklist, dan mobile-pertama pengindeksan. untuk tag itself sebagai bagian dari wider pada-halaman tag family, meta tags cluster adalah map.

Add an expert note

Pin an expert quote

New person? Create their unclaimed profile at /admin/experts/ → Pin a quote first.