META Tags to boost SEO and Page Rankings
Tags: javascript, webdev, tutorial, productivity
Published: 2022-07-23 18:53:00

Meta tags are snippets of text that describe a page's content. With Open Graph Protocol meta tags are on steroids, whenever someone share links on Twitter or Whatsapp, we see website thumbnail, gif with description, that's what open graph protocol does to meta tags.

Meta tags are tags within the HTML code of your website that describe the different components of your site to search engines. These tags allow Bing or Google search algorithms to read descriptions of the makeup of your site.

The Open Graph protocol enables any web page to become a rich object in a social graph. For instance, this is used on Facebook to allow any web page to have the same functionality as any other object on Facebook.

## Plain META Tags 

```html
<meta charset='utf-8'>
```

```html
<!-- title -->
<title>···</title>
<meta property='og:title'  content='···'>
<meta name='twitter:title' content='···'>
 
```

```html
<!-- url -->
<link rel='canonical'       href='http://···'>
<meta property='og:url'  content='http://···'>
<meta name='twitter:url' content='http://···'>
 
```

```html
<!-- description -->
<meta name='description'         content='···'>
<meta property='og:description'  content='···'>
<meta name='twitter:description' content='···'>
 
```

```html
<!-- image -->
<meta property="og:image"  content="http://···">
<meta name="twitter:image" content="http://···">
```

```html
<!-- ua -->
<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
```

```html
<!-- viewport -->
<meta name='viewport' content='width=device-width'>
<meta name='viewport' content='width=1024'>
```


## Progressive web apps

### Add to homescreen

```html
<meta name='mobile-web-app-capable' content='yes'>
<meta name='apple-mobile-web-app-capable' content='yes'>
```

```html
<meta name='apple-mobile-web-app-status-bar-style' content='black'>
<!-- black | black-translucent | default -->
```

### Theme color

```html
<meta name='theme-color' content='#ff00ff'>
```

Android-only. See: [Theme color](https://developers.google.com/web/updates/2014/11/Support-for-theme-color-in-Chrome-39-for-Android)

### Manifest

```html
<link rel='manifest' href='/manifest.json'>
```

Android-only. See: [Manifest](https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/)

### Icons

```html
<!-- Minimal -->
<link rel='icon' type='image/png' href='favicon@32.png'>
<link rel='icon' sizes='192x192' href='icon@192.png'>
<link rel='apple-touch-icon' href='icon@152.png'>
<meta name='msapplication-square310x310logo' content='icon@310.png'>
```

```html
<!-- Apple -->
<link rel='apple-touch-icon' href='touch-icon-iphone.png'>
<link rel='apple-touch-icon' sizes='76x76' href='touch-icon-ipad.png'>
<link rel='apple-touch-icon' sizes='120x120' href='touch-icon-iphone-retina.png'>
<link rel='apple-touch-icon' sizes='152x152' href='touch-icon-ipad-retina.png'>
```

```html
<!-- Microsoft -->
<meta name='msapplication-square70x70logo' content='icon_smalltile.png'>
<meta name='msapplication-square150x150logo' content='icon_mediumtile.png'>
<meta name='msapplication-wide310x150logo' content='icon_widetile.png'>
```

********
## The Open Graph Protocol Meta Tags

### Basic Metadata

```
og:title - The title of your object as it should appear within the graph, e.g., "The Rock".
og:type - The type of your object, e.g., "video.movie". Depending on the type you specify, other properties may also be required.
og:image - An image URL which should represent your object within the graph.
og:url - The canonical URL of your object that will be used as its permanent ID in the graph, e.g., "https://www.imdb.com/title/tt0117500/"
```
**Example**

```html
<html prefix="og: https://ogp.me/ns#">
<head>
<title>The Rock (1996)</title>
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="https://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="https://ia.media-imdb.com/images/rock.jpg" />
...
</head>
...
</html>
```

**Optional Metadata**
The following properties are optional for any object and are generally recommended:

```html
og:audio - A URL to an audio file to accompany this object.
og:description - A one to two sentence description of your object.
og:determiner - The word that appears before this object's title in a sentence. An enum of (a, an, the, "", auto). If auto is chosen, the consumer of your data should chose between "a" or "an". Default is "" (blank).
og:locale - The locale these tags are marked up in. Of the format language_TERRITORY. Default is en_US.
og:locale:alternate - An array of other locales this page is available in.
og:site_name - If your object is part of a larger web site, the name which should be displayed for the overall site. e.g., "IMDb".
og:video - A URL to a video file that complements this object.
```

**Example**

```html
<meta property="og:audio" content="https://example.com/bond/theme.mp3" />
<meta property="og:description" 
  content="Sean Connery found fame and fortune as the
           suave, sophisticated British agent, James Bond." />
<meta property="og:determiner" content="the" />
<meta property="og:locale" content="en_GB" />
<meta property="og:locale:alternate" content="fr_FR" />
<meta property="og:locale:alternate" content="es_ES" />
<meta property="og:site_name" content="IMDb" />
<meta property="og:video" content="https://example.com/bond/trailer.swf" />
```

### Example of Image thumbnail meta for social sharing

```html
<!-- Primary Meta Tags -->  
<title>Meta Tags — Preview, Edit and Generate</title>  
<meta name="title" content="Meta Tags — Preview, Edit and Generate">  
<meta name="description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!">  
  
<!-- Open Graph / Facebook -->  
<meta property="og:type" content="website">  
<meta property="og:url" content="https://metatags.io/">  
<meta property="og:title" content="Meta Tags — Preview, Edit and Generate">  
<meta property="og:description" content="With Meta Tags you can edit and experiment with your content then preview how your webpage will look on Google, Facebook, Twitter and more!">  
<meta property="og:image" content="https://aws-huddleup.s3.ap-south-1.amazonaws.com/meta-image.png">  
  
<!-- Twitter -->  
<meta property="twitter:card" content="summary_large_image">  
<meta property="twitter:url" content="https://www.yourwebsite.com/">  
<meta property="twitter:title" content="Website Title">  
<meta property="twitter:description" content="Website Description">  
<meta property="twitter:image" content="https://aws-s3.ap-south-1.amazonaws.com/meta-image.png">

```

## Use these website to create and preview meta tags live and test it.
- https://metatags.io/
- https://www.seoptimer.com/meta-tag-generator

References:
- https://ogp.me/
- https://devhints.io/html-meta
- https://css-tricks.com/snippets/css/media-queries-for-standard-devices/