Back to blog

September 07, 2024

avataravatar

Gautam Patoliya, Deep Poradiya

Tutor Head

HTML and CSS Learning: Meta Tags and SEO

blog-img-HTML and CSS Learning: Meta Tags and SEO


Meta Tags and Their Importance in SEO


The <meta> tag defines metadata about an HTML document. Metadata is information about the data on a webpage and plays a crucial role in SEO (Search Engine Optimization). Meta tags are placed within the <head> section of an HTML document and are not visible on the page but help search engines and browsers understand your content.


Common Meta Tag Attributes:


  • name: Specifies the type of metadata. Common values include description, keywords, author, and viewport.


<meta name="description" content="A brief description of the page.">


  • content: Provides the value for the name or http-equiv attribute.


<meta name="keywords" content="HTML, CSS, JavaScript">


  • http-equiv: Acts as an HTTP header for the page. Common values include content-type, refresh, and X-UA-Compatible.


<meta http-equiv="refresh" content="30">


  • charset: Specifies the character encoding for the HTML document, essential for displaying special characters correctly.


<meta charset="UTF-8">


  • viewport: Controls the size and scaling of the viewport, important for responsive design.


<meta name="viewport" content="width=device-width, initial-scale=1.0">


  • property: Used by Open Graph meta tags to define metadata for social media sharing, like the title or description of shared content.


<meta property="og:title" content="Title of the page">


  • scheme: Defines the scheme used for the content (less commonly used).


<meta name="identifier" content="1234" scheme="ISBN">


Meta Tag Examples


1. Basic Metadata Example


  • The following example shows a set of basic meta tags used for SEO:


<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="description" content="A brief description of the page for search engines."><meta name="keywords" content="HTML, CSS, JavaScript, Web Development"><meta name="author" content="John Doe"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Example Meta Tags</title>
</head>
<body><h1>Welcome to My Website</h1>
</body>
</html>


2. Open Graph Tags (for Social Media)


  • Open Graph meta tags help optimize how content appears when shared on social media platforms.


<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta property="og:title" content="Example Open Graph Title"><meta property="og:description" content="A description that will appear when this page is shared on social media."><meta property="og:image" content="https://example.com/image.jpg"><meta property="og:url" content="https://example.com"><title>Open Graph Meta Tags</title>
</head>
<body><h1>Open Graph Example</h1>
</body>
</html>


3. HTTP-Equiv Meta Tags (e.g., Auto-Refresh)


  • You can use the http-equiv attribute to refresh the page at set intervals or to specify browser compatibility.


<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="refresh" content="30"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>HTTP-Equiv Meta Tags</title>
</head>
<body><h1>Auto-refresh Page Every 30 Seconds</h1>
</body>
</html>


4. Viewport Meta Tag (Responsive Design)


  • The viewport meta tag is essential for making your webpage responsive and adjusting the layout based on the user's device.


<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Responsive Design Meta Tags</title>
</head>
<body><h1>Responsive Design with Viewport Meta Tag</h1>
</body>
</html>
HTML
CSS
Web