0
0
HTMLmarkup~5 mins

Avoiding deprecated tags in HTML

Choose your learning style9 modes available
Introduction

Deprecated tags are old HTML tags that browsers no longer support well. Avoiding them helps your website work better and look good on all devices.

When writing new web pages to ensure they follow modern standards.
When updating old websites to improve compatibility and accessibility.
When you want your site to be easier to maintain and style with CSS.
When you want your website to work well on phones, tablets, and computers.
Syntax
HTML
<strong>Old (deprecated) tag:</strong>
<center>Centered text</center>

<strong>New (recommended) way:</strong>
<p style="text-align: center;">Centered text</p>

Use CSS for styling instead of old tags like <center> or <font>.

Modern HTML uses semantic tags and CSS for layout and appearance.

Examples
Use <strong> instead of <b> because it means important text, not just bold style.
HTML
<b>Bold text</b>

<strong>Bold text</strong>
Use <em> for emphasized text instead of <i> which is just for style.
HTML
<i>Italic text</i>

<em>Italic text</em>
Use CSS styles instead of the <font> tag to change colors.
HTML
<font color="red">Red text</font>

<span style="color: red;">Red text</span>
Use CSS text-align property instead of the <center> tag.
HTML
<center>Centered text</center>

<p style="text-align: center;">Centered text</p>
Sample Program

This example shows how to center and style text using CSS instead of deprecated tags like <center> or <font>. It uses semantic tags like <header>, <main>, and <footer> for better structure and accessibility.

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Avoid Deprecated Tags</title>
  <style>
    .centered {
      text-align: center;
      color: darkblue;
      font-weight: bold;
      font-style: italic;
    }
  </style>
</head>
<body>
  <header>
    <h1 class="centered">Welcome to My Website</h1>
  </header>
  <main>
    <p>This paragraph uses modern HTML and CSS.</p>
    <p class="centered">This text is centered and styled without deprecated tags.</p>
  </main>
  <footer>
    <p>Ā© 2024 My Website</p>
  </footer>
</body>
</html>
OutputSuccess
Important Notes

Deprecated tags may still work in some browsers but can cause problems in the future.

Using CSS keeps your HTML clean and separates content from design.

Semantic HTML helps screen readers and improves SEO.

Summary

Avoid old tags like <center>, <font>, <b>, and <i>.

Use CSS for styling and layout instead.

Use semantic HTML tags for better structure and accessibility.